+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Junior Member George Duls's Avatar
    Using
    AutoCAD 2006
    Join Date
    Oct 2007
    Location
    Croatia, Split
    Posts
    18

    Default A simple way to do this?

    Registered forum members do not see this ad.

    Hello, it's me again.
    Here is the question

    (defun c:sve ()
    (setq p1 (list 0 21))
    (setq p2 (list 1082 39))
    (setq p3 (list 2298 60))
    ;
    ;
    (setq p1_x (car p1))
    (setq p1_y (cadr p1))
    ;
    (setq p2_x (car p2))
    (setq p2_y (cadr p2))
    ;
    (setq p3_x (car p3))
    (setq p3_y (cadr p3))
    ;and so on...
    )

    Now, is it possible for lisp to set p1_x to the value
    of (car p1) automaticly (?!) so I don't have to write
    all the text manually?
    Thank you for reading my question,
    greetings!

  2. #2
    Senior Member wizman's Avatar
    Using
    AutoCAD 2009
    Join Date
    Nov 2007
    Location
    Abu Dhabi / Philippines
    Posts
    408

    Default

    put them in another list

    (setq allx (mapcar 'car (list p1 p2 p3))) >>>> all values of x
    (setq ally (mapcar 'cadr (list p1 p2 p3))) >>>> all values of y

    then play in just 2 lists (allx and ally)

  3. #3
    Super Member CAB's Avatar
    Using
    AutoCAD 2000
    Join Date
    May 2004
    Location
    Tampa, Florida
    Posts
    801

    Default

    You can use something like this. It ceates as many variables as needed.
    Code:
    (defun c:sve ()
      (setq pointlist
             '(
               (0 21)
               (1082 39)
               (2298 60)
              )
      )
      (setq idx 1)
      (foreach pt pointList
        (set (read (strcat "p" (itoa idx) "_x")) (car pt))
        (set (read (strcat "p" (itoa idx) "_y")) (cadr pt))
        (setq idx (1+ idx))
      )
      (princ)
    )
    But there is seldom a need for the code I posted. I would do it like wizman did.

  4. #4
    Junior Member George Duls's Avatar
    Using
    AutoCAD 2006
    Join Date
    Oct 2007
    Location
    Croatia, Split
    Posts
    18

    Default

    Registered forum members do not see this ad.

    Thank you

    And now I have two more commands
    to learn, mapcar&foreach.
    I dont have my
    own internet connection and i cant
    come here very often. That sucks,
    this is a very nice place to be.
    Greetings to everyone!

Similar Threads

  1. Perspective in simple 2d
    By Gothic in forum Tutorials & Tips'n'Tricks
    Replies: 13
    Last Post: 10th Nov 2006, 02:39 pm
  2. Lines - im sure this is simple
    By mattwsp in forum AutoCAD Drawing Management & Output
    Replies: 9
    Last Post: 31st Aug 2006, 03:26 pm
  3. Pls Help I am sure this is Simple!
    By Ste1978 in forum AutoCAD Drawing Management & Output
    Replies: 14
    Last Post: 29th Aug 2006, 08:16 pm
  4. Simple simple, huh? rectangles how are they built?
    By Anna_here in forum AutoCAD Beginners' Area
    Replies: 6
    Last Post: 2nd Aug 2006, 09:18 pm
  5. A simple offer of help!
    By Psmeg in forum Design Software
    Replies: 3
    Last Post: 30th Sep 2002, 06:57 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts