Results 1 to 5 of 5

Thread: Help interpreting autolisp code

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2012-09
    Location
    Pune
    Posts
    1

    Default Help interpreting autolisp code

    Well this is my 1st post..I'm thankful to AUGI
    Lets get to business...

    help me interpret the below code (actually a section of a program)....

    Code:
    (setq  a(entsel "Select a object ")...........(1)
             a(car a).................(2)
             b(entget a)..............(3)
             p1(cdr(assoc 10 b))
             p2(cdr(assoc 11 b))
             )
    So i want to know what lines 1,2,3 mean....please explain in detail...thanks in advance...and AUGi Rocks..!!!!!!
    Last edited by rkmcswain; 2012-09-12 at 05:47 PM. Reason: added [CODE] tags

  2. #2
    Certified AUGI Addict rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Houston
    Posts
    7,519

    Default Re: Help interpreting autolisp code

    entsel = Prompts the user to select a single object (entity) by specifying a point
    car = Returns the first element of a list
    entget = Retrieves an object's (entity's) definition data

    For more, see http://docs.autodesk.com/ACD/2011/EN...16f8b-5913.htm

  3. #3
    Certified AUGI Addict rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Houston
    Posts
    7,519

    Default Re: Help interpreting autolisp code

    I also changed the name of this thread so that the title is more descriptive.
    General titles like "Extremely important......Help me out !!!!!!!!" have little value when searching.
    Thanks.

  4. #4
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,344

    Default Re: Help interpreting autolisp code

    As RK's shown, just a tad more detail

    Line1:
    Code:
    (         Start a lisp expression
    setq      Call the setq function
    a         Set the following value into variable a
    (         Start a lisp expression
    entsel    Call the entsel function, asking user to pick an object
    "..."     Argument to entsel, in this case the message to display
    )         Close the last lisp expression
    Notice there's only one closing parenthesis, which means the 1st lisp expression continues to the next line.

    Lisp runs the code from inside to out in prefix notation. I.e. the ( effectively means about to call something. The first word in the (...) group is the function name. The rest (if any) are the arguments passed to that function.

    So, what happens in the 1st line? The arguments for setq is evaluated first. Setq can have many arguments, but always in multiples of two: 1st the variable's name, then it's new value. But seeing that the 1st value is a lisp expression, that is evaluated before it's set into a.

    So then entsel is called, passing the sting (note surrounded by double-quotes) argument to it. This then waits for the user to pick an object. After the user picked the object entsel returns a list of data in the form (<EName> <Pick Point>). This then gets set into variable a.

    Then setq checks if there's any more arguments ... ah yes, there are. A pair: a (car a). So again evaluate the value first: car means 1st element of list. Since a already contains (<EName> <Pick Point>), this then extracts only the <EName> and places it inside a.

    Next we get: b (entget a). The entget takes the <EName> inside a, then extracts the DXF data from that entity and returns it to setq so it can be saved into b.

    The rest continue much in the same manner until the last closing parenthesis is reached and setq then stops. It returns the last value it evaluated, in this case the remainder of the sub-list in b starting with 11, which is most probably something like the endpoint of a line in the form of a list of reals: (X Y Z).
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  5. #5
    100 Club
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    150

    Default Re: Help interpreting autolisp code

    Grab the books , they dont bite
    Attached Files Attached Files

Similar Threads

  1. Autolisp Code To Print Multiple Paperspace layout
    By mill3929974348 in forum AutoLISP
    Replies: 2
    Last Post: 2012-04-27, 09:10 PM
  2. interpreting lock symbols
    By ccenergy in forum Revit Architecture - General
    Replies: 7
    Last Post: 2012-02-16, 05:44 PM
  3. Insert vbscript code has not code
    By buzz in forum AMEP General
    Replies: 3
    Last Post: 2008-02-09, 02:08 AM
  4. Convert VBA code to VB code
    By Robert Platt in forum VBA/COM Interop
    Replies: 20
    Last Post: 2007-08-15, 10:13 PM
  5. Replies: 13
    Last Post: 2004-07-29, 11:38 PM

Tags for this Thread

Posting Permissions

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