+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Administrator CADTutor's Avatar
    Computer Details
    CADTutor's Computer Details
    Operating System:
    Windows 7 Home Premium 64bit
    Motherboard:
    Asus P7P55D-E PRO
    CPU:
    Intel Core i7-860
    RAM:
    4GB PC3-12800 C8 Corsair Dominator
    Graphics:
    NVIDIA Quadro FX 1800 768 MB
    Primary Storage:
    Intel X25-M SSD 160GB
    Secondary Storage:
    Samsung Spinpoint 320GB
    Monitor:
    BenQ FP241W 24" Wide
    Discipline
    Education
    CADTutor's Discipline Details
    Occupation
    Senior Lecturer (Digital Design), Landscape Architect & Web Designer
    Discipline
    Education
    Using
    AutoCAD 2015
    Join Date
    Aug 2002
    Location
    Hampshire, UK
    Posts
    3,690

    Default How to use the LISP routines in this archive

    Registered forum members do not see this ad.

    How to use the LISP routines in this archive

    All of the lisp code posted on this bulletin board may be run on your own installation of AutoCAD. The basic process is pretty simple and is set out below. There are 3 main steps, creating the lisp file, loading the lisp file and running the lisp routine.

    Note: AutoLISP routines will only run on full versions of AutoCAD, they will not run on AutoCAD LT.

    Creating the lisp file

    Copy and paste all of the text in the Code: box into Windows Notepad. Take care not to miss anything out. Below is an example:

    Code:
    (defun c:zone ( / ss la rv i tv op en) 
     
       (while (not ss) 
              (princ "\nPick any object on the required layer") 
              (setq ss (ssget))) 
     
       (initget "Length Area") 
       (setq rv (getkword "\nWould you like to measure Length/<Area> : ")) 
       (and (not rv) 
            (setq rv "Area")) 
     
       (setq la (cdr (assoc 8 (entget (ssname ss 0)))) 
             ss (ssget "X" (list (cons 0 "*POLYLINE") 
                                 (cons 8 la))) 
              i (sslength ss) 
             tv 0 
             op 0) 
       (while (not (minusp (setq i (1- i)))) 
              (setq en (ssname ss i)) 
              (command "_.AREA" "_E" en) 
              (cond ((= rv "Length") 
                     (setq tv (+ tv (getvar "PERIMETER")))) 
                    (T 
                     (setq tv (+ tv (getvar "AREA"))) 
                     (if (/= (logand (cdr (assoc 70 (entget en))) 1) 1) 
                         (setq op (1+ op)))))) 
     
       (princ (strcat "\nTotal " rv 
                      " for layer " la 
                      " = " (rtos tv 2 2) 
                      " in " (itoa (sslength ss)) " polylines\n" 
                      (if (/= rv "Length") 
                          (strcat (itoa op) " with open polylines") ""))) 
       (prin1))
    When you have pasted the code into Notepad, you should have something like this:



    You must now save the file. You can call it whatever you like as long as it has a .LSP file extension but it is always a good idea to give the file the same name at the lisp routine to avoid confusion. You will always find the name of the routine preceded with a c: at the beginning of the code. In the example above, you will see that that the routine is called "zone". So, in this case, the file should be saved as zone.lsp.

    Loading the lisp file

    Next, open AutoCAD and select ToolsAutoLISPLoad... from the pull-down menu. You will see the dialogue box shown below:



    Use the following sequence to load zone.lsp:

    1. Navigate to the folder where you saved the lisp file.
    2. Select the file you want from the list.
    3. Click the Load button.
    If all went well, you will see a message saying "zone.lsp successfully loaded".
    4. Click the Close button to close the dialogue box.

    Running the lisp routine

    Once the lisp file is loaded, you can run the routine from the command line. The routine is run simply by entering its name. In this example, enter zone at the command line. Remember, the routine name is the bit following the c: near the beginning of the code.

    Tip: You may also load the lisp file by dragging-and-dropping the file icon onto the AutoCAD drawing area.
    Tip: Please do not PM or email me with CAD questions - use the forums, you'll get an answer sooner.
    AutoCAD Tutorials | How to add images to your posts | How to register successfully | Forum FAQ

  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
    16,840

    Default

    Additional Loading Instructions

    In addition to the above advice, there are a few other filetypes to be aware of when delving into the world of LISP programming.

    VLX/FAS Files

    You may discover that some programs are posted in the form of either a .VLX or .FAS file. These are programs that have been compiled into one file to make them not only easier to load (with only one file to deal with), but also more secure as far as code protection is concerned.

    To load a .VLX or .FAS file, just save the file to a known location, and follow the instructions in the above post, as if you were dealing with a LISP file. Of course, the syntax to invoke the function is not readily available, but may be either provided by the program developer, or appear at the command line upon loading the file.

    DCL Files

    DCL (Dialog Control Language) gives the user the ability to create dialog boxes with relative ease. These files run in conjunction with LISP files, and may be compiled with the relevant LISP file into a VLX or FAS file.

    DCL language looks like this:

    Code:
    // Increment Numerical Text Sign Selector
    
    adder : dialog { label = "Specify Increment Direction";
          : text { label = ""; key = "sel_text"; alignment = centered; }
          : row {
             : button { label = "+1"; key = "sel_add"; fixed_width = true; mnemonic = "+"; }
             : button { label = "-1"; key = "sel_sub"; fixed_width = true; mnemonic = "-"; }
          } // row
    ok_only;
    } // dialog
    To run a program that uses a DCL file, save the provided DCL file into your AutoCAD Search Path.

    The AutoCAD Search Path is normally found:

    C:\Program Files\AutoCAD <version>\Support\

    But additonal Search Path locations may be added by going to:

    Tools > Options > Files (tab) > Support File Search Path

    And adding a new filepath.

    The LISP file associated with the DCL file can be loaded and run as normal, using the instructions provided in the above post.

    If you are still puzzled, search the forums, or our FAQ for more information.

    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

  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
    16,840

    Default

    Registered forum members do not see this ad.

    "; error: no function definition: vlax-get-acad-object"

    "; error: no function definition: vlax-ename->vla-object"


    If you find yourself receiving either of these errors, this is an indication that the Visual LISP ActiveX functions required by some programs have not been loaded on your system.

    The Visual LISP ActiveX functions can be loaded using the (vl-load-com) function.

    This function need only be called once per session to ensure the functions are available throughout the drawing session, hence many users will have (vl-load-com) located at the top of their ACADDOC.lsp / ACAD.lsp customisation files so that it may be loaded on startup. For this reason, a developer may not notice the omission of this function in their program.

    If you are receiving one of the above error messages when running a program, simply add (vl-load-com) on a new-line at the top of the relevant LISP file.

    Example:

    Code without
    (vl-load-com) :
    Code:
    (defun c:test ( / )
        (vlax-get-acad-object)
        (princ)
    )
    Modified:
    Code:
    (vl-load-com)
    (defun c:test ( / )
        (vlax-get-acad-object)
        (princ)
    )
    If you are still stuck, search the forums/FAQ for more help.
    Last edited by Lee Mac; 2nd Aug 2012 at 11:30 pm.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

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

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