280 likes | 397 Views
Enforcing CAD Standards Using Visual LISP ®. R. Robert Bell Design Technology Manager, Sparling. Expectations. You do NOT need to know Visual LISP You will be exposed to some Visual LISP code. R. Robert Bell.
E N D
Enforcing CAD Standards Using Visual LISP® R. Robert Bell Design Technology Manager, Sparling
Expectations • You do NOT need to know Visual LISP • You will be exposed to some Visual LISP code
R. Robert Bell • Design Technology Manager at Sparling since 2007(largest US electrical specialty firm) • Former network administrator at an MEP firm for 19 years • Writing code since 1983 • Former AUGI Director • Self-admitted Autodesk/AUGI discussion group junkie • Active participant in Autodesk Beta Programs • Published author
Getting to Know You • How many have been CAD Managers for more than 2 years? • How many have little or no programming in AutoCAD?
File Load Order • Acad20xx.lsp • Acad.rx • Acad.lsp • Acad20xxDoc.lsp • AcadDoc.lsp • MNL files • CUIx LISP Node • S::Startup
Acad.rx • Text-based file • Loads ARX files • Filenames listed will load automatically
Acad.lsp • Text-based file • Contains Visual LISP code • Executes only once per AutoCAD session • Leave AcadLspAsDoc=0
AcadDoc.lsp • Text-based file • Contains Visual LISP code • Executes every time a drawing is opened
MNL Files • Text-based file • Contains Visual LISP code • Executes every time a drawing is opened • Loads automatically as part of the CUIx
CUIx LISP Node • Part of the CUIx • Executes every time a drawing is opened • Loads the LSP file
S::Startup • Special Visual LISP function • Executes every time a drawing is opened • Executes after the command line is available • Append code to S::Startup
Lost In Stupid Parentheses • Each opening parenthesis needs a closing parenthesis • A function name follows an open parenthesis • Data may follow the function name • Most functions return data (=sky "blue")
Sample Visual LISP Code (if (= sky "blue") (DoWearShorts) (DoGrabUmbrella) )
Editing Visual LISP Code • Can be done in Notepad • Use the VLIDE • Parenthesis matching • Color coding • Debugging tools • AU 2009 Classes on the VLIDE • CP218-2L • CP222-1L
Bootstrapping • Profiles are important for CAD Standards • Specifies file search path • Specifies plot support items • Profiles can be deployed • Starting AutoCAD by not using your shortcut • Profiles can be changed • Enforce standards every time a drawing is opened
Working with the Current Profile (wcmatch (strcase (getvar "Cprofile") ) (strcase "Sparling") ) (setq myProfile (vla-get-preferences (vlax-get-acad-object) ; <- needs (vl-load-com) ) )
Settings in the Options, File Dialog Box (setqmyFiles (vla-get-files myProfile) ) (setqappPath (strcat (vla-get-path (vlax-get-acad-object)) "\\" ) )
Forcing a Setting in the Options, File Dialog Box (vla-put-supportpath myFiles (strcat "P:\\Acad" ";" (strcat (getvar "RoamableRootPrefix") "Support") ";" (strcatappPath "Support") ) )
Initializing the Environment • Highlighting (setvar "Highlight" 1) • File Dialogs (setvar "FileDia" 1) • Automatic Field Evaluation (setvar "FieldEval" (+ 1 2 4 8 16))
Bitcodes • Some system variables use bitcode values • Bitcodes are like a bank of light switches • The first switch has a value of 1 • Each subsequent switch's value is double the previous • All "ON" values are added together • Each possible value is a unique combination of on/off positions
Setting a Maximum Limit on Save Times (setvar "SaveTime" (min (getvar "SaveTime") 15 ) )
Fixing a "Broken" Main Spelling Dictionary (if (= (getvar "DctMain") "" ) (setvar "DctMain" "enu") )
Checking the Version of AutoCAD (if (> (atof (getvar "AcadVer") ) 17.1 ) (setvar "LayerDlgMode" 0) )
Report to Mama (defunReportIssue (msg filename / file user ws) (if (setq file (open filename “a”)) (progn (write-line (strcat “User: “ (getvar “LoginName”) “, Workstation: “ (getenv “ComputerName”) “, “ msg) file) (close file))) (princ))
Using the Reporting Function (if (and (= (atof (getvar “AcadVer”)) 18.0) (= (substr (getvar “_VerNum”) 1 (vl-string-search “ (UNICODE)” (getvar “_VerNum”))) “D.215.0.0”)) (ReportIssue “Has SP1.” “C:\\Temp\\AutoCAD 2010 Service Pack Report.txt”))
Demand Loading • ;;;My Sample.lsp • (defun C:MySample () • ;; Lots of code here • (princ)) • ;;;AcadDoc.lsp • (defun C:MySample () • ;; Autoload the application • (load “My Sample.lsp”) • ;; Execute the newly loaded application’s function • (C:MySample))
Summary • Enforcing standards in the profile is important • Cannot be done effectively without "programming" • Visual LISP is an easy way enforce standards