P. 1
81959924 AutoCAD VBA Programming Tools and Techniques

81959924 AutoCAD VBA Programming Tools and Techniques

|Views: 280|Likes:
Published by xuanhuynh

More info:

Published by: xuanhuynh on Nov 02, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Page 84

Dim MyLayer As AcadLayer
Set MyLayer = ThisDrawing.Layers.Add(''MyLayer")
MyLayer.Color = acBlue
MyLayer.Linetype = "DASHED"

Note the use of the constant acBlue to designate the color value. A complete list of constants can be found in the
class inside the Object Browser. In most cases, you can figure out what the name of the constant will be once
you learn the basic method behind the naming scheme. To illustrate, the remaining color codes are acRed, acYellow,
acCyan, and so forth.

The uses of most of the named constants found in the object browser are pretty obvious. But if you are not sure, select
the member item: at the bottom of the object browser, the value of the constant will be shown along with a quick
description of how it is intended to be used. Press the F1 key for even more information about the constant and how to
use it.

Returning to the collectionscollections are used in AutoCAD for more than just tables of common information. They are
also used when working with groups of entity objects such as those found in the block references, Model Space, Paper
Space, selection sets, and entity groups. The same basic strategies are employed in these cases as well. Entity objects are
added to the Model Space collection or Paper Space collection or to a block definition collection. When an application
wants to access an entity, it can do so through the collection methods as applied to any of the entity collections.

The following tables are available for all collections in the AutoCAD VBA environment. There are not as many
methods and properties associated with collection objects as there are with the objects we've looked at thus far. The
reason is that collection objects are a general object used to house other objects that will have more properties and
methods as you drill deeper. Think of collections as a list containing reference pointers to the individual items that in
turn contain all the details about themselves.

< previous page


next page >

< previous page


next page >

Page 85

MethodWhat it does


Adds a new member to the collection of choice. Remove a member using either the Delete or RemoveItems methods defined in
the object members.

DeleteDeletes a member from the collection. This is available only in the view ports collection. In all other AutoCAD collections, the
delete function is found in the data objects. That is, to delete a layer, you first access the specific layer object, then the delete( )
method applied to that object. This will remove it from the collection.


Retrieves a member given its index value, which can be a number or a string.


What it's for


An integer containing a count of the objects in the collection. This value is read-only.

The Item method is used to retrieve collection members. It works on all manners of collections, ranging from tables to selection sets. When
referencing an item from a collection, you can use either an index value (an integer) or the name of the collection member being sought. Names
are applied only when working with objects that have names such as the block table or text style table. On the other hand, a selection set
collection does not contain names and can be referenced only by an index number. We will explore collections in much greater detail in Chapters
5 and 6. The important thing to keep in mind right now is that you use collections to drill deeper in the object hierarchy.

Entity Objects

Each entity in the AutoCAD database is an object and has a set of methods and properties that are specific to the control of that object. There
are many methods and properties that share the same name and accomplish the same feats from one entity to the next (this is polymorphism at

< previous page


next page >

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->