las vegas, nevada, december 3–6, 2002 - augi

16
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

Upload: others

Post on 30-Nov-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

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)

www.autodesk.com 2

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

Mastering the Visual LISP™ Integrated Development Environment (IDE)

www.autodesk.com 3

(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

Mastering the Visual LISP™ Integrated Development Environment (IDE)

www.autodesk.com 4

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

1

Mastering the Visual LISP™ Integrated Development Environment (IDE)

Speaker’s Name: R. Robert BellCourse ID: CP42-1Course 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

2

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 VLIDEConsoleInspect featureTrace command and windowSymbol Service featureApropos featureProject featureApplication Wizard

The Console

Perform expressionsExamine variablesRecall previous actions with <Tab>Clear the window

3

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)

(defun *Error* (Err)(if (not

(member Err'("console break"

"Function cancelled""quit / exit abort")))

(vl-bt))(princ))

Many prefer watches and breakpoints.(vl-bt), for the diehards.

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.

4

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

Files are loaded in the order listed.Assign compile options for the project (FAS files).

Use to manage the files for an application.

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.

5

Debugging Tools of the VLIDEBreak on ErrorWatchBreakpoints/SteppingAnimate

The Watch Window

You can watch:• The value of a variable.• The result of an expression.• The last value/result.

Using BreakpointsYou may set breakpoints wherever you want.• Use the <F9> key, or the toolbar button.

Debug on Entry into a function by Symbol Service.

Show the last break source.

You may also deactivate breakpoints, instead of simply removing them.

6

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 FeatureThis will run your code, line-by-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.

7

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:• 1st 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.

8

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

Pros:• Helps to see nesting level.

Cons:• Opening/closing parens do not line up.

• Unnecessarily long code.

(defun C:Test ()

|(vla-Get-Name

||(vla-Get-ActiveDocument

|||(vlax-Get-Acad-Object)

|||)

||)

|)

9

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

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.

(defun C:Test ()

(vla-Get-Name

(vla-Get-ActiveDocument

(vlax-Get-Acad-Object)

)

)

)

;_ closes vla-Get-ActiveDocument

;_ closes vla-Get-Name

;_ closes defun

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.

10

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.

11

Syntax ColorsSpacesStringSymbolsIntegerRealNon-inline commentsInline commentsParensUnknown Variable/argumentsSelected textEnabled breakpointsDisabled breakpointsError 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

12

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