Macros – More Advanced

In my next post on customisation I will be looking at more advanced macro writing. After this post there will be a few individual macro examples which should be helpful!

Please refer to my macro basics and other customisation tutorials first.

In this tutorial I am going to refer to two UCS commands I have written to get around the lack of easy plan rotation in AutoCAD LT. In full AutoCAD you get a rotation box in the upper right corner that looks like the one below. This is unfortunately not available in LT.

Rotate from Viewcube
Rotate from Viewcube

These are a bit more automated version of the tutorial I have posted before as I decided that even that was too much effort!

—–

The first macro rotates the UCS back to world and takes the plan view with it. This avoids the need for UCS follow being set to 1 and the annoying zoom extents bug it has.

^C^Cucs;w;plan;w;

So lets break down the macro above. Its just a simple chain of commands to do with the UCS and PLAN.

  • The first ^C^C at the beginning is escape twice to ensure that the command line is clear
  • Then the UCS command is started
  • Then the UCS command is told to reset to (W)orld
  • Then the PLAN command is started
  • Then the PLAN command is told to reset to (W)orld

Now the drawing is viewed in world view and the UCS is orientated the same way.

——

The second macro rotates the UCS to an object and then updates the view to suit.

^C^Cucs;ob \plan;c;

So lets break this one down as it has something slightly different in its layout.

  • The first ^C^C at the beginning is escape twice to ensure that the command line is clear
  • Then the UCS command is started
  • Then the UCS command is told to select by object
  • Then the script waits for input by the use of a space then a backslash
  • Then the PLAN command is started (after input)
  • Then the PLAN command is told to update to the (C)urrent

——

This formula can be used to make further buttons to emulate the plan rotate found in full AutoCAD or make any chain of commands work.

A quick way to create a macro is to run a command and follow the command line and write down your inputs and once you have completed the command you have the basics for putting together a macro.

—–

Lets make a macro to rotate the UCS and PLAN to the right. Here is a copy of the command line and below that is a list of the command inputs and then the resultant macro.

Command line:

Command: UCS
Current ucs name:  *NO NAME*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: z
Specify rotation angle about Z axis <90.00>: 90
Command: PLAN
Enter an option [Current ucs/Ucs/World] <Current>: c
Regenerating model.

Command input only:

ucs
z
90
plan
c

Macro:

^C^Cucs;z;90;plan;c;

Macros – Basics

In order to create custom commands and then assign them to a button in AutoCAD you will need to create a MACRO. This is so for all buttons, even those that call a LISP or OBJECTARX piece of code.

The MACRO is basically a list of the inputs on the command line listed out in one line.

A simple MACRO would look like this:

^C^Cplot;

This if turned placed in a button would bring up the plot dialog box.

The ^C^C is the code for pressing “escape” twice. This clears any active commands in case one is running.

The ; is the representation of enter. Any number of commands can be strung together into one MACRO.

MACROs also allow for input for selecting objects and this is written with a space and then a backslash.

I will be running through several of my custom commands to show how they are put together.