-2

I am getting the following output (a separate pair of two lists) after running a chunk of code:

("a") ("a")

How do I combine this pair of lists into one? i.e. I want the following output:

("a" "a")

For clarification my code is:

(defun c:TEST ()
    (setq a (ssget)); I select a line here
    (setq b (assoc 8 (entget (ssname a 0)))); gets me all dotted pairs containing 8
    (setq c (list (cdr b))); gets second elements of each pair (strings in this case) and converts them to two separate lists
    (print c)
)
Kevin Chiha
  • 59
  • 1
  • 8
  • Use `APPEND` to append multiple lists into one list. – Barmar Jun 20 '18 at 23:56
  • How is the function returning multiple lists? – Barmar Jun 20 '18 at 23:56
  • 3
    Are you sure the first `("a")` isn't what is printed (`c`) and the second is he same as returned value? – Sylwester Jun 21 '18 at 00:59
  • 2
    I'm with @Sylvester here; a single `(print c)` isn't going to produce two values. The `printf` function [returns the leftmost argument value is it passed](http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-697e.htm) and so if it is the last expression of the function, that function will return whatever was printed. If you run that function from some interactive listener ("REPL" or "read-eval print loop") you will see the printed output and the returned value printed again. – Kaz Jun 21 '18 at 01:15
  • I'm dumb. You're right. I feel stupid. Thanks! How do i mark as solved? – Kevin Chiha Jun 21 '18 at 01:20

1 Answers1

2

I have gone through your question, As far as I know, I am trying to solve your problem, it seems that you try to get layer name of that line.

if you run test function as mention in question it returns ("a") ("a") twice because of the first one due to (print c) in code and the second one as function output value. the output is single list ("a") but it write two time in command prompt.

I thought you misunderstood here. if you type (princ) at the end of your function then the output is ("a") .

keep in mind AutoLISP always return the last statement of function as function value to get more go through developer documents.

also, you can found in AutoLISP to print value developer use "print", "princ", "prin1" and "prompt" command for detail click here

below I write some function which can help you to better understand the concept

;
(defun c:TEST()
    (setq a (ssget))
    (setq b (assoc 8 (entget (ssname a 0))))
    (setq c (list (cdr b)))
    (print c)
  ;output-> ("a") ("a")
)

(defun c:TEST1 ()
    (setq a (ssget))
    (setq b (assoc 8 (entget (ssname a 0))))
    (setq c (list (cdr b)))
    (print c)

  (princ);return nothing

  ;output-> ("a")
)


(defun c:TEST2()
    (setq a (ssget))
    (setq b (assoc 8 (entget (ssname a 0))))
    (setq c (list (cdr b)))
    (print c)

  (princ "last statement");return nothing
  ;output-> ("a") last statement"last statement"
  )

(defun c:TEST3()
    (setq a (ssget))
    (setq b (assoc 8 (entget (ssname a 0))))
    (setq c (list (cdr b)))
    (print c)

  (princ "last statement");return nothing
  (princ)
  ;output-> ("a") last statement
  )

if you run test output is ("a") ("a")

if you run test1 output is ("a")

if you run test2 output is ("a") last statement"last statement"

here you see "last statement" is two time because again same reason AutoLISP always return the last statement of function as function value

if you run test3 output is ("a") last statement

hope this helps

Dinesh Vilas Pawar
  • 493
  • 2
  • 5
  • 18