TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on February 07, 2006, 02:55:12 PM

Title: Manipulate Lists
Post by: GDF on February 07, 2006, 02:55:12 PM
Sorry, I have to ask. Can someone show me how to manipulate dotted pair list.

Code: [Select]
("MyRoomInformation" (1000 . "ROOM NAME") (1000 . "Living Room") (1000 . "ROOM
NUMBER") (1000 . "123") (1000 . "AREA") (1040 . 55.2294))

I want the following:

Room Name "Living Room"
Room Number "123"
Area 55.2294

Gary
Title: Re: Manipulate Lists
Post by: T.Willey on February 07, 2006, 03:09:02 PM
One way.
Code: [Select]
(setq MyList '("MyRoomInformation" (1000 . "ROOM NAME") (1000 . "Living Room") (1000 . "ROOM NUMBER") (1000 . "123") (1000 . "AREA") (1040 . 55.2294)))
(foreach Item (cdr MyList)
 (setq tmp (vl-princ-to-string (cdr Item)))
 (if tmpStr
  (progn
   (prompt (strcat "\n " tmpStr " " tmp))
   (setq tmpStr nil)
  )
  (setq tmpStr tmp)
 )
)
Title: Re: Manipulate Lists
Post by: GDF on February 07, 2006, 03:22:32 PM
Thanks Tim

I find it hard to do the simplest things.

using your code I get:

 123 ROOM NAME
 Living Room ROOM NUMBER
 123 AREA"55.2294"

So how would you do the list like in my previous example?

ROOM NAME Living Room
ROOM NUMBER "123"
area "55.2294"


Gary
Title: Re: Manipulate Lists
Post by: Jeff_M on February 07, 2006, 03:27:03 PM
Another way.... (I did add ":" after each description)
Code: [Select]
(while (setq lst (cdr lst))
  (princ (strcat "\n" (cdar lst) ":  "
(cond ((= (type (setq x (cdadr lst))) 'INT)
(itoa x))
       ((= (type x) 'REAL)
(rtos x))
       ((= (type x) 'STR)
(strcat "\"" x "\""))
       )
))
  (setq lst (cdr lst))
  )
Edited to relocate the line feed
Title: Re: Manipulate Lists
Post by: GDF on February 07, 2006, 03:34:18 PM
Thanks Jeff

ROOM NAME:  "Living Room"
ROOM NUMBER:  "123"
AREA:  4'-7 59/256"

That is what I wanted.

Now I just need to save these examples and not lose them.

Gary
Title: Re: Manipulate Lists
Post by: Fatty on February 07, 2006, 04:26:41 PM
Here is another one
Code: [Select]
(defun readxd (lst)
  (if (cadr (cdr lst))
    (cons (list (cdar (cdr lst))
(vl-princ-to-string (cdadr (cdr lst))))
  (readxd (cddr lst)))))
Title: Re: Manipulate Lists
Post by: GDF on February 07, 2006, 04:38:24 PM
Fatty

Thanks

Code: [Select]
(defun C:XDL1 (/ BMENT BMSEL ELST FOROBJ)
 (vl-load-com)
 (setq BMSEL (entsel "\n* Select Object to Get It's Xdata *"))
 (if BMSEL
  (progn
   (setq BMENT (car BMSEL))
   (vlax-for FOROBJ (vla-get-registeredapplications
                     (vla-get-database
                      (vla-get-activedocument
                       (vlax-get-acad-object)
                      )
                     )
                    )
    (setq ELST (entget BMENT (list (vla-get-name FOROBJ))))
    (if (assoc -3 ELST)
     (print (cadr (assoc -3 ELST)))  (print (cadar (assoc -3 ELST)))
    )
   )
  )
 )   
 (prin1)
)

I get the following using Tim Willeys (c:RoomInfo):

(("ROOM NAME" "Living Room") ("ROOM NUMBER" "123") ("AREA" "55.2294"))

When I use:

(readxd '("MyRoomInformation"
               (1000 . "ROOM NAME")
               (1000 . "Living Room")
               (1000 . "ROOM NUMBER")
               (1000 . "123")
               (1000 . "AREA")
               (1040 . 55.2294)))
Title: Re: Manipulate Lists
Post by: T.Willey on February 07, 2006, 04:48:24 PM
You can add more stuff to that routine Gary.  Just have it prompt for my questions if that isn't enough for you.  That is one I will be working on when I have time.  Glad someone found a use for it.
Title: Re: Manipulate Lists
Post by: Mark on February 07, 2006, 07:52:51 PM
Now I just need to save these examples and not lose them.

They are!  :-)
Title: Re: Manipulate Lists
Post by: Kerry on February 07, 2006, 08:01:05 PM
Tim, Mark has a team of people who, every night, save threads that Mark has pre-nominated.

You have no worries, 'cause this is one of those threads ..

 :lmao: