Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Macro Writing Kate Morrical AutoCAD LT Technical Marketing Manager.

Similar presentations


Presentation on theme: "Introduction to Macro Writing Kate Morrical AutoCAD LT Technical Marketing Manager."— Presentation transcript:

1 Introduction to Macro Writing Kate Morrical AutoCAD LT Technical Marketing Manager

2 Customization Without Programming

3 Agenda  What’s in:  Writing Macros  Using DIESEL in Macros  Using Macros in CUI Elements  Using Macros in Tool Palettes  The Action Recorder  What’s out:  Linetypes  Hatch Patterns  Dynamic Blocks  Scripts  LISP/VB A/.NET/Everything Else

4 Text Conventions  AutoCAD-generated command line text  USER-GENERATED TEXT OR NUMBERS  Enter, left-click or other special characters

5 Writing Macros  Start with “want” statement  “I want to…”  First example:  “I want to draw a circle with a radius of 1 unit.”  Command line entry: Command: CIRCLE (enter) Specify center point for circle or [3P/2P/Ttr (tan tan radius)]: (left-click) Specify radius of circle or [Diameter]: 1 (enter)

6 Writing Macros, cont.  Put the pieces together:  circle ;; \\ 11 ;;  circle;\1;  Not quite done yet, though.

7 Writing Macros, cont.  What if a command were running when you started the macro?  You’d need to cancel it…  ^C^C  ^C^Ccircle;\1;  What if this was used in a non-English version of AutoCAD?  You’d need to translate the command  _circle  ^C^C_circle;\1;

8 Detour: CUI Topics & Tool Palettes  Skipping to Page 16 of the handout

9 Demo

10 Back on Track: Writing Macros  Special Characters  Semicolon (;)  Blank Space ( )  Backslash (\)  Underscore (_)  Dash/Hyphen (-)  Asterisk (*)  Caret (^)  Dollar Sign ($)  Example: Create Multiple Circles  *^C^C_circle;\1;

11 Demo

12 Rotate By Fixed Angle  Rotate an object by 180 degrees every time Command: ROTATE (enter) Current positive angle in UCS: ANGDIR=counterclockwise ANGBASE=0 Select objects: (left-click) 1 found Select objects: (enter) Specify base point: (left-click) Specify rotation angle or [Copy/Reference] : 180(enter)

13 Rotate By Fixed Angle  Clear any running commands  ^C^C  Start the rotate command  _rotate ;  Let the user pick the object to rotate \\  End the “select object” mode ;;  Let the user pick the base point \\  Specify the rotation angle and end the command  180;  Put it all together: ^C^C_rotate;\;180;

14 Demo

15 Copy and Rotate  Copy an object and then rotate it  Clear any running commands  ^C^C  Start the copy command  _copy ;  Let the user pick the object to copy \\  End the “select object” mode ;;  Let the user pick the base point and the second point  \\

16 Copy and Rotate, cont.  Start the rotate command  _rotate ;  Select the last object created  L;  End the “select object” mode ;;  Use the coordinates of the last point specified  Let the user specify the rotation angle \\  Put it all together: 

17 Demo

18 Macros for Dialog-Based Commands  Need to use command-line version  Type out the command, pay attention to every time you pick an option or press Enter.  Hatches  -hatch  Blocks  -insert  Layers  -layer

19 Create a Hatch  Create a hatch with:  A pattern of ANSI37  A scale of 4  And a rotation of 45 degrees  Using the “select objects” method

20 Create a Hatch, cont. Command: -HATCH (enter) Current hatch pattern: ANSI31 Specify internal point or [Properties/Select objects/draW boundary/remove Boundaries/Advanced/DRaw order/Origin/ANnotative]: P (enter) Enter a pattern name or [?/Solid/User defined] : ANSI37 (enter) Specify a scale for the pattern : 4 (enter) Specify an angle for the pattern : 45 (enter)

21 Create a Hatch, cont. Current hatch pattern: ANSI37 Specify internal point or [Properties/Select objects/draW boundary/remove Boundaries/Advanced/DRaw order/Origin/ANnotative]: S(enter) Select objects:(left-click) 1 found Select objects: (enter) Current hatch pattern: ANSI37 Specify internal point or [Properties/Select objects/draW boundary/remove Boundaries/Advanced/DRaw order/Origin/ANnotative]: (enter)

22 Create a Hatch, cont.  Replace all (left-click) with backslash and all (enter) with semi-colons:  ^C^C-hatch;p;ANSI37;4;45;s;\;;

23 Demo

24 Insert a Block  Insert a specified block with:  A scale of 12  And a rotation of 90 degrees

25 Insert a Block, cont. Command: -INSERT (enter) Enter block name or [?]: SAMPLE (enter) Units: Inches Conversion: Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: S (enter) Specify scale factor for XYZ axes : 12 (enter) Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: R (enter) Specify rotation angle : 90 (enter) Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: (left-click)

26 Insert a Block, cont.  Replace all (left-click) with backslash and all (enter) with semi-colons:  ^C^C-insert;sample;s;12;r;90;\  Insert the same block exploded:  ^C^C-insert;*sample;\12;90;  Insert the block and explode it after placement:  ^C^C-insert;sample;s;12;r;90;\explode;L;  Insert the block, explode it after placement, then purge:  ^C^C-insert;sample;s;12;r;90;\explode;L; -purge; B;sample;N;

27 Demo

28 Create a Layer Command: -LAYER (enter) Current layer: "0" Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATeria l/Plot/Freeze/Thaw/LOck /Unlock/stAte/Description/rEconcile]: M (enter) Enter name for new layer (becomes the current layer) : S-ANNO-TEXT (enter) Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATeria l/Plot/Freeze/Thaw/LOck /Unlock/stAte/Description/rEconcile]: C (enter) New color [Truecolor/COlorbook] : 1 (enter) Enter name list of layer(s) for color 1 (red) : (enter)

29 Create a Layer, cont. Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATeria l/Plot/Freeze/Thaw/LOck /Unlock/stAte/Description/rEconcile]: L (enter) Enter loaded linetype name or [?] : continuous (enter) Enter name list of layer(s) for linetype "continuous" : (enter) Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATeria l/Plot/Freeze/Thaw/LOck /Unlock/stAte/Description/rEconcile]: (enter)

30 Create a Layer, cont.  Replace all (enters) from previous slides with semi-colons:  ^C^C-layer;M;S-ANNO-TEXT;C;1;;L;Continuous;;;  What if your linetype isn’t loaded?  Load it first!  ^C^C-insert;*LT_beam_removed;0,0;1;;-layer ;M;S-BEAM-STEL-DEMO;C;1;;L;BEAM_REMOVED;;;

31 Demo

32 Plot a Drawing Command: -PLOT (enter) Detailed plot configuration? [Yes/No] : N(enter) Enter a layout name or [?] : Layout1 (enter) Enter a page setup name <>: Setup1 (enter) Enter an output device name or [?] : (enter) Write the plot to a file [Yes/No] : (enter) Save changes to page setup [Yes/No]? : (enter) Proceed with plot [Yes/No] : (enter)

33 Plot a Drawing, cont.  Replace all (enters) from previous slide with semi-colons:  ^C^C-plot;N;Layout1;Setup1;;;;;

34 Demo

35 Repeating Macros  Can’t use Enter or Spacebar to repeat macros  Can use right-click shortcut menu  Unless the macro was launched from the Ribbon (known issue)

36 Bringing Macros Through Upgrades  Only thing to watch out for is changes in command options or names  For example  Introduction of PEDITACCEPT meant you could skip a step in the PEDIT command—broke a few macros that way

37 DIESEL  Direct Interpretively Evaluated String Expression Language  Always preceded with a dollar sign  $M=$(diesel expression here)  Operators go first  $M=$(+,2,3)  $M=$(/,12,4)

38 Using Variables in DIESEL  Start by using GETVAR to retrieve variable value:  $(getvar,DIMSCALE)  Then do some math with it:  $M=$(*,$(getvar,DIMSCALE),0.25)  Finally put it into a command:  ^C^C^Rfillet;r; ;  ^C^C^Rfillet;r;$M=$(*,$(getvar,DIMSCALE),0.25);

39 Demo

40 More DIESEL Macros  Two more macros that use DIMSCALE:  Start with:  $M=$(*,$(getvar,DIMSCALE),0.125)  Set single-line text height based on DIMSCALE:  ^C^C_dtext; ;  ^C^C_dtext;\$M=$(*,$(getvar,DIMSCALE),0.125);  Set multi-line text height based on DIMSCALE:  ^C^C_mtext;\h; ;\  ^C^C_mtext;\h;$M=$(*,$(getvar,DIMSCALE),0.125);\

41 Demo

42 Conditional Expressions  DIESEL IF function similar to Excel IF function  $M=$(if,expression,true,false)  Expression: statement to evaluate  True: command sequence if expression is true  False: command sequence if expression is false  Good for toggling values

43 Conditional Expressions, cont.  Build macro for toggling cursor size from 5% of screen to 100% of screen  Verbalize IF function:  “If the CURSORSIZE variable is already set to 100, change it to 5. If it’s not 100, change it to 100.  Verbalize the expression:  “Is the cursor size already 100%?”  Write the expression:  $(=,$(getvar,CURSORSIZE),100)

44 Conditional Exprsesions, cont.  Verbalize the TRUE condition:  “If the expression is true, set the cursor size to 5%.”  Write the TRUE condition:  CURSORSIZE;5  Verbalize the FALSE condition:  “If the expression is false, set the cursor size to 100%.”  Write the FALSE condition:  CURSORSIZE;100  Put it all together:  $M=$(if,expression,true,false)  $M=$(if,$(=,$(getvar,CURSORSIZE),100), CURSORSIZE;5,CURSORSIZE;100)

45 Demo

46 User Variables  10 built-in variables  Can’t rename, can’t use more  Five for integers  USERI1 through USERI5  Five for real numbers (with decimal points)  USERR1 through USERR5

47 User Variables, cont.  Use a variable to automatically increment the value of a block attribute  Start the Insert command and place the block:  Block definition must already exist in the drawing or in one of the support paths!  ^C^C-insert;label;\;;  Retrieve current value of USERI1:  $M=$(getvar,USERI1)  Use USERI1 as attribute value:  Block definition should contain only one attribute!  USERI1;

48 User Variables, cont.  Increase the value of USERI1 by 1:  $M=$(+,$(getvar,USERI1),1);  Put it all together:  *^C^C-insert;label;\;;$M=$(getvar,USERI1); USERI1;$M=$(+,$(getvar,USERI1),1);  Asterisk repeats the command multiple times  You do have to remember to reset the value of USERI1 every time you run the macro

49 The Action Recorder

50  Guidelines for Creating Action Macros  Don’t use dialog-based commands  OR  Use the command-line equivalent for dialog boxes  Don’t accept the default entry for commands  Place macros in read-only folders for sharing

51 Demo

52 Any Questions?  How to reach me:   LT Unlimited:  More resources   (forums & ATP classes)  Please remember to take the class survey sometime today (they’re really important!)  Thanks for coming, and enjoy the rest of AU!

53


Download ppt "Introduction to Macro Writing Kate Morrical AutoCAD LT Technical Marketing Manager."

Similar presentations


Ads by Google