Top Banner
Introduction to Macro Writing Kate Morrical AutoCAD LT Technical Marketing Manager
53

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

Dec 15, 2015

Download

Documents

Tamia Scammell
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Macro Writing Kate Morrical AutoCAD LT Technical Marketing Manager.

Introduction to Macro Writing

Kate MorricalAutoCAD LT Technical Marketing Manager

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

Customization Without Programming

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

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/VBA/.NET/Everything Else

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

Text Conventions

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

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

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)

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

Writing Macros, cont.

Put the pieces together: circle ; \ 1 ;

circle;\1;

Not quite done yet, though.

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

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;

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

Detour: CUI Topics & Tool Palettes

Skipping to Page 16 of the handout

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

Demo

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

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;

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

Demo

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

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 foundSelect objects: (enter)Specify base point: (left-click)Specify rotation angle or [Copy/Reference] <0>: 180(enter)

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

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;

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

Demo

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

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 \\

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

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: ^C^C_copy;\;\\_rotate;L;;@;\

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

Demo

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

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

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

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

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

Create a Hatch, cont.

Command: -HATCH (enter)Current hatch pattern: ANSI31Specify 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] <ANSI31>: ANSI37 (enter)

Specify a scale for the pattern <1.0000>: 4 (enter)Specify an angle for the pattern <0>: 45 (enter)

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

Create a Hatch, cont.

Current hatch pattern: ANSI37Specify internal point or [Properties/Select objects/draW boundary/remove Boundaries/Advanced/DRaw order/Origin/ANnotative]: S(enter)

Select objects:(left-click) 1 foundSelect objects: (enter)Current hatch pattern: ANSI37Specify internal point or [Properties/Select objects/draW boundary/remove Boundaries/Advanced/DRaw order/Origin/ANnotative]: (enter)

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

Create a Hatch, cont.

Replace all (left-click) with backslash and all (enter) with semi-colons:

^C^C-hatch;p;ANSI37;4;45;s;\;;

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

Demo

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

Insert a Block

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

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

Insert a Block, cont.

Command: -INSERT (enter)Enter block name or [?]: SAMPLE (enter)Units: Inches Conversion: 1.0000Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: S (enter)

Specify scale factor for XYZ axes <1>: 12 (enter)Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: R (enter)

Specify rotation angle <0.0000>: 90 (enter)Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: (left-click)

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

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;

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

Demo

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

Create a Layer

Command: -LAYER (enter) Current layer: "0"Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck

/Unlock/stAte/Description/rEconcile]: M (enter) Enter name for new layer (becomes the current layer) <0>: S-ANNO-TEXT (enter)

Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/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) <S-ANNO-TEXT>: (enter)

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

Create a Layer, cont.

Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck

/Unlock/stAte/Description/rEconcile]: L (enter) Enter loaded linetype name or [?] <Continuous>: continuous (enter)

 Enter name list of layer(s) for linetype "continuous" <S-ANNO-TEXT>: (enter)

Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck

/Unlock/stAte/Description/rEconcile]: (enter)

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

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;;;

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

Demo

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

Plot a Drawing

Command: -PLOT (enter)Detailed plot configuration? [Yes/No] <No>: N(enter)

Enter a layout name or [?] <Layout1>: Layout1 (enter)

Enter a page setup name <>: Setup1 (enter)Enter an output device name or [?] <HP Officejet 4300 series>: (enter)

Write the plot to a file [Yes/No] <N>: (enter)Save changes to page setup [Yes/No]? <N>: (enter)

Proceed with plot [Yes/No] <Y>: (enter)

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

Plot a Drawing, cont.

Replace all (enters) from previous slide with semi-colons:

^C^C-plot;N;Layout1;Setup1;;;;;

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

Demo

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

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)

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

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

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

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)

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

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;<need number here>; ^C^C^Rfillet;r;$M=$(*,$(getvar,DIMSCALE),0.25);

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

Demo

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

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;<need number here>; ^C^C_dtext;\$M=$(*,$(getvar,DIMSCALE),0.125);

Set multi-line text height based on DIMSCALE: ^C^C_mtext;\h;<need number here>;\ ^C^C_mtext;\h;$M=$(*,$(getvar,DIMSCALE),0.125);\

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

Demo

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

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

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

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)

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

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)

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

Demo

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

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

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

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;

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

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

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

The Action Recorder

1

2 3 4 5

6

7

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

The Action Recorder

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

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

Demo

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

Any Questions?

How to reach me: [email protected] LT Unlimited: http://ltunlimited.typepad.com

More resources www.autodesk.com/discussion www.augi.com (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!

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