+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 22
  1. #1
    Senior Member tomhamlet's Avatar
    Computer Details
    tomhamlet's Computer Details
    Operating System:
    Windows 7
    Computer:
    DELL Desktop
    CPU:
    AMD phenom 2 (6 core)
    RAM:
    6gig
    Graphics:
    1 gig
    Primary Storage:
    1 tb
    Monitor:
    Dell widescreen
    Discipline
    See details...
    tomhamlet's Discipline Details
    Occupation
    mechanical engineer, draftsman
    Discipline
    See details below.
    Details
    At Denios, we design storage and containment units for hazerdous materials. We also design cranes, racks, or whatever the customer needs.
    Using
    Mechanical 2011
    Join Date
    Oct 2012
    Location
    Louisville, KY
    Posts
    122

    Default First Lisp Written Solo!

    Registered forum members do not see this ad.

    I have been getting back into lisp, after I had a class that scratched the surface of lisp, I never looked back on it until now. This is my first lisp command written without copying it from a book!
    Code:
    (defun c:ibeamp()
    (setq pw (getdist "\nEnter Beam Width: "))
    (setq ih (getdist "\nEnter Inner Height: "))
    (setq pt (getdist "\nEnter Plate Thickness: "))
    (setq po (getdist "\nEnter Overhang Distance: "))
    (setq ip (getpoint "\nInsertion point: "))
    (setq p2 (polar ip (dtr 180.0) (/ pw 2)))
    (setq p3 (polar p2 (dtr 270.0) pt))
    (setq p4 (polar p3 (dtr 0.0) po))
    (setq p5 (polar p4 (dtr 270.0) ih))
    (setq p6 (polar p5 (dtr 180.0) po))
    (setq p7 (polar p6 (dtr 270.0) pt))
    (setq p8 (polar p7 (dtr 0.0) pw))
    (setq p9 (polar p8 (dtr 90.0) pt))
    (setq p10 (polar p9 (dtr 180.0) po))
    (setq p11 (polar p10 (dtr 90.0) ih))
    (setq p12 (polar p11 (dtr 0.0) po))
    (setq p13 (polar p12 (dtr 90.0) pt))
    (command "line" ip p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 "c"
    )
    (princ)
    )
    (defun dtr (x)
    (* pi (/ x 180.0))
    )
    (princ)
    this draws a very general I-beam. Any feedback is appreciated, constructive more so
    Hard work beats talent every time talent doesn't work hard.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Quote Originally Posted by tomhamlet View Post
    Any feedback is appreciated, constructive more so
    On first glance: be sure to Localise your Variables
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    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
    4,008

    Default

    Some observations:
    • To make sure that avoid any interference with current auto Osnap mode, you need to disable it when call the command - check the OSMODE system variable. Also, a good programming practice is to retain the user environment and restore it at the end.
    Code:
    (setq oldOsmode (getvar "OSMODE"))
    (setvar "OSMODE" 0)
    ;call commands
    (setvar "OSMODE" oldOsmode)
    • In order to avoid interference with other routines you should use local variables:
    Code:
    (defun c:ibeamp( / pv ih pt po ...)
    • To ensure that your code works well with localized versions of AutoCAD (that it, in languages other than English) use an uderscore when call commands and options:
    Code:
    (command "_.LINE" ... "_C")
    • Not less important is to get used to add comments to your code; it will be very useful when decide to review it later.
    Regards,
    Mircea

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

  4. #4
    Senior Member tomhamlet's Avatar
    Computer Details
    tomhamlet's Computer Details
    Operating System:
    Windows 7
    Computer:
    DELL Desktop
    CPU:
    AMD phenom 2 (6 core)
    RAM:
    6gig
    Graphics:
    1 gig
    Primary Storage:
    1 tb
    Monitor:
    Dell widescreen
    Discipline
    See details...
    tomhamlet's Discipline Details
    Occupation
    mechanical engineer, draftsman
    Discipline
    See details below.
    Details
    At Denios, we design storage and containment units for hazerdous materials. We also design cranes, racks, or whatever the customer needs.
    Using
    Mechanical 2011
    Join Date
    Oct 2012
    Location
    Louisville, KY
    Posts
    122

    Default

    great!
    Code:
    (defun c:ibeamp(pw ih pt po ip)
    (setq pw (getdist "\nEnter Beam Width: "))
    (setq ih (getdist "\nEnter Inner Height: "))
    (setq pt (getdist "\nEnter Plate Thickness: "))
    (setq po (getdist "\nEnter Overhang Distance: "))
    (setq ip (getpoint "\nInsertion point: "))
    (setq p2 (polar ip (dtr 180.0) (/ pw 2)))
    (setq p3 (polar p2 (dtr 270.0) pt))
    (setq p4 (polar p3 (dtr 0.0) po))
    (setq p5 (polar p4 (dtr 270.0) ih))
    (setq p6 (polar p5 (dtr 180.0) po))
    (setq p7 (polar p6 (dtr 270.0) pt))
    (setq p8 (polar p7 (dtr 0.0) pw))
    (setq p9 (polar p8 (dtr 90.0) pt))
    (setq p10 (polar p9 (dtr 180.0) po))
    (setq p11 (polar p10 (dtr 90.0) ih))
    (setq p12 (polar p11 (dtr 0.0) po))
    (setq p13 (polar p12 (dtr 90.0) pt))
    (command "line" ip p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 "c"
    )
    (princ)
    )
    (defun dtr (x)
    (* pi (/ x 180.0))
    )
    (princ)
    is this what you mean?
    Hard work beats talent every time talent doesn't work hard.

  5. #5
    Luminous Being BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    2 x 240GB Samsung EVO SSD (RAID 0)
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Discipline
    Civil
    BlackBox's Discipline Details
    Occupation
    Senior Civil Designer
    Discipline
    Civil
    Details
    Public/Private Land Development, Transportation, and Utilities.
    Using
    Civil 3D 2016
    Join Date
    Nov 2009
    Posts
    5,282

    Default

    First, congrats on writing your first LISP.

    ... One thing to beware, if you prompt the user for input and they do not enter a valid response, you need to account for that rather than allowing the code to progress as this may cause an error.

    As an example, consider pw = nil.

    One common way of mitigating this is to use an IF statement, and in your case an AND statement may also be helpful.
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Sincpac C3D ~ Exchange Apps ~ Autoloader ~ AutoCAD Security

  6. #6
    Senior Member tomhamlet's Avatar
    Computer Details
    tomhamlet's Computer Details
    Operating System:
    Windows 7
    Computer:
    DELL Desktop
    CPU:
    AMD phenom 2 (6 core)
    RAM:
    6gig
    Graphics:
    1 gig
    Primary Storage:
    1 tb
    Monitor:
    Dell widescreen
    Discipline
    See details...
    tomhamlet's Discipline Details
    Occupation
    mechanical engineer, draftsman
    Discipline
    See details below.
    Details
    At Denios, we design storage and containment units for hazerdous materials. We also design cranes, racks, or whatever the customer needs.
    Using
    Mechanical 2011
    Join Date
    Oct 2012
    Location
    Louisville, KY
    Posts
    122

    Default

    Quote Originally Posted by RenderMan View Post
    First, congrats on writing your first LISP.

    ... One thing to beware, if you prompt the user for input and they do not enter a valid response, you need to account for that rather than allowing the code to progress as this may cause an error.

    As an example, consider pw = nil.

    One common way of mitigating this is to use an IF statement, and in your case an AND statement may also be helpful.
    I do want to get into the IF and And commands soon. but im making sure I know what these routine do first. Thank you!
    Hard work beats talent every time talent doesn't work hard.

  7. #7
    Luminous Being BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    2 x 240GB Samsung EVO SSD (RAID 0)
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Discipline
    Civil
    BlackBox's Discipline Details
    Occupation
    Senior Civil Designer
    Discipline
    Civil
    Details
    Public/Private Land Development, Transportation, and Utilities.
    Using
    Civil 3D 2016
    Join Date
    Nov 2009
    Posts
    5,282

    Default

    Quote Originally Posted by tomhamlet View Post
    I do want to get into the IF and And commands soon. but im making sure I know what these routine do first. Thank you!
    In an attempt to give you an example that does not remove the excitement from having written your first routine, please take from this pseudo code example what you like (building on multiple comments):

    Code:
    (defun c:FOO ( / ;|localVariables|; pw ih pt po ip)
    
      ;; If, the user enters all of the necessary criteria
      (if (and (setq pw (getdist "\nEnter Beam Width: "))
               (setq ih (getdist "\nEnter Inner Height: "))
               (setq pt (getdist "\nEnter Plate Thickness: "))
               (setq po (getdist "\nEnter Overhang Distance: "))
               (setq ip (getpoint "\nInsertion point: "))
          )
    
        ;; Then, continue the routine
        (prompt
          "\nThanks for entering all of the necessary criteria. "
        )
    
        ;; Else, tell the user what they failed to specify
        (cond (po (prompt "\n** Insertion point required ** "))
              (pt (prompt "\n** Overhang distance required ** "))
              (ih (prompt "\n** Plate thickness required ** "))
              (pw (prompt "\n** Inner height required ** "))
              ((prompt "\n** Beam width required ** "))
        )
      )
      (princ)
    )
    Last edited by BlackBox; 8th Nov 2012 at 12:41 am.
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Sincpac C3D ~ Exchange Apps ~ Autoloader ~ AutoCAD Security

  8. #8
    Senior Member tomhamlet's Avatar
    Computer Details
    tomhamlet's Computer Details
    Operating System:
    Windows 7
    Computer:
    DELL Desktop
    CPU:
    AMD phenom 2 (6 core)
    RAM:
    6gig
    Graphics:
    1 gig
    Primary Storage:
    1 tb
    Monitor:
    Dell widescreen
    Discipline
    See details...
    tomhamlet's Discipline Details
    Occupation
    mechanical engineer, draftsman
    Discipline
    See details below.
    Details
    At Denios, we design storage and containment units for hazerdous materials. We also design cranes, racks, or whatever the customer needs.
    Using
    Mechanical 2011
    Join Date
    Oct 2012
    Location
    Louisville, KY
    Posts
    122

    Default

    [QUOTE=RenderMan;506123]In an attempt to give you an example that does not remove the excitement from having written your first routine, please take from this pseudo code example what you like (building on multiple comments):

    thanks. I will definately give it a shot!
    Hard work beats talent every time talent doesn't work hard.

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Quote Originally Posted by RenderMan View Post
    Code:
    (defun c:FOO (;|globalVariables|; / ;|localVariables|; pw ih pt po ip)
    The above highlighted section should instead read 'function parameters', as global variables are not declared in the defun expression.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Luminous Being BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    2 x 240GB Samsung EVO SSD (RAID 0)
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Discipline
    Civil
    BlackBox's Discipline Details
    Occupation
    Senior Civil Designer
    Discipline
    Civil
    Details
    Public/Private Land Development, Transportation, and Utilities.
    Using
    Civil 3D 2016
    Join Date
    Nov 2009
    Posts
    5,282

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Lee Mac View Post
    The above highlighted section should instead read 'function parameters', as global variables are not declared in the defun expression.
    Good catch, Lee; code corrected (oops).
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Sincpac C3D ~ Exchange Apps ~ Autoloader ~ AutoCAD Security

Similar Threads

  1. Replies: 3
    Last Post: 10th Aug 2010, 04:39 am
  2. Profile gets over-written
    By antheads in forum AutoCAD General
    Replies: 0
    Last Post: 15th Feb 2010, 09:49 am
  3. remember what was written
    By Ferronovum in forum Feedback
    Replies: 11
    Last Post: 10th Feb 2009, 02:36 pm
  4. Have Written first independent LISP but AutoCAD says Unknown Command.
    By skipsophrenic in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 8th Jan 2009, 06:33 pm
  5. inputting hand written survey points to CAD
    By scubadoo in forum AutoCAD General
    Replies: 31
    Last Post: 22nd Nov 2007, 11:36 pm

Tags for this Thread

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