+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 20

Thread: My first Lisp

  1. #1
    Forum Deity steven-g's Avatar
    Computer Details
    steven-g's Computer Details
    Operating System:
    Win 7
    Discipline
    Construction
    steven-g's Discipline Details
    Occupation
    Draughtsman
    Discipline
    Construction
    Details
    I work in the estimating department of a large building contractor.
    Using
    AutoCAD 2018
    Join Date
    May 2013
    Location
    An Englishman in Belgium
    Posts
    2,174

    Default My first Lisp

    Registered forum members do not see this ad.

    After the last six months using full Autocad I have finally taken the plunge into Lisp (there's still life in the old dog yet)
    So here is my first efforts it's actually designed to help me in Bricscad but Lisp is Lisp.
    No question, I am looking for hard critical assesment on any point, if I'm going down this path I really don't want to start with bad habits, so please be harsh if needed, I'm thick skinned, some would even say "thick in head" (at least they would in Barnsley) and to be honest I'd tend to agree this isn't easy for me to pick up. The hardest part is reading Lisp, is it now a command, a keyword, a variable or what? at least in Excel with VBA you get some color coding clues in the editor.
    Attached Files
    I've just been down graded from 2012LT to full Autocad 2017. I WANT LT BACK

  2. #2
    Luminous Being Dadgad's Avatar
    Using
    AutoCAD 2013
    Join Date
    Nov 2011
    Location
    At the confluence of worthlessness & invaluability
    Posts
    6,056

    Default

    Congratulations steven-g on taking the plunge.
    In light of some of the really interesting things you have done, and shared in the past, I have no doubt that you will quickly come to grips with it.
    I am reasonably sure you will have researched the wealth of good information, functions and the like which Lee Mac provides on his site.
    Volume and repetition do not validate opinions forged in the absence of thought.

  3. #3
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,800

    Default

    As your starting your in the best position, some of the best are here at cadtutor. Lee-mac of course Tharwat, AlanJT, Ronjonp to mention a few.

    Anyway back on track think about when writing keep stds like p1 pt1 are points txt txt1 are text and so forth. When I was taught programing some 30 + years ago you have stuff like strings numbers, reals and so forth reals X Y integers I J K so be consistent with your variable names, use defuns like Lee, LM: SG: then you know you did it.

    When taught programming one of the important steps is using library functions so think about making a library rather than just continuously copying and pasting code. If you find your repeating steps then make it a defun.

    On a commercial package I was involved in setting up a library as the 1st step was critical for all the layers created you drew an object it always went on the correct layer. The extra step was that the end user defined the layer properties used. It meant a few lines of code not 50+. Think about using data files TXT to store lots of info I have some with 200+ lines that we use in conjunction with our CIV3D.

    Most of the posts here are 1 off's so no real use of a library. But in your end user world think about where your working and dont get into the habit of copy and pasting, I am sure some will disagree.

    I know about one bit of coding submitted here and I sent it back with 6 defuns as the code continually repeated the same steps. The thing was that I had created library routines saving coding time and ensuring the code worked every time.

    You can take advantage of complete routines by people like Lee by just 1 line (if ( not LMxx)(Load "LMXXX)) no need to copy and paste into every routine.

    I have started using dcl's for input where its more than 1 or 2 requests and prefill whenever possible. Again a library function.

    Lastly don't be like me and expect the user to do the right thing try to add some error checking did they pick a block ?

    Code:
    (defun SG:visibility ( )
    (defun C:visoff ()
    
    .......
    )
    Wrap your code in a defun then use (if (not sg:visibilty)(Load "vislisp")) hey its a library routine 1 line in your new code.
    Last edited by BIGAL; 13th Apr 2018 at 11:59 am.
    A man who never made mistakes never made anything

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,267

    Default

    Thank you BIGAL for your nice words.

    @Steven-g, Why did you go with acet-* functions while with AutoLISP vanilla can get the job done the same way and guarantee the routine would work in all releases of AutoCAD?
    So you can highlight / select the objects with the use of this function SSSETFIRST

    Happy coding.

  5. #5
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,490

    Default

    Hi, Steven

    Quote Originally Posted by steven-g View Post
    No question, I am looking for hard critical assesment on any point, if I'm going down this path I really don't want to start with bad habits, so please be harsh if needed
    First very important thing is to localise the variables you use, you probably know this as 'declaring variables' in VBA:

    Code:
    (defun C:visoff ( / ss1 )
      (setq ss1 nil) ; <- you don't need this BTW
      (setq ss1 (ssget))
      (acet-ss-visible ss1 1)
    )
    What this means that when the routine finished with/without error the variables you localised are reset to nil.
    Heres a more elaborated explanation by Lee Mac: Localising Variables

    Second thing you probably know, that has to be done is to use some conditional functions like the if function:

    Code:
    (defun C:visoff ( / ss1 )
      (if (setq ss1 (ssget))
        (acet-ss-visible ss1 1)
      ); if
    )
    Although acet-ss-visible can handle null values, and does't crashes with error - overall its a good practice to make use of the conditionals.
    Somewhere was written "never trust the user", which means theres always a chance to pass the wrong type of inputs.

    Quote Originally Posted by steven-g View Post
    The hardest part is reading Lisp, is it now a command, a keyword, a variable or what? at least in Excel with VBA you get some color coding clues in the editor.
    If you practice alot you'll get used to it, btw VLIDE's console gives enough hints:

    Code:
    _$ (type if)
    SUBR
    _$ (type (lambda (x) x))
    USUBR
    _$ (type "this is a string")
    STR
    _$ (type 1)
    INT
    _$ (type 1.)
    REAL
    _$ (type 'a)
    SYM
    _$ (type nil)
    nil
    Also try not to rely on the acet-* functions.
    The best experience would be to practice here on the forum and post your codes, so you'll recieve advices/critics and build-up your skill.
    You might find this thread kinda related,
    and you can see how I learnt something new there thanks to Tharwat and LM (Now I feel that thread so old, like its been from 2012).

  6. #6
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2017
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,267

    Default

    Thank you Grrr for the nice words.

    Actually the functions acet-ss-visible won't error if the selection set is empty / nil so the conditional statement is that required in this case but its recommended.

  7. #7
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,490

    Default

    Quote Originally Posted by Tharwat View Post
    Thank you Grrr for the nice words.
    Thank you for the constant help all these years!


    Quote Originally Posted by Tharwat View Post
    Actually the functions acet-ss-visible won't error if the selection set is empty / nil so the conditional statement is that required in this case but its recommended.
    I kinda ment the same (but with different words) :

    Quote Originally Posted by Grrr View Post
    Although acet-ss-visible can handle null values, and does't crashes with error - overall its a good practice to make use of the conditionals.
    Somewhere was written "never trust the user", which means theres always a chance to pass the wrong type of inputs.
    Still if Steven coded in VBA he probably would have a good base.

  8. #8
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,800

    Default

    A quick one we use a lot of menu's to start a lisp and then want to run it again later where user knows command.

    Code:
    (defun c:xxxx ( / ......
    .........
    )
    (c:xxxx) ; by adding this at end it will run after load so no need to type 
     at command line note c: must be full defun name
    
    same
    (defun xyzc ( / ....
    ....
    )
    (xyzc) ; non command line version but makes use of localised varaiables.
    A man who never made mistakes never made anything

  9. #9
    Senior Member
    Discipline
    Manufacture
    Using
    AutoCAD 2016
    Join Date
    Apr 2015
    Posts
    102

    Default

    and down the rabbit hole he goes...
    Philip

  10. #10
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    1,106

    Default

    Registered forum members do not see this ad.

    Just start simple (kiss : keep it simple stupid) and steal others programs, make a few changes and see what happens and document (not only for yourself) what it is you want to achieve and / or have changed... but mostly, try not to be intimidated by people with more experience (or brain cells)



Similar Threads

  1. Replies: 1
    Last Post: 28th Jul 2017, 09:27 am
  2. Replies: 14
    Last Post: 24th Mar 2017, 08:23 am
  3. Pause a lisp to interact with a dynamic block and then resume the lisp
    By woodman78 in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 29th May 2015, 10:38 am
  4. [LISP] First time writing LISP routine... trying to rotate, move and scale
    By chiimayred in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 18th Jul 2013, 06:02 pm
  5. Replies: 3
    Last Post: 10th Aug 2010, 04:39 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