Templates for Reusability (Templates and Reusability) (AutoCAD VBA)

Templates don’t tend to get misplaced in the way macros sometimes do.If you are an intermediate user of VBA, you probably already know how to create your own templates—but did you know that macros, too, can be included in those templates? This topic offers a few useful ones.

AutoCAD has lots of different techniques for duplicating and reusing drawing items, helping you reduce the repetition associated with setting up drawing options and duplicating drawing objects. You’ll learn how to create a template to set up the drawing environment for a floor plan, and a macro that does the same thing. You’ll also see how to duplicate existing objects and set up a new user coordinate system.

Templates are blueprints for reproducing drawings with identical drawing objects and environment settings. You already use a template, perhaps without realizing it, every time you open AutoCAD and a Model Space and display at least two Layout pages containing a blank drawing. Templates allow you to create new drawings automatically, just like photocopying a layout that you want to reproduce with some identical features. After you’ve opened a drawing based on the template, you need only concentrate on entering the parts that differ from drawing to drawing.

A template is a special type of file that contains all the settings needed to re-create a drawing, including environmental settings, as well as the drawing objects you’ll want to include in all the drawings you create based on that template. For example, a template can contain settings such as measurement units, objects such as lines and circles, specific user coordinate systems (UCSs), grid points, and viewports.


If you repeatedly make new drawings and set them up with the same UCS and the same drawing environment settings, or you often need to duplicate parts of drawings, then you should consider creating templates containing only these settings and parts. The next time you need to create one of these drawings, you can do so simply and efficiently based on the template. All the settings and parts saved in the template will be included automatically. Then you just need to draw the additional parts and make any other adjustments required.

In this topic, we’ll customize the drawing environment to make it suitable for drawing a simple floor plan of a small apartment in a building with several stories. The whole drawing can be saved as a template usable for reproducing the floor plans for other apartments, with adjustments made to meet buyers’ specifications. As we adjust each setting, I’ll show you how to do the same thing from a macro. The various stages involved in creation of this template are as follows:

1.    Changing the drawing units to feet and inches

2.    Switching grid points inside a specified area

3.    Setting the spacing for grid points and viewing the whole grid

4.    Setting the snap spacing and snapping clicked points to grid points, to make drawings more accurate and to ensure that all lines connect

5.    Drawing the floor plan

When the floor plan is complete, a main macro will be created to call the macros involved in each of these stages. Then you’ll learn how to create a template that will reproduce the same floor plan at the touch of a button. The next time you need to create a floor plan, you’ll be able to choose between running the macro to make the plan, or basing your drawing on the settings from the template.

Next post:

Previous post: