Download presentation
Presentation is loading. Please wait.
Published byBrendan Allison Modified over 9 years ago
1
1 AutoCAD: Secrets Every User Should Know Chapter 7 - AutoCAD Scripts
2
2 Scripts
3
3© 2006 Autodesk Introduction ASCII Text File Commands You Can Type at Command Line Not Aliases Commands and Options Lisp Code AutoLISP Functions and Commands Other Scripts Open Dialog Boxes: SAVE~ Limitations: No User Input
4
4© 2006 Autodesk Writing Scripts Special Script Functions: Backspace keyPauses a script RESUMEResumes a paused script ;Remark within a script DELAYDelays the next step a specified time RSCRIPTRepeats the script when done Space in lineEnter key New lineEnter key
5
5© 2006 Autodesk Writing Scripts File Format All On One Line Separate Line for Each Command String Save with SCR Extension Same as Windows screen saver Prior to AutoCAD 2006 change association
6
6© 2006 Autodesk Uses for Scripts Create Entities Test Computer Speed Set Up Layers, Text Styles, Dimension Styles, etc. Change Variable Settings Saved in drawing Saved in Registry Extract Block Attributes Make Slides and Run Slide Show Edit Unlimited Number of Drawings
7
7© 2006 Autodesk Simple Script Layer New fl1,fl1-dim,fl1-txt Color 2 fl1 Color 3 fl1-dim Color 4 fl1-txt
8
8© 2006 Autodesk Simple Script - Alternate Format Layer New fl1,fl1-dim,fl1-txt C 2 fl1 C 3 fl1-dim C 4 fl1-txt...or all on one line
9
9© 2006 Autodesk Setup Script LAYER New obj,hid,cen,txt,dim Color 1 hid Color 3 cen Color 4 txt Color 5 dim L hidden hid L center cen S obj STYLE romans romans 0 1 0 N N N APERTURE 5 ATTDIA 1 AUNITS 0 AUPREC 1 BLIPMODE 0 CECOLOR bylayer CELTSCALE 1 CELTYPE bylayer CMDDIA 1 CMDECHO 1 CURSORSIZE 5 DRAGMODE A ELEVATION 0 EXPERT 0 FACETRES 1 FILEDIA 1 FILLETRAD 0 GRIPCOLOR 5 GRIPHOT 1 GRIPS 1 GRIPSIZE 3 HIGHLIGHT 1 LTSCALE 1 MBUTTONPAN 1 MIRRTEXT 0 OSMODE 4133 PELLIPSE 0 PICKADD 1 PICKAUTO 1 PICKBOX 3 PICKFIRST 1 PICKSTYLE 1 PLINEGEN 1 PSLTSCALE 1 SAVETIME 15 SDI 0 SORTENTS 23 THICKNESS 0 UCSICON off UCS w UCSVP 1
10
10© 2006 Autodesk Bench-Testing Computers TIME R BOX 0,0 10,10,10 SPHERE 5,5,5 5 SUBTRACT NON 0,0 L VPOINT 1,-1,1 SLICE L 5,0 5,5 5,5,5 -1,0 3DARRAY L R 4 4 4 10 10 10 ZOOM ALL HIDE VPORTS 4 CVPORT 5 UCS X 90 PLAN C CVPORT 4 UCS W PLAN C CVPORT 2 UCS X 90 UCS Y 90 PLAN C TILEMODE 0 ERASE ALL MVIEW R F MSPACE CVPORT 3 SOLPROF ALL Y Y Y CVPORT 4 SOLPROF ALL Y Y Y CVPORT 5 SOLPROF ALL Y Y Y CVPORT 6 SOLPROF ALL Y Y Y TIME
11
11 Automatically Updating Drawing Script Files Batch Files Lisp Files Batch-Editing Drawings
12
12© 2006 Autodesk Introduction Automatically Updating Multiple Drawings Possibilities: Reducing file size of all drawings in a directory Replacing existing title blocks with a new one Creating drawing files from existing block definitions Adding attributes to existing block definitions Redefining existing block definitions Extracting attribute information into a text file Repathing all XRefs and images to relative Almost anything else…if you know a little AutoLISP
13
13© 2006 Autodesk Tools needed for this system A Script File Can be run on startup of AutoCAD Can makes changes directly or load Lisp program Can exit AutoCAD to restart cycle A Batch File – DOS Isn’t Dead Yet for Me Can create a new folder for replacement drawings Can use the FOR function to process multiple files Can use the /r switch to include subdirectories A Lisp program Can do nearly anything
14
14© 2006 Autodesk Two Cautions! Try Out Programming in Small Pieces on a Test File Does the script do what you want it to? Does the Lisp do what you want it to? Does the batch file work with a small group of files? Protect Your Files! Back up your original files Make NEW files with this process Don’t delete the originals until you’re done Place new drawings in their own directory
15
15© 2006 Autodesk Background - Scripts Create with Notepad or WordPad Save with an.SCR Extension, NOT.txt You may have to quote filename “myscript.scr” A Script Can Run on Startup Using the Switch /b Scripts Contain Command-Line Input Try out commands at the command line Use a dash with commands, like -LAYER, -INSERT Turn FILEDIA off to try options of SAVEAS AutoCAD Can Open a Drawing on Startup …AutoCAD 2007\acad.exe "path\drawing name"
16
16© 2006 Autodesk Background – Batch Files Create with Notepad or WordPad Save with a.BAT extension, NOT.txt OPEN Batch File to Run It Two DOS Commands Are Key: "FOR" function and "%f" parameter allow processing of multiple files (DWG in this example) "START /WAIT" starts a windows application and returns to the batch file when application closes
17
17© 2006 Autodesk Background – AutoLISP Files Create With VLISP, Notepad, or WordPad Save with an.LSP Extension, NOT.txt Lisp Code Can Be Included Directly in Scripts Use parentheses Type as you would at the command line Learn as Much AutoLISP as You Can Good operator’s programming language It is NOT going away – too much existing code It’s fun – really (Friday Morning: Not so Rapid…)
18
18© 2006 Autodesk AutoLISP Files Important Note! These AutoLISP Files Have Been Simplified for This Presentation. They Do Not: Include Annotation Include Error Handling Define Program Variables as Local Account for Anonymous Blocks
19
19 Example One Reducing Archive File Sizes
20
20© 2006 Autodesk Reducing Archive File Sizes Step 1 – script file Open Notepad (right-click New Text Document) Type the following: (load "c:\\Sybex\\wbout.lsp") ZOOM All WBOUT QUIT Y Save the file as "C:\Sybex\wbout.scr"
21
21© 2006 Autodesk Reducing Archive File Sizes Step 2 – batch file Open Notepad (NOT a word processor) Type the following in TWO lines: md C:\Sybex\dwg\wb FOR %f in (C:\Sybex\dwg\*.dwg) do start /wait C:\"program files"\"AutoCAD 2007"\ acad.exe "%f" /b C:\Sybex\wbout.scr Save the file as "C:\Sybex\wbout.bat"
22
22© 2006 Autodesk Reducing Archive File Sizes Step 3 – Lisp file Open Notepad or VLISP (NOT a word processor) Type the following: (defun c:wbout() (setq dn (getvar "dwgname")) (setq pa (getvar "dwgprefix")) (setq pawbdn (strcat pa "wb\\" dn)) (command "wblock" pawbdn "*") ) Save the file as "C:\Sybex\wbout.lsp"
23
23© 2006 Autodesk Reducing Archive File Sizes page 5 Step 4 -- RUN the batch file Go to My Computer or Explorer Open folder C:\Sybex Double-click wbout.bat
24
24© 2006 Autodesk Caution with Batch Files! Double-clicking a Batch File… RUNS the file, doesn’t open it for editing! To change the text in the file Select Edit after right-clicking
25
25© 2006 Autodesk Processing Files in Subdirectories The FOR Function in DOS Can Be Modified to Include Subdirectories The Text Changes as Follows: FOR /R C:\Sybex\dwg\%f in (*.dwg) do…
26
26 Example Two Updating a Title Block
27
27© 2006 Autodesk Updating a Title Block Step 1 – script file: INSERT border=C:\Sybex\dwg\new-border 0,0 1 1 0 ERASE L (load "c:\\Sybex\\TbUpdate.lsp") TbUpdate QUIT Y Save the file as "C:\Sybex\ TbUpdate.scr"
28
28© 2006 Autodesk Updating a Title Block Step 2 – batch file in TWO lines: md C:\Sybex\dwg\NewBorder FOR %f in (C:\Sybex\dwg\D5*.dwg) do START /WAIT C:\"program files"\"AutoCAD 2007"\acad.exe "%f" /b C:\Sybex\TbUpdate.scr Save the file as "C:\Sybex\TbUpdate.bat"
29
29© 2006 Autodesk Updating a Title Block Step 3 – Lisp file: (defun c:TbUpdate() (setq dn (getvar "dwgname")) (setq pa (getvar "dwgprefix")) (setq panbdn (strcat pa "NewBorder\\" dn)) (command "SAVE" panbdn ) ) Save the file as "C:\Sybex\ TbUpdate.lsp "
30
30© 2006 Autodesk Updating a Title Block Step 4 – Run the program Go to My Computer Open folder C:\Sybex Double-click TbUpdate.bat
31
31 Example Three Creating Drawings from Block Definitions
32
32© 2006 Autodesk Creating Drawings from Blocks Step 1 – script file: (load "c:\\Sybex\\blockout.lsp") blockout QUIT Y Save the file as "C:\Sybex\ blockout.scr"
33
33© 2006 Autodesk Creating Drawings from Blocks Step 2 – batch file in TWO Lines: md C:\Sybex\dwg\NewBlocks for %f in (C:\Sybex\dwg\sym*.dwg) do START /WAIT c:\"program files"\"AutoCAD 2007"\acad.exe "%f" /b C:\Sybex\blockout.scr Save the file as "C:\Sybex\blockout.bat"
34
34© 2006 Autodesk Creating Drawings from Blocks Step 3 – Lisp file: (defun c:blockout () (setq dn (getvar "dwgname")) (setq pa (getvar "dwgprefix")) (setq s1 (strcat pa "NewBlocks\\" dn)) (setq blkdata (tblnext "BLOCK" T)) (while blkdata (setq blname (cdr (assoc 2 blkdata))) (setq fullname (strcat s1 blname)) (command "WBLOCK" fullname blname) (setq blkdata (tblnext "BLOCK")) ) Save the file as "C:\Sybex\ blockout.lsp"
35
35© 2006 Autodesk Dim/Hatch Blocks Break Program! An * Precedes Anonymous Block Names – Can’t Use * in Filenames Dynamic Blocks Saved to Pre-2006 Format Also Have This Problem
36
36© 2006 Autodesk Creating Drawings from Blocks Step 4 – Run the program Go to My Computer Open folder C:\Sybex Double-click blockout.bat
37
37© 2006 Autodesk Future Considerations These Programs Were Simplified as Much as Possible Add Documentation to Each File ; before documentation lines in script files REM before documentation lines in batch files ; before documentation lines in Lisp files Use VLISP for Creating Lisp Programs Add Error-Trapping to All Lisp Programs
38
38© 2006 Autodesk Error-Trapping Example (defun da_error (msg) (command) (setvar "aperture" ap) (setvar "osmode" os) (setq *error* old_error) (alert "Returning drawing to original status.") ) (defun C:MID (/ p1 p2 old_error) (setq old_error *error*) (setq *error* da_error) …etc.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.