Author Topic: Manipulate Lists  (Read 2934 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Manipulate Lists
« 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
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Manipulate Lists
« Reply #1 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)
 )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Manipulate Lists
« Reply #2 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
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Manipulate Lists
« Reply #3 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

GDF

  • Water Moccasin
  • Posts: 2081
Re: Manipulate Lists
« Reply #4 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
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Fatty

  • Guest
Re: Manipulate Lists
« Reply #5 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)))))

GDF

  • Water Moccasin
  • Posts: 2081
Re: Manipulate Lists
« Reply #6 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)))
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Manipulate Lists
« Reply #7 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Manipulate Lists
« Reply #8 on: February 07, 2006, 07:52:51 PM »
Now I just need to save these examples and not lose them.

They are!  :-)
TheSwamp.org  (serving the CAD community since 2003)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Manipulate Lists
« Reply #9 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:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.