Las Vegas, Nevada, December 3 6, 2002 Speaker Name: R. Robert Bell Course Title: Mastering the Visual LISP Integrated Development Environment (IDE) Course ID: CP42-1 Course Outline: The introduction of the Visual LISP IDE in AutoCAD 2000 added some powerful tools for the Visual LISP (AutoLISP ) programmer. The VLIDE is not simply a pretty text editor with parenthesis checking, although that feature alone is of great benefit. Would you like to understand the other benefits the VLIDE delivers? This course will explain the following features: Programming Aids o Console o Inspect feature o Trace command and window o Symbol Service feature o Apropos feature o Project feature o Application Wizard Debugging Tools o Break on Error o Watch o Breakpoints/Stepping o Animate Formatting Options o Expression styles o Closing paren styles o List styles o Comment styles o Miscellaneous options
Mastering the Visual LISP Integrated Development Environment (IDE) Here is the code that will be used during the class: ; Trace.lsp v1.0 Demonstrates the Trace function. To be run from the console. (trace I:Double) (Test) View the trace window. (untrace I:Double) ; (defun I:Double (Number) (* Number 2)) (defun Test (/ Number) (setq Number 1) (repeat 10 (setq Number (I:Double Number))) (princ)) ; Symbol.lsp v1.0 Demonstrates changing a variable's value using the Symbol Service. Run the function once from the console. (Test 2) Observe the return value. Place a breakpoint at the beginning of the expression (* 2 inpnum). Run the function again. (Test 2) When you reach the breakpoint, use the Symbol Service to change inpnum to 4. ; (defun Test (inpnum) (* 2 inpnum)) The following code will be used to demonstrate the Project feature. ; EntSelF.lsp from AcadX.com ; (defun I:EntSelF (Msg ; selection prompt Filter ; filter list / EntN ; (entsel) list pbdist ; pickbox size in drawing units PtPick ; point of selection from (entsel) sspick) ; selection set (setvar "ErrNo" 0) ; clear ErrNo for loop (while (and (not (setq EntN (if Msg ; if selection prompt www.autodesk.com 2
Mastering the Visual LISP Integrated Development Environment (IDE) (entsel Msg) ; then (entsel) w/prompt (entsel)))) ; while no selection (or no exit) (/= 52 (getvar "ErrNo")))) ; if null response (cond (EntN ; if not exit (setq pbdist (abs ; return absolute number, get pixel ratio (/ (* (/ (getvar "PickBox") (cadr (getvar "ScreenSize"))) (getvar "ViewSize")) ; apply to viewsize (in units) (sin (* 0.25 pi)))) ; at 45 PtPick (cadr EntN)) ; get point of pick (if (setq sspick (ssget "_C" ; if entities in crossing (polar PtPick (* 1.25 pi) pbdist) ; lower left (polar PtPick (* 0.25 pi) pbdist) ; upper right Filter)) ; match filter, if any (cons (ssname sspick 0) (list PtPick)))))) ; then return first entity as (entsel) ; AttGet.lsp from AcadX.com ; (defun I:AttGet (Ent AttTag / DxfVal ; entity type Done) ; flag to exit loop (while (not Done) ; loop until done (cond ((and (= "ATTRIB" (setq DxfVal (cdr (assoc 0 Ent)))) ; if sub-entity is an attdef (= (cdr (assoc 2 Ent)) AttTag)) ; and matching attribute (setq Done T)) ; then exit loop ((= "SEQEND" DxfVal) ; if at end of block's entities (setq Done T ; then exit loop Ent nil))) ; clear entity data (if (not Done) ; if not done (setq Ent (entget (entnext (cdr (assoc -1 Ent))))))) ; then get next entity Ent) ; return entity data ; Sheet.lsp Displays the value of the Sheet# attribute. ; (defun C:Sheet (/ eblk eatt) (setq eblk (I:EntSelF "\nselect titleblock: " ; get titleblock '((2. "Title Block")))) ; filter for specific name (cond (eblk ; if titleblock selected (setq eatt (I:AttGet (entget (car eblk)) "SHEET#")) ; get value of Sheet# (alert (strcat "Sheet number: " (cdr (assoc 1 eatt)))))) ; display value (princ)) ; clean exit www.autodesk.com 3
Mastering the Visual LISP Integrated Development Environment (IDE) The following code is used to demonstrate the 5 commenting styles. ; Comment.lsp v1.0 Return the active document's name. Used to demonstrate the 5 commenting styles. ; (defun C:Test () ;;; returns a string (vla-get-name ; get name (vla-get-activedocument ;; ThisDrawing (vlax-get-acad-object)))) ;_ closes defun www.autodesk.com 4
Mastering the Visual LISP Integrated Development Environment (IDE) Speaker s Name: R. Robert Bell Course ID: CP42-1 Course Outline: This course will explain many of the features, tools, and options in the VLIDE. The student will have a better understanding of how the VLIDE is useful. Expectations You will learn about the VLIDE: Programming aids. Debugging tools. Formatting options. Who Is R. Robert Bell? Network Administrator for MW Consulting Engineers (A/E/C) since 1988. Writing code since 1983. AutoLISP since AutoCAD v2.5 Visual LISP since 1999 AUGI VBA Guild Moderator and self-admitted Autodesk newsgroup junkie. Member of AcadX.com, helping you customize AutoCAD. Image courtesy of Berke Breathed
Now, About You How many wrote most of their code in AutoLISP? What text editor did you use? How many have written lots of AutoLISP code since AutoCAD 2000, and are comfortable with the VLIDE? How many program in other languages, such as VB(A)? Programming Features of the VLIDE Console Inspect feature Trace command and window Symbol Service feature Apropos feature Project feature Application Wizard The Console Perform expressions Examine variables Recall previous actions with <Tab> Clear the window
The Inspect Feature Examine variables (usually during a breakpoint). Expression results. Copy object to *obj*. Drill-down for more information. The Trace Command and Window (trace func) (untrace func) Many prefer watches and breakpoints. (vl-bt), for the diehards. (defun *Error* (Err) (if (not (member Err '("console break" "Function cancelled" "quit / exit abort"))) (vl-bt)) (princ)) The Symbol Service Feature Permits you to see/change the value of a symbol. Add the symbol to the Watch Window. If the symbol is a USUBR, you can use Show Definition to display the code.
The Apropos Feature Searches the symbol table. Even sees symbols that are local to functions. Match by prefix option. Use WCMatch style filtering. Use the help button to see the help file for SUBRs. The Project Feature Use to manage the files for an application. Files are loaded in the order listed. Assign compile options for the project (FAS files). The Application Wizard The wizard makes compiling a Visual LISP application easy. The defaults are usually sufficient for average applications. Note: Contrary to documentation, VBA projects are not accessible.
Debugging Tools of the VLIDE Break on Error Watch Breakpoints/Stepping Animate The Watch Window You can watch: The value of a variable. The result of an expression. The last value/result. Using Breakpoints You may set breakpoints wherever you want. Use the <F9> key, or the toolbar button. Show the last break source. Debug on Entry into a function by Symbol Service. You may also deactivate breakpoints, instead of simply removing them.
Manually Stepping Thru Your Code Stepping is active when: Errors occur and Break on Error is set. Reaching an enabled breakpoint. Step options: Step into. Step over. Step out. Continue. Reset. Quit. The Animate Feature This will run your code, lineby-line, at a specified interval. Understanding the Formatting Options You may modify the options so that your code is formatted the way you like (in most cases). It is possible to format your code with the touch of a button.
Plane Style (for Expressions) (I:AttGet Ent AttTag) All the arguments are on the same line. All the arguments are separated by a single space. Affected by: Right Text Margin. Printing length must be less than Approximate Line Length. Wide Style (for Expressions) (I:AttGet Ent AttTag) First argument on the same line. Remaining arguments lined up below. Affected by: 1 st element (I:AttGet above) must be a SYM. Maximum Wide-Style Car Length for the SYM. Narrow Style (for Expressions) (I:AttGet Ent AttTag) All arguments on a new line. Affected by: Narrow Style Indentation determines number of spaces for the indent.
Column Style (for Expressions) (cond (test1 ; code ;) (test2 ; code ;) (test3 ; code ;)) All elements are positioned in a column. You will see this on quoted lists and (cond) expressions. Close At the Same Line Pros: Results in compact code. Cons: Must rely on paren checker to determine nesting. Moves argument/local variable parens right 1 space. (defun C:Test () (vla-get-name (vla-get-activedocument (vlax-get-acad-object)))) Close With Inner Indentation (defun C:Test () (vla-get-name (vla-get-activedocument (vlax-get-acad-object) Pros: ) Helps to see nesting level. ) ) Cons: Opening/closing parens do not line up. Unnecessarily long code.
Close With Outer Indentation Pros: Helps to see nesting level. Opening/closing parens line up. Cons: Unnecessarily long code. (defun C:Test () (vla-get-name (vla-get-activedocument (vlax-get-acad-object) ) ) ) Insert Form-Closing Comment (defun C:Test () (vla-get-name (vla-get-activedocument (vlax-get-acad-object) ) ;_ closes vla-get-activedocument ) ;_ closes vla-get-name ) ;_ closes defun Automatically adds a comment to lonely closing parens. Does not change if the statement is changed. Lots of deleting if you want to clean them up. Additional Format Options Preserve existing line breaks only if you love your current format. Split comments if your comments exceed right margin. Many like to force protected symbols to lowercase.
Long List Format Options Single-column (setq alist '(123 456 789 123 456 789 123 456 789)) 2-column (setq alist '(123 456 789 123 456 789 123 456 789)) Multi-column (setq alist '(123 456 789 123 456 789 123 456 789)) Fill-to-margin (setq alist '(123 456 789 123 456 789 123 456 789)) Page Setup Options (for Printing) Don t limit the amount of code that you can print on a page! Adjust your margins. Alter your font to a smaller size if you are only documenting. Header & footer codes are well documented. Window Attributes (Syntax Color) Top row of colors is the foreground color. Bottom row is the background color.
Syntax Colors Spaces String Symbols Integer Real Non-inline comments Inline comments Parens Unknown Variable/arguments Selected text Enabled breakpoints Disabled breakpoints Error messages in Build Output The 5 Commenting Styles ; Comment.lsp v1.0 Return the active document's name. ; (defun C:Test () ;;; returns a string (vla-get-name ; get name (vla-get-activedocument ;; ThisDrawing (vlax-get-acad-object)))) ;_ closes defun Wrap-up The VLIDE provides many features Programming aids Console Inspect Apropos Debugging tools Watch Breakpoints/Stepping Formatting options Close at the same line Multiple commenting styles
Questions Thank You Thank you for attending this course! Please don t forget to fill out the evaluation forms. Course name: Mastering the Visual LISP Integrated Development Environment (IDE) Course number: CP42-1 My Name: R. Robert Bell