Results 1 to 9 of 9

Thread: Help me understand this code please

  1. #1
    Member
    Join Date
    2010-02
    Posts
    21
    Login to Give a bone
    0

    Default Help me understand this code please

    Hi have this code in a routine I got from the internet, I know what it does but I don't understand it... Could someone explain?

    Code:
    (defun C:sumlp (/ p l e sxy exy sum)
       (setq p  (ssget   (list (cons -4 "<or")
                                  (cons 0 "LINE")
                                  (cons 0 "LWPOLYLINE")
                                  (cons -4 "<and")
                                     (cons 0 "POLYLINE")
                                     (cons -4 "<not")
                                        (cons -4 "&") (cons 70 (+ 16 32 64))
                                     (cons -4 "not>")
                                  (cons -4 "and>")
                               (cons -4 "or>")
                         )
                )
             sum 0.0
       )
    Thanks a lot

  2. #2
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,194
    Login to Give a bone
    0

    Default Re: Help me understand this code please

    Quote Originally Posted by rdogomes View Post
    Hi have this code in a routine I got from the internet, I know what it does but I don't understand it... Could someone explain?

    Code:
    (defun C:sumlp (/ p l e sxy exy sum)
       (setq p  (ssget   (list (cons -4 "<or")
                                  (cons 0 "LINE")
                                  (cons 0 "LWPOLYLINE")
                                  (cons -4 "<and")
                                     (cons 0 "POLYLINE")
                                     (cons -4 "<not")
                                        (cons -4 "&") (cons 70 (+ 16 32 64))
                                     (cons -4 "not>")
                                  (cons -4 "and>")
                               (cons -4 "or>")
                         )
                )
             sum 0.0
       )
    Thanks a lot
    Welcome to AUGI and congrats on your first post.
    this code allows the user to select any object that is a line or polyline, as long as the polyline is not a 3d polygon mesh that is closed in the n direction and that is not a polyface mesh and sets the selection set to the variable p, as well as setting sum equal to 0.0. But I dont think it will do what it is intended as typically dxf codes are not considered bitwise, meaning, you cant use a sum, you would have to specify each 70 group individually.
    Last edited by ccowgill; 2010-02-25 at 01:14 PM.
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  3. #3
    Super Moderator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,673
    Login to Give a bone
    0

    Default Re: Help me understand this code please

    Quote Originally Posted by ccowgill View Post
    But I dont think it will do what it is intended as typically dxf codes are not considered bitwise, meaning, you cant use a sum, you would have to specify each 70 group individually.
    It works in my tests, and the documentation agrees.
    It says "The bitwise AND, "&", is true if ((integer_group & filter) /= 0)—that is, if any of the bits set in the mask are also set in the integer group."

    Which in this case is the same as saying... (logand value (+ 16 32 64)), and as examples...

    * (logand 16 (+ 16 32 64)) returns 16 [this is a 3D mesh polyline]
    * (logand 128 (+ 16 32 64)) returns 0 [this is a plain closed polyline]
    R.K. McSwain | CAD Panacea |

  4. #4
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,194
    Login to Give a bone
    0

    Default Re: Help me understand this code please

    Quote Originally Posted by rkmcswain View Post
    It works in my tests, and the documentation agrees.
    It says "The bitwise AND, "&", is true if ((integer_group & filter) /= 0)—that is, if any of the bits set in the mask are also set in the integer group."

    Which in this case is the same as saying... (logand value (+ 16 32 64)), and as examples...

    * (logand 16 (+ 16 32 64)) returns 16 [this is a 3D mesh polyline]
    * (logand 128 (+ 16 32 64)) returns 0 [this is a plain closed polyline]
    I've learned something today, I'm going home now
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  5. #5
    Member
    Join Date
    2010-02
    Posts
    21
    Login to Give a bone
    0

    Default Re: Help me understand this code please

    Thanks a lot for the replies

    I also learned today that I have a lot to learn.. I don't get most of what has been said.

    But perhaps I didn't phrase my question well enough.

    I know what the code does, but I don't know how

    sorry if my english sounds strange

  6. #6
    Certifiable AUGI Addict ccowgill's Avatar
    Join Date
    2004-08
    Location
    Hartford, Michigan
    Posts
    3,194
    Login to Give a bone
    0

    Default Re: Help me understand this code please

    the list is a filter that applies to the selection set, when an object is selected, its properties are matched against the filter list and if the object meets those filter requirements, it is allowed to be added to the selection set, otherwise it is discarded. if you look up the SSGET function in the developer help, it will give you some additional information.
    Christopher T. Cowgill, P.E.
    Autodesk Expert Elite
    AEC Collection Civil 3D 2020
    Windows 10

  7. #7
    Member
    Join Date
    2010-02
    Posts
    21
    Login to Give a bone
    0

    Default Re: Help me understand this code please

    more specifically what I don´t understand is all those "<or" "<and" "&", and that part (cons 70 (+ 16 32 64)

    I can't seem to find the info about those kinds of conditionals, does anyone know?

  8. #8
    Member
    Join Date
    2010-02
    Posts
    21
    Login to Give a bone
    0

    Default Re: Help me understand this code please

    I think I found something in the help file about relational tests... I'm starting to understand it.

  9. #9
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Lightbulb Re: Help me understand this code please

    Quote Originally Posted by rdogomes View Post
    more specifically what I don´t understand is ... that part (cons 70 (+ 16 32 64)
    I can hit this one. That particular DXF code (70) stores a bit-value. So instead of simply providing the sum, e.g. '(70 . 112), the author is showing, in the code, which bits we are concerned about, e.g. (+ 16 32 64). If you want to understand why showing bit values in this fashion makes sense, see this post.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

Similar Threads

  1. CP122-1: CUI: You Can Understand It!
    By Autodesk University in forum Customization and Programming
    Replies: 0
    Last Post: 2014-12-01, 01:44 AM
  2. Venting and I don’t understand why this is.
    By burninin1 in forum Inventor - General
    Replies: 5
    Last Post: 2009-01-13, 12:10 AM

Posting Permissions

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