+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 20
  1. #1
    Forum Newbie
    Using
    AutoCAD 2012
    Join Date
    Sep 2011
    Posts
    9

    Default Extracting values from objects

    Registered forum members do not see this ad.

    I want to extract values from objects such as a line, and use them as variables in Autolisp.

    For instance, say I draw a line:
    Code:
    (command "line" "0,0" "@5000<37" "")
    It will draw a line 5000 units long from the origin at an angle of 37°, to an unknown point.

    If I inspect the properties of this line, I can find that end point END X = 4000 and END Y = 3000.

    Is there a way to extract these values through lisp and assign them to a variable?

    eg.
    Code:
    (setq endx1 ("end x value"))
          (setq endy1 ("end y value"))
    Conversely I also want to be able to draw a line from absolute coords point1 to point2 and get the delta x and y values, as well as the length and angle.
    Last edited by bpdav1; 15th Aug 2012 at 11:33 pm.

  2. #2
    Senior Member nod684's Avatar
    Computer Details
    nod684's Computer Details
    Operating System:
    Windows 7 Home
    Discipline
    Architectural
    Using
    AutoCAD 2010
    Join Date
    Jul 2012
    Location
    Singapore
    Posts
    232

    Default

    Quote Originally Posted by bpdav1 View Post
    I want to extract values from objects such as a line, and use them as variables in Autolisp.

    For instance, say I draw a line: (command "line" "0,0" "@5000<37" "")

    It will draw a line 5000 units long from the origin at an angle of 37°, to an unknown point.

    If I inspect the properties of this line, I can find that end point END X = 4000 and END Y = 3000.

    Is there a way to extract these values through lisp and assign them to a variable?

    eg. (setq endx1 ("end x value"))
    (setq endy1 ("end y value"))

    Conversely I also want to be able to draw a line from absolute coords point1 to point2 and get the delta x and y values, as well as the length and angle.

    try reading this :
    http://www.jefferypsanders.com/autolispintr_dxf.html

    and take note of group Code 10 and 11
    "Memories fade but the scars still linger...."

  3. #3
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    This ... ?

    Code:
    (command "_.line" "0,0" "@5000<37" "")
    (if (setq e (entlast))
      (progn
        (setq elist (entget e))
        (setq end (cdr (assoc 11 elist)))
        (setq x_end (car end))
        (setq y_end (cadr end))
      )
    )
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  4. #4
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    Since you know both starting point and the polar displacement, you can calculate the target point, don't need to list it from entity:
    Code:
    (setq pointTemp (polar '(0 0) (* (/ 37.0 180.0) pi) 5000.0)
          endX (car  pointTemp)
          endY (cadr pointTemp))
    I believe you already had this information on your other thread.

    Also, please edit your post and add the code tags. Thank you.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  5. #5
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    This is much better and to guarantee that the last object is created and line entity .

    Code:
    (if (setq e
           (entmakex
             (list '(0 . "LINE")
               '(10 0. 0. 0.)
               (cons 11 (polar '(0. 0. 0.) (* (/ 37.0 180.0) pi) 5000.0))
             )
           )
        )
      (progn
        (setq elist (entget e))
        (setq end (cdr (assoc 11 elist)))
        (setq x_end (car end))
        (setq y_end (cadr end))
      )
    )
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  6. #6
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x86
    CPU:
    Pentium(R) Dual-Core CPU E5500 @ 2.80GHz
    RAM:
    4 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    ThinkVision 22"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    9,110

    Default

    bpdav1,

    Please read the CODE POSTING GUIDELINES and edit your posts (in this thread and some previous threads) to include code tags.
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  7. #7
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    Sorry Tharwat, but that is totally counter-productive. Why add the entity and interrogate it later when you have access to all his features at design time?!?
    Even if OP was looking for such work-around, I believe that a better approach is to advice him/her to use an effective solution.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  8. #8
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    Quote Originally Posted by MSasu View Post
    Sorry Tharwat, but that is totally counter-productive.
    Where is the counter-productive of the code ?
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  9. #9
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    Have you read my whole message?
    Quote Originally Posted by MSasu View Post
    Why add the entity and interrogate it later when you have access to all his features at design time?!?
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  10. #10
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by MSasu View Post
    Have you read my whole message?
    I don't like these kinds of replies Mircea
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

Similar Threads

  1. AutoCAD 2D with third dimension values for objects ?
    By micheldenis in forum AutoCAD Beginners' Area
    Replies: 3
    Last Post: 11th Aug 2012, 05:36 pm
  2. 2D objects with z-values
    By senthil in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 6th Apr 2012, 05:07 pm
  3. Replies: 4
    Last Post: 22nd Mar 2011, 02:11 pm
  4. how to grab values from different objects?
    By gilsoto13 in forum AutoLISP, Visual LISP & DCL
    Replies: 18
    Last Post: 26th Mar 2010, 12:10 am
  5. Need help extracting attribute values in Lisp
    By Archiman86 in forum AutoLISP, Visual LISP & DCL
    Replies: 30
    Last Post: 18th Feb 2010, 01:27 am

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