VBA Macros for TurboCAD Pro
Plug-in tools for TurboCAD
Regen Objects for TurboCAD
External applications that work with TurboCAD
VBA Macros for TurboCAD Pro:
= macro works in TurboCAD Pro v7
= macro works in TurboCAD Pro v8
(Back to top)
henon2_tcm.zip(8B) Added 03/08/03
This macro draws an object called a Henon Strange Attractor. The equations used
have their origins in studies of self-organizing systems and chaos theory.
For more information on this subject I suggest you perform web searches on these
The equations used in this macro are credited to Edward Rietman.
Despite all this fancy science, the macro is very simple, as you can see. When
started, an input box will ask you to supply the value of "A" to be used in
plotting the attractor system. The rest of the values used are set in the code.
The macro then places dots in the drawing in 2D coordinates to map the system.
Basically, the system will appear "stable" for many values of "A", but will break
up at certain values. Around the values that cause instability, very small
changes in "A" will cause marked changes in the attractor. Try these
values of A: 1.1; 1.2; 1.264; 1.265; 1.275, 1.3, 1.35; 1.5; 1.57; 1.575; 1.58;
1.591; 1.6; 1.601; 1.602; 1.7
To completely clear an attractor in the drawing before drawing a new one, I
suggest you use the menu commands Edit|Select|All
pickover_tcm.zip(16KB) Added 03/08/03
This macro will plot dots in the active drawing according to an equation for an
object called a "Strange Attractor". See
http://www.wfu.edu/~petrejh4/Attractor.htm for a discussion of this
The equations used in this example were developed by Clifford Pickover, and were
adapted from code in the book "Visual Basic Graphics Programming" by Rod
When you start the macro, it will begin placing dots in the drawing based on the
values set in the configuration boxes. The attractor is drawn in 3D and you may
rotate and examine it as it is growing. Press the "Stop" button when you've seen
To start a new attractor, it's best to clear the previous one first. The fastest
way to do this is to use the menu commands "Edit|Clear|All"
xrefinfo_tcm.zip(12KB) Added 03/08/03
This macro uses a tree view to display all the blocks and xrefs for all open
drawings. Each root of the tree is the file path for each open drawing. Then
next nodes break into groups of blocks and xrefs for each drawing. For the
blocks, the names of the blocks are simply listed. For the xrefs, the path to
each xrefs drawing file is listed. The macro checks to see if it can find the
file, and if so, a green check is placed in front of the file path; if not, a
red X. Also, double-clicking on the file path for a valid XREF will cause that
drawing to be opened. The tree view control used in this macro is not included in
the VBA that ships with TurboCAD. It is in the ActiveX library MScomctl.ocx.
This is a fairly commonly used VB runtime, and is probably on most PC's. If not,
you can find it for download from many sites (Here
is just one.)
Run this in an empty drawing. It just draws lines using each line style active
in the application, and prints the name of the style to the right of each line.
Run this in an empty drawing. It draws an array of rectangles, one for each
named color in the application, and prints the name of the color next to each
Run this in an empty drawing. It draws a "color wheel" using all the named
colors in the drawing. The name of each color is printed radially around the
outside of the wheel.
picktest_tcm.zip(9KB) Added 03/08/03
One of those older macros I found on my system. Just a quick demonstration of
determining the coordinates of a mouse click in the drawing window. The macro
reports both view and world coordinates. Also contains a procedure showing the
conversion of drawing coordinates to view and screen coordinates.
Export-2-Csv.zip(15KB) Added 09/10/02
This macro is intended to be used in drawings containing only straight line and
polyline objects (no arc segments). Other objects in the drawing will be
ignored. The coordinates of each line vertex are output to a file in CSV format
(comma delimitated), which can then be read into other applications such as
Excel. Each record is the file is prefaced with an index value to identify to
which line each vertex belongs. A transformation using the UCS of each object is
performed to convert the coordinate values to World UCS.
FullScreenView.zip(14KB) Added 08/23/02
Inspired by a question in the TurboCAD user forum. This macro will capture an
image of the active view in a drawing and display the picture in a full screen
size form. Windows API functions are used to remove the title bar and borders
from the displayed form.
InsertVertex.zip(18KB) Added 08/23/02
Another one inspired by a question in the TurboCAD user forum. TurboCAD does not
provide you with the means to insert a new vertex (node) into an existing 3D
polyline. This macro will help you to do it. After selecting a line (it works
for 2D polylines (with no arc segments) as well as 3D polylines) and running the
macro, a form is displayed with a list box containing items representing each
pair of vertices in the line. You select one pair of vertices, click the
"Insert" button, and a new vertex is inserted midway between the selected
ProjectionExample.zip(5KB) Added 08/03/02
An example of using simple matrix transformations to create 2D orthographic
projections of graphics in 3D space. This method seems to work on most of the
standard graphic objects I tried, but will not work on solid and surface
graphics. This is a screen
capture of the results.
FsoExample.zip(6KB) Added 08/03/02
Demonstrates using the File System Object from the Microsoft Scripting Runtime
to discover a few things about a file saved on disk.
PolyLineArea02.zip(10KB) Added 08/03/02
Demonstrates a method for calculating the area of simple, closed polyline
graphic in a VBA procedure. The macro places the calculated area value into the
graphic's Attribute field (which can be viewed from the property pages for the
graphic). This same information can be viewed in the "Selection Info" palette,
but I don't know of a way to read the palette's information from a macro.
PrismsAndLoftsEx.zip(6KB) Added 08/03/02
Just a simple example of using the Loft to create a few objects in a drawing.
This macro creates the profiles, and then adds them to a Loft graphic.
SaveCopyAsBmpExample.zip (9KB) Added 07/23/02
This demonstrates the use of the SaveCopyAs method to capture the active drawing
view as a bitmap. It is very easy to call the method in a macro. In order to
insure that you get the view you want, you can set the export settings in
the TCW80.INI file. This macro shows how to change these setting in code before
running the SaveCopyAs method. Note this macro will also work in TC v7 Pro if
you edit the code by replacing "TCW80.ini" with "TCW70.ini".
timertest.zip(13KB) Added 07/23/02
VBA does not offer a timer control. There are third party Activex controls you
can use if you need a timer in a macro. There is also a system timer that can be
used by with the SetTimer and KillTimer API calls. This macro draws some objects
to represent a clock face, and then uses the timer function to move the hands
around the clock. See the comments in the code for more information.
ResizableForm.zip (44KB) Added 07/15/02
This macro demonstrates how you can change the properties of VBA forms. The
macro uses a class module from an Excel macro written by
Stephen Bullen. In this sample, there is a
check box on the form that can be used to enable or disable the resizable
property of the the form.
UcsTranformEx.zip(6KB) Added 07/09/02
Another matrix example macro. This one draws a graphic (circle) in the active
drawing on the World workplane, then shows how to use a transformation matrix to
move it to the current drawing UCS.
ImportCsv.zip (13KB) Added 06/05/02
This is an example of reading coordinate data from a file in CSV (Comma Separated Value) format. Please see
the article Importing coordinate data into TurboCAD
for more information on this code.
NodeCleaner.zip (30KB) Added 02/27/02
This macro can be used to reduce the node count of certain polylines. When 2D polylines are used
to represent contours and curved profiles they can sometimes contain thousands of vertices, depending
upon how they were generated. High node counts increase file size and can drag system performance down,
especially during editing operations. Many times the number of nodes can be cut in half, or more, with out
changing the overall shape of the profile noticeably.
Here is one example.
This macro will only work with 2D polylines made of line segments (no arc
segments). It will remove up to 50% of the
nodes at a time, but this is configurable. There are also settings for making a copy of the original (for a back-up in case
you don't like the results; the node removal action is not undoable). And the settings are saved in an INI configuration
file in the Program folder.
ScaleMutipleWithMatrix.zip (9KB) Added 01/12/02
Macro to demonstate ways that transformation matrices can be used. This macro contains two
procedures to scale a group of selected objects. While the scale method would probably be
the easiest method to use for this operation in most case, the purpose of the macro is to show
how matrices can work. One of the procedures performs the scaling in three separate, simple matrix
transform operations, to show the use of translation and scaling separately. The other procedure
combines translation and scaling in one matrix. This macro also uses the Graphic.ReferencePoint property,
which is new in the v8 SDK. The macro will not run in v7, but it can still be loaded in v7 and viewed
to see the code for the matrix transformations.
MatrixExample.zip (13KB) Added 01/12/02
This macro shows a form with textboxes arranged to input values for a transformation matrix.
The transformation can then be applied to objects which are selected in the active drawing.
Intended to be a learning tool.
MirrorCopyExample.zip (5KB) Added 01/12/02
Simple example demonstrating how to make a mirror copy of a graphic object using the
LightArray.zip (16KB) Added 12/16/01
This is an example of a macro that checks which version of TurboCAD is running in order
to use the correct index values for TCLight extended properties. This is necessary due to changes
in the SDK between v7 and v8. The macro is intended to be run in a new, empty drawing. It will
add a few solid objects, and then a circular array of spotlights, based on input from a form.
Then the lights are randomly colored and the scene is rendered.
v8-MultiBooleanAdd.zip (9KB) Add 12/08/01
This does the same thing as Multi3DBoolAdd.tcm, below, but is written for TurboCAD v8.
Due to a change in the library file in which the 3D Boolean ops are stored, the v7 macro
will not work in v8. (Nor will this one work in v7.)
3D-QuickSplineClosed.zip (22KB) Added 11/05/01
This is very similar to the 3D-QuickSpline macro. The difference is that this one calculates a path for a closed
bspline curve based on the control points. It is intended that a closed 3D polyline will be used for the control point
frame. This means the first and last vertices of the polyline are coincident. This is simply to make the use of the macro
more logical. In actual practice, the last vertex is not included in the calculation, since it would just be a dulplicate
of the first. So in fact the last vertex could be place anywhere.
Multi3DBoolAdd.zip (7KB) Added 11/04/01
This macro allows to user to select multiple 3D solid objects and Boolean add them all with one step. The code sorts through the
selection set and ignores any objects that are not solids. This macro can also be used to help perform other 3D Boolean
operations. How would you make a screen plate by subtracting an array of solids arranged in a hole pattern? First, add
all the "hole" solids together with the macro. Then subtract the resulting solid from the plate. Could save a lot of time
compared to subtracting each hole separately. Note that for Boolean adds,
the objects do not have to intersect or be touching.
3D-QuickSpline.zip (21KB) Added 11/02/01
A pared down version of the 3D-Bspline macro. This one has no forms to fill in. Read the comments in the
code for details. Basically, you first draw a standard 3D polyline as the control point frame. Select the frame,
and run the macro. That's it. This picture will give you an
idea of how the QuickSpline curve follows the control frame.
DemoRestrictEntryToNum.zip (11KB) Added 10/20/01
Many of the macros I write are incomplete in that they are vulnerable to errors caused by invalid data entry.
For example, entering any non-numeric character in a field for a coordinate of a vertex will cause the macro to
halt with an error.
Usually that is fine for personal use, but to better "bug proof" macros, you can add code that will restrict the
input to entries that are valid for the intended use. This macro demonstrates a couple of different ways this can
Slot.zip (9KB) Added 10/20/01
Bare bones code showing how to draw arc segments in 2D polylines by setting the Bulge vertex property.
Screen shot with notation added.
IsClosed.zip (22KB) Added 10/19/01
Basically this macro tells you if the "Closed" property of a graphic is true or false. It is helpful
for determining if a 2D profile is closed, for purposes of making 3D solids. It
does not work with all graphics (read comments in code).
DemoCreateMDB.zip (14KB) Added 10/16/01
Demonstration of using DAO to create a Microsoft Access database file (MDB). Some fields are
added to the file and some information about graphics in the active drawing is placed into it.
Requires DAO 3.6.
SpikeyThing.zip (8KB) Added 10/15/01
Macro draws a green spikey thing.
Demonstrates use of TCW40LOFT to create solid object, in this case a cone. Also demonstrates rotation
of object. When the macro is run, multiple long, thin cones are drawn at randomized height, and rotated in
3D-Bezier-simple.zip (12KB) Added 10/15/01
Draws a polyline along a path of a 3D Bezier curve. Limited to input of four control points. This
basically allows you to connect two points with a 3D Bezier, and define direction vectors with two
other control points. Screen shot
ExcelExport.zip (10KB) Added 10/15/01
Demonstrates method to create and export data to a new Excel XLS file from within a TurboCAD macro.
Based on macro ExcelImport.tcm once posted by Anatoli Albul. You must have Excel installed on your
system for this macro to work.
3D-Bspline.zip (127KB) Added 10/14/01
Uses MSFLEXGRID control to enter control points for creation of a 3D Bspline. Requires
MSFLXGRD.OCX, included in the ZIP file.
Macro draws a polyline along the path of the resulting Bspline curve.
3D-Bspline-2.zip (18KB) Added 12/08/01
Basically the same as 3D-Bspline.tcm, but without the FlexGrid. Actually this works better.
After invoking the macro, the user selects a graphic object by clicking in the drawing with the mouse. All objects in the drawing are then hidden, except the selected object. A small form with a toggle button appears which can be used to toggle the visibility of the hidden objects. When done, the visibilty of all graphic objects is set back to true.
A little fun I had during lunch break one day. Macro starts with a form to allow adjusting a few parameters, and then draws the curve.
To create this object, I added a parameter for the Z coordinate as well, and used the resulting curve
as an extrusion path.
A macro which shows a listbox displaying all the layers in a drawing along with the layer color (by name). It allows selection of several layers at once for the purpose of changing all to a new color. The code was used in Visual Basic to create a DLL (see "Tools" section).
Places a text object in the drawing, base on a mouse click. The text of the object is the current drawing path and name. This idea was extended later to a Regen object that would automatically update when the file name or save location was changed.
It worked pretty well, but was not perfect. (Any way, I seem to have lost the regen version for now).
Demonstration of using sliders to modify RBG values. Allows changing foreground
and background colors separately to experiment with color contrast.
Show five methods of providing color selection in macros.
Requires Microsoft ActiveX control COMDLG32.OCX to be installed and
registered on the system.
Show three types of common dialog controls that can be used to open and save
files from a macro.
Requires Microsoft ActiveX control COMDLG32.OCX to be installed and
registered on the system.
Demonstration of how macro settings can be saved in a Windows *.ini file.
Demonstrates using different values for "justification" using the AddText method.
A macro for retrieving the extended properties of the application, the active drawing,
and the first graphic object (.Graphics(0)). Useful for discovering what extended properties
are available for use in macros.
Example of using recursive method to draw 2D stick trees.
Shows a way to invoke HTML help files from macros. Includes a sample CHM file.
Based on a suggestion from the TurboCAD user forums. Turns all layers off, and displays a list
of layer names. Each layer will be displayed by itself when it's name is clicked in the list.
This macro will lock selected objects in a drawing. What I like about this
macro is the way this is accomplished. A new extended property is created for the selected
objects to store the name of the layer the objects are on. Then the objects are moved to a newly
created, locked layer. To unlock the objects, the objects are moved back to their original layers
(using the layer name stored in the extended property) and the locked layer and extended properties
Simple macro example. Moves selected objects a fixed distance based on input of X, Y, and Z
values. This code was later used to make a DLL plug-in.
Simple macro example. Toggles paper color between black and white. This code was later used to make a DLL plug-in.
From a thread in the TurboCAD user forum. Present a dialog box to allow input parameters for
drawing a polyline along a helical path.
Automatically measures the time to complete the various render modes.
Plug-in Tools for TurboCAD:
These plug-ins are simple tools that can be used in TurboCAD. Each one was first
developed as a macro, and then later compiled into a DLL file in Visual Basic. To use the
tools, copy the DLL file into the Draggers folder under your TurboCAD installation directory.
The next time you start TurboCAD, you should see a new tool bar with the tool(s) on it. To remove the
tools, simply remove the DLL files from the Draggers folder.
custompapercolor_dll.zip (11KB) Added 03/08/03
This tool is sort of like the PaperColor tool (see article
Making Tools for TurboCAD), but
has been enhanced to allow the user to assign custom colors to each of the
buttons. The interface is an adaptation of the ZoomFactor tool form. View
this pdf document for more information about installing and using
Note that CustomPaperColor uses the Windows ActiveX control "comdlg32.ocx".
Usually this will already be on your system. The PDF implies that this file is
included in the download archive, but that is not the case; the download
provided here only contains the CustomPaperColor.dll file. If you need
comdlg32.ocx you should be able to find it online. Here is one place you can get
ZoomFactor.zip (12KB) Added 05/15/02
Tool to allow quickly changing the zoom factor setting. Normally, you have to
go through the Options menu to open the Program Setup/Preference, enter a new
zoom factor setting, and click OK. I found that I wanted the ability to quickly
change zoom factor on the fly as I'm working, because I've come to rely on the
zooming function using the mouse wheel to move around in drawings. When this
tool is invoked, it will display a small button bar with five buttons, each set
for a different zoom factor. Clicking one of the buttons once sets the zoom
factor to a new value and closes the bar. The values assigned to the buttons are
configurable by double-clicking on the word "Config." at the bottom of the bar.
On my systems, I assign a keystroke combinations of "Shift + Z" to invoke this
TextFindandReplace.zip (10KB) Added 02/10/02
Tool will search active drawing space for text graphics, and replace a given string with
a new string. Simple tool with no settings, is case sensitive. Look for the command for this tool
at the bottom of the "Edit" menu, or as a new button on the "Text" toolbar.
Tool made from ChangePaperColor.tcm. Toggles paper color between black and white.
Clears the undo buffer. I don't have a need for this now but maybe you do. Only works in
v8 because this function was not implemented in the v7 SDK.
Tool made from ChangeLayersColors.tcm. Allows changing color of mutiple layers at once.
Tool made from MoveSelection.tcm. Just another way to move selected objects a given distance
along any axis. I often use this tool instead of the inspector bar fields.
(VB source files 21KB)
This file demonstrates how to include multiple tools in one plug-in. In this case, the tools
are very simple. There are five tools, each of which changes the paper color. Each tool has
it's own button on a common toolbar.
- TCVBTool.exe (58 KB, self extracting)
This is Visual Basic source code containing the basic elements for creating a plug-in
tool for TurboCAD. This code was posted to the
TurboCAD Programming forum some time ago by
SoftDev developer Anatoli Albul. I have re-posted it here
with Anatoli's kind permission.
This source was used as the starting point for all the tools I have included above. I plan
to have a section on this site discussing in more detail how this code works, but have not
had time to complete it. There are also more examples in the SDK sample code, and if you
look at those you will see that much more can be included than what is contained is this source.
(Back to top)
Regen Objects for TurboCAD:
Regens are objects, made up of TurboCAD graphic objects, that you can place in a drawing.
The regens are coded so that they respond to certain events, such as resizing or moving the object, or
opening and saving a file, etc. Depending upon how the regen object is coded, it will then "regenerate" itself
based on the new conditions.
Like plug-in tools, regens are compiled into DLL files using an external development application, such as
Visual Basic, or C++. To use the regens in your drawings, the regen DLL file must be placed in the "Regens" folder
under your TurboCAD "Program" folder. To find the regens in TurboCAD, look under the "SDK" menu in V7, and the "AddOns"
DateRegen.zip (13KB) Added 02/22/02
This gives you a regen object which always displays the current system date. There is
a property page which allows you to set the text size, and change the way the
date is displayed. One "feature" I did not anticipate when I made this regen is
that each time the date object regenerates, it will do so using the font style
that is currently active in the drawing. This may or may not be desirable,
depending on how you look at it! It would be possible to add an option to
the property page to either have the object regen the way it does now, or have
it keep the same font style it had when it was originally placed. I may do that
if anyone shows an interest in using this regen.
(Back to top)
External Apps that work with TurboCAD:
These are applications made in Visual Basic that run outside of TurboCAD.
(Back to top)
TCWRenamer9902.zip (1.55 MB) added
This is complete mini-app that will need to be installed on your system in
order to run. This is because it uses two ActiveX controls that must be registered with Windows. There are
more details about these files in the text document included in the ZIP file.
If you create symbols in TurboCAD, and have looked for them on your hard
drive, you know that they are given non-descriptive names, such as
"Symb0003.TCW". If you have given the symbols names in the TurboCAD symbols
palatte, you will be able to read the names in Windows Explorer by looking at
the file property, in the summary information tab. What I have done in the past
was manually copy this name from the document summary information dialog, and
paste it into the file name to make them more descriptive.
I found out how to read these names from the document summary information
using Visual Basic, and have made this application to assist with automatically
renaming the files.
This is a Windows Application that will install and uninstall like any other
program. I have tested it in Windows 98SE, Windows ME, Windows 2000, and Windows
XP and it has not given me any trouble with either TCAD v7 or v8 symbols files.
One person who is running Windows NT4 SP6 has reported that the program will
exit with an error, so try it at your own risk.
This is what the opening form
of the application looks like.
This is a fairly useless application. It is a EXE that will
run by itself, but needs TurboCAD to be open with an active drawing before it will do anything. All it
does is draw a bunch of circles in the drawing, with the option of having the color gradually change from blue
to red. Great, huh? Well, it was just a simple example of how an external application can be made that will
GC-source2.zip (4 KB) source code for Visual Basic 6.