VBA The Basics
Posted: Sun Aug 19, 2001 11:36 pm
It was very confusing when I tried to learn VBA even though I was proficient in Lisp – the VBA jargon got me!
What are Objects, Properties, Methods, Constants and where do I go to access these?
The Answers as it relates to ICAD:
When the VB or VBA was written the developers decided using real world names to the various items in the program.
An Object is just that; it is any object that is exposed by VBA and ICAD is even an Object (it is king of the heap of objects and called the Application Object) Also a Line in your drawing is a Line Object (normally called a line entity), guess what they call a Circle – yes a Circle Object.
Properties are the settings of Objects, just like a Line in your drawing can have a color red – in VBA we say, the Color Property of the Line Object is set to Red and of course things like Layers are properties for all drawing entities – every user knows that all entities must have a layer and if one is not set then ICAD puts it on Layer 0 by default.
Methods are the activities we can do to Objects, if we rotate a line in ICAD – in VBA we say that we used the Rotate Method on a Line Object. So Methods can be considered like modifying Objects.
Constants are just special variables that can’t be changed and have user friendly names, just like CAD colors the Red = 1, Yellow = 2 and Green = 3 – in VBA constant vicRed = 1, vicYellow = 2 and vicGreen = 3.
The developers also created a development environment where VBA code is written and placed special icons adjacent to Properties, Methods and Constants to make it easy for us to understand what we are setting or altering.
The ICAD Object Model is a map displaying the VBA objects in ICAD and how to get to these. Just like a DOS command C:\ICAD\MyFile points to the directory named MyFile by going through the root directory in the C drive (C:\) then through the ICAD directory (ICAD\) in VBA it is just the same only instead of back slashes we use periods. To point to an Object in VBA we start at the root application object called IntelliCAD then to a document called ActiveDocument then to a space type called ModelSpace then to an entity, say a Line (IntelliCAD.ActiveDocument.ModelSpace.Line). To point to an circle object in paper space we use IntelliCAD.ActiveDocument.PaperSpace.Circle
The developers of ICAD helped us out by creating a special object called ThisDocument which is the ICAD Active Document. This can save us some typing by eliminating the “IntelliCAD.ActiveDocument” portion and replacing it with ThisDocument.
There are three areas in VBA where we go to – these are named ModelSpace, PaperSpace and Blocks to get to the drawing entities. Blocks contain drawing entities and this is the reason for the pathway.
When we want to interact with the user from the command prompt we go to an area in VBA called Utility (not much of a descriptive name) to select drawing entities and select positions such as corner or point. As an example to get the user to select a point we use ThisDocument.Utility.GetPoint(, "Place command prompt here").
Another important area is the Library (also not much of a descriptive name) to calculate, create or convert objects. The Library is separate from the ActiveDocument area, to access it we use Application Object. To create a Point Object at the drawing origin we use IntelliCAD.Library.CreatePoint(0,0,0)
I have covered a lot of basic information here and it is important you understand this so I suggest you go through each paragraph a few times to get your head around the jargon. Feel free to post any questions no matter what it is because I may not have fully explained the topic in sufficient detail and it will assist other readers.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
What are Objects, Properties, Methods, Constants and where do I go to access these?
The Answers as it relates to ICAD:
When the VB or VBA was written the developers decided using real world names to the various items in the program.
An Object is just that; it is any object that is exposed by VBA and ICAD is even an Object (it is king of the heap of objects and called the Application Object) Also a Line in your drawing is a Line Object (normally called a line entity), guess what they call a Circle – yes a Circle Object.
Properties are the settings of Objects, just like a Line in your drawing can have a color red – in VBA we say, the Color Property of the Line Object is set to Red and of course things like Layers are properties for all drawing entities – every user knows that all entities must have a layer and if one is not set then ICAD puts it on Layer 0 by default.
Methods are the activities we can do to Objects, if we rotate a line in ICAD – in VBA we say that we used the Rotate Method on a Line Object. So Methods can be considered like modifying Objects.
Constants are just special variables that can’t be changed and have user friendly names, just like CAD colors the Red = 1, Yellow = 2 and Green = 3 – in VBA constant vicRed = 1, vicYellow = 2 and vicGreen = 3.
The developers also created a development environment where VBA code is written and placed special icons adjacent to Properties, Methods and Constants to make it easy for us to understand what we are setting or altering.
The ICAD Object Model is a map displaying the VBA objects in ICAD and how to get to these. Just like a DOS command C:\ICAD\MyFile points to the directory named MyFile by going through the root directory in the C drive (C:\) then through the ICAD directory (ICAD\) in VBA it is just the same only instead of back slashes we use periods. To point to an Object in VBA we start at the root application object called IntelliCAD then to a document called ActiveDocument then to a space type called ModelSpace then to an entity, say a Line (IntelliCAD.ActiveDocument.ModelSpace.Line). To point to an circle object in paper space we use IntelliCAD.ActiveDocument.PaperSpace.Circle
The developers of ICAD helped us out by creating a special object called ThisDocument which is the ICAD Active Document. This can save us some typing by eliminating the “IntelliCAD.ActiveDocument” portion and replacing it with ThisDocument.
There are three areas in VBA where we go to – these are named ModelSpace, PaperSpace and Blocks to get to the drawing entities. Blocks contain drawing entities and this is the reason for the pathway.
When we want to interact with the user from the command prompt we go to an area in VBA called Utility (not much of a descriptive name) to select drawing entities and select positions such as corner or point. As an example to get the user to select a point we use ThisDocument.Utility.GetPoint(, "Place command prompt here").
Another important area is the Library (also not much of a descriptive name) to calculate, create or convert objects. The Library is separate from the ActiveDocument area, to access it we use Application Object. To create a Point Object at the drawing origin we use IntelliCAD.Library.CreatePoint(0,0,0)
I have covered a lot of basic information here and it is important you understand this so I suggest you go through each paragraph a few times to get your head around the jargon. Feel free to post any questions no matter what it is because I may not have fully explained the topic in sufficient detail and it will assist other readers.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au