Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add list to a list

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
454 Views, 9 Replies

Add list to a list

I have a list -

(setq List1 (list "Line A" "Line B" "Line C"))

I would like to add each item in an existing list to a new list -

(setq ListNew (list "This is some text" "This is more text"

    ;the following is the part I can't figure out - it just adds the list to the list, not the individual items

   (mapcar '(lambda (x) x) List1)

))

 

I am looking for ListNew to be - (a list with 5 strings)

"This is some text"

"This is more text"

"Line A"

"Line B"

"Line C"

9 REPLIES 9
Message 2 of 10
alanjt_
in reply to: Anonymous

(setq List1 (list "Line A" "Line B" "Line C"))

(append (list "additional 1" "additional 2") List1)

OR

(cons "additional 1" (cons "additional 2" List1))

 

This gives you two options. append is easier in this regard, but will be much slower than cons. If you know what they items will be (set number of), then I'd go with cons.

Message 3 of 10
Anonymous
in reply to: alanjt_

I understand how to use the append and cons.

I was hoping I could add the values during the setq function itself.

 

Message 4 of 10
mid-awe
in reply to: alanjt_

Could this approach be used for merging selection sets?
Message 5 of 10
alanjt_
in reply to: Anonymous


@Anonymous wrote:

I understand how to use the append and cons.

I was hoping I could add the values during the setq function itself.

 


I'm not sure I understand. It can be done at any time. If you know the values at the time of originally construction the list, just append/cons as shown or construct the list just including the new items.

Message 6 of 10
alanjt_
in reply to: mid-awe


@mid-awe wrote:
Could this approach be used for merging selection sets?

No. To combine two selection sets, you would need to step through one and add each ename to the other.

Message 7 of 10
mid-awe
in reply to: alanjt_

Thank you for the answer. Right now I use ssadd, but I have to know how many selection sets are going to be merged, so I'll dig into your solution. Again thank you.
Message 8 of 10
alanjt_
in reply to: mid-awe


@mid-awe wrote:
Thank you for the answer. Right now I use ssadd, but I have to know how many selection sets are going to be merged, so I'll dig into your solution. Again thank you.

No problem.

 

This should give you something to play with. I elected to create a new, rather than adding to one of the unknown number of picksets, so this would change the actual pickset. This will handle a list of as many picksets (selection sets) as you can throw at it and combine each ename into one pickset.

 

(defun _ssUnion (ssList / add i)
  (setq add (ssadd))
  (foreach ss ssList
    (if (eq (type ss) 'PICKSET)
      (repeat (setq i (sslength ss)) (ssadd (ssname ss (setq i (1- i))) add))
    )
  )
  (if (> (sslength add) 0)
    add
  )
)

 

Message 9 of 10
mid-awe
in reply to: alanjt_

Beautiful! 🙂
I reworked my tools to use your sub. Thank you.
Message 10 of 10
alanjt_
in reply to: mid-awe


@mid-awe wrote:
Beautiful! 🙂
I reworked my tools to use your sub. Thank you.

Good deal. Happy coding. 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost