+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Full Member
    Computer Details
    chiimayred's Computer Details
    Operating System:
    Windows 7 64-bit
    Using
    Civil 3D 2014
    Join Date
    Jul 2013
    Posts
    48

    Default [LISP] First time writing LISP routine... trying to rotate, move and scale

    Registered forum members do not see this ad.

    Hi guys,

    Total newb here, did some reading in the tutorials area in how to write lisps and I'm having issues with it not working. I'm trying to start off really simple hence the rotate, move and scale. This is my first time trying to program so please bear with me.

    Here is the code:

    Code:
    (defun C:firstprog ()
    (command "ro" all 1,2 45)
    (command "m" all 0,0 50,50)
    (command "sc" 0,0 25.4)
    )
    When I try to run this i get an error: nil

    Any help would be appreciated.
    Last edited by chiimayred; 17th Jul 2013 at 03:00 pm. Reason: Newb to forum, added code posting

  2. #2
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    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 2018
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,883

    Default

    Start with reading Code posting guidelines and place your Code in Code Tags.
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



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

    Default

    Welcome to CADTutor

    Here are some comments to get you started:
    Code:
    (defun c:firstprog ( )
        (command
            "_.rotate"
            ;; Always use full command name
            ;; "_" = use english version of command
            ;; "." = use non-redefined version of command
            "_all" ;; Use underscore to use english version of keywords
            ""     ;; Equivalent to user pressing Enter
            "_non" ;; None Object Snap modifier - ignore object snap
            '(1 2) ;; Quoted literal list
            45.0
            "_move"
            "_all"
            ""
            "_non"
            '(0 0)
            "_non"
            '(50 50)
            "_.scale"
            "_all"
            ""
            "_non"
            '(0 0)
            25.4
        )
        (princ) ;; Suppress the return of the command expression (would return nil otherwise)
    )
    One reason that your original code is causing an error is because the 'all' string is not enclosed with string delimiters (quotation marks, e.g. "all") and hence is being interpreted as a variable to be evaluated. However, since the 'all' symbol has no value in your program (i.e. it has not been defined using setq / set), it will evaluate to nil, causing the error.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  4. #4
    Full Member
    Computer Details
    chiimayred's Computer Details
    Operating System:
    Windows 7 64-bit
    Using
    Civil 3D 2014
    Join Date
    Jul 2013
    Posts
    48

    Default

    Quote Originally Posted by Lee Mac View Post
    Welcome to CADTutor

    Here are some comments to get you started:
    Code:
    (defun c:firstprog ( )
        (command
            "_.rotate"
            ;; Always use full command name
            ;; "_" = use english version of command
            ;; "." = use non-redefined version of command
            "_all" ;; Use underscore to use english version of keywords
            ""     ;; Equivalent to user pressing Enter
            "_non" ;; None Object Snap modifier - ignore object snap
            '(1 2) ;; Quoted literal list
            45.0
            "_move"
            "_all"
            ""
            "_non"
            '(0 0)
            "_non"
            '(50 50)
            "_.scale"
            "_all"
            ""
            "_non"
            '(0 0)
            25.4
        )
        (princ) ;; Suppress the return of the command expression (would return nil otherwise)
    )
    One reason that your original code is causing an error is because the 'all' string is not enclosed with string delimiters (quotation marks, e.g. "all") and hence is being interpreted as a variable to be evaluated. However, since the 'all' symbol has no value in your program (i.e. it has not been defined using setq / set), it will evaluate to nil, causing the error.
    Thanks Lee Mac!

    Would there be any chance you could explain your philosophy for doing it that way? It would be greatly appreciated.

  5. #5
    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,418

    Default

    Quote Originally Posted by chiimayred View Post
    Would there be any chance you could explain your philosophy for doing it that way?
    Is there a specific part of the code that you do not understand?
    Have you read my comments?
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  6. #6
    Full Member
    Computer Details
    chiimayred's Computer Details
    Operating System:
    Windows 7 64-bit
    Using
    Civil 3D 2014
    Join Date
    Jul 2013
    Posts
    48

    Default

    I have, it's mostly why I would want to use the "_non", everything else i can understand why.

    Also, here is an updated version of the code and I'm getting an error: nil still... can't figure it out, can you please help me troubleshoot it

    Code:
    (defun C:firstprog ( )
      (command
        "_.rotate"
        "_all"
        ""
        "_non"
        '(1 2)
        45
        "_move"
        "_all"
        ""
        "_non"
        '(0 0)
        "_non"
        '(50 50)
        "_.scale"
        "_all"
        ""
        '(0 0) 
        25.4
        )
      (princ)
    )
    Edit: Figured it out... didn't add the "" after the selection from scaling, which caused the error.

    Thanks for your help!
    Last edited by chiimayred; 17th Jul 2013 at 04:26 pm. Reason: missing words

  7. #7
    Senior Member
    Using
    AutoCAD 2011
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    115

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by chiimayred View Post
    I have, it's mostly why I would want to use the "_non", everything else i can understand why.
    "_non" is used to ignore OSnaps, it sets a temporary value of "None"

Similar Threads

  1. Fixing my record time lisp routine???
    By jim_archi4 in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 24th Oct 2011, 02:45 pm
  2. a lisp routine to have an object rotate 360
    By djw in forum AutoLISP, Visual LISP & DCL
    Replies: 32
    Last Post: 29th Jun 2010, 12:09 pm
  3. Rotate, move attributes lisp
    By Astro in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 30th Sep 2009, 02:05 pm
  4. Move Rotate Lisp needed
    By JeepMaster in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 11th Jul 2008, 09:22 pm
  5. RT - Rotate crosshairs Lisp routine.
    By JimWebster in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 16th Mar 2005, 03:01 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