I have had numerous requests from people asking for a tutorial on
for Applications. Well here it is. This tutorial will take you from the
of opening the Visual Basic Editor to building a simple application.
I must stress though, that Visual Basic is a language with thousands of
built in functions and numerous custom modules and controls available. I
strongly recommend that you invest in a good Visual Basic book as I cannot
possibly take you through the whole VB language. Also, remember that
AutoCAD Visual Basic for Applications is a subset of the Visual Basic
language with it's own build in functions and controls.
Anyway, enough warbling for now, let's get started with our application.
This application called, Change Layer, will allow you to change the
any entity within your drawing. It will display a dialogue box with a list
listing all of the available layers in your drawing. After you have
a layer to change to, it will prompt you to select the entities you would
to change to that layer and then change them. Sound's good hey! Here we
Fire up AutoCAD and choose 'TOOLS-MACRO-VISUAL BASIC EDITOR' from the
The Visual Basic Editor should appear and will look like this:
Don't worry about the various windows that appear in the editor. We
will go through each one as we progress through this tutorial.
Now choose 'INSERT-USERFORM' from the pull down menu bar.
The following should appear :
This is the form that we will use to create our dialogue box from.
Now look in the top left hand corner of the screen. There you will find
the Project dialogue. This basically lists all the Forms, Modules, etc.
that are part of your VBA project.
As you can see, because we haven't named our project yet, AutoCAD gives
project the name Project.dvb. Before we go any further let's save our
and give it a name. Select 'FILE-SAVE' from the menu bar and name the
'Chlayer.dvb'. Also you will be able to see the form that we created
under Forms and given the default name of UserForm1. All forms, modules
controls that you insert into your project will be given a default name.
can, if you wish change it later but, in this exercise we will only work
the default names.)
Now, let's have a look at the Properties dialogue box. This you will
the lower left-hand corner of the Editor and should look like this:
This dialogue lists all the properties that an object has. The dialogue
show all the properties available for the form, UserForm1 that you
If it doesn't, click on the form to select it.
The first property listed is (Name) - UserForm1. This is the property
you would change if you wanted to change the name of the form. Please
remember, that this is the name that you use to programatically refer to
this particular form. If you change this name once you have written code
referring to this form, you will have to manually change all the instances
of that name in your code.
Let's change the caption of the form. Select the caption property and
from 'UserForm1' to 'Change Layer'. Your form should now look like this :
Notice how the caption has changed. On the next page we will have a
adding controls to our form. See you there.........