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

Availability:

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

08/12/2013

pdf

text

original

Page 87

Dim Obj As Object
Set Obj = ThisDrawing.ModelSpace.Item(0)

Another way to obtain an entity object is to have the user show it on the screen. The following code segment requests
that the user ''Pick an object" from the drawing. Note that as user activity increases, so must the error-checking in the
program code. If the user does not pick an object and the error handler is not enabled, the program will crash. By
enabling the error handler as shown below, your program can respond as required when user input does not follow what
was expected.

Dim Uobj As Object
Dim Pnt(0 To 2) As Double
On Error Resume Next
ThisDrawing.Utility.GetEntity Uobj, Pnt, "Pick an object: "
If Err.Number <> 0 Then
Err.Clear
MsgBox "Entity not selected."

Else

'Entity object now in variable (Uobj).

End If

Another way to get an object is to have the handle (a string) or Object ID (a number) and convert it to an object. These
two approaches work best when interfacing with external databases (handles) and when conversing with some
ObjectARX modules.

Given the object pointer, an application program can use the associated methods and properties to manipulate the
entities.

Because entity objects are all derived from the same general object handling system, there are many methods and
properties that are common to all entity objects. The following tables list those that are common.

The first table contains those methods that are related to performed edit type operations on the entity objects.

< previous page

page_87

next page >

< previous page

page_88

next page >

Page 88

Method

What it does

ArrayPolar
ArrayRectangular
Copy

Copies the object multiple times or a single time.

Erase

Erases the object.

GetXData
SetXData

Retrieves and sets extended data attached to an object.

Highlight

Highlights the object.

Mirror
Mirror3D

Creates a mirrored image of the object given two points that define the axis of reflection.

Move

Moves the object to a new location.

Rotate
Rotate3D

Rotates the object.

ScaleEntity

Scales the entity given a base point and scaling factor.

Update

Regenerates the object in the display.

Geometry methods associated with entities are very powerful tools for application developers. These are the same routines used inside AutoCAD
to solve the basic problems of CAD manipulation.

Method

What it does

GetBoundingBoxReturns two points describing a rectangular boundary around the object that is parallel to the world coordinate system.

IntersectWith

Determines the points where the current object intersects with another object.

TransformBy

Applies a transformation matrix to the object to combine rotation, axis shift, and scaling operations.

Many of the methods have parameters associated with them that you can quickly learn while typing them into the VBAIDE. As a properly
dimensioned object is filled in with the IDE, the parameters of the methods are prompted for as needed. Even more information is
available via the online help too. Programming has never been so programmer friendly!

< previous page

page_88

next page >

< previous page

page_89

next page >

Page 89

Property

What it's for

Color

Entity object color value as an integer.

EntityName

Same as the class name of the object. This value contains a descriptive type name used to identify what kind of object is
in use. The result is stored in a string and can be used when accessing custom objects. For most AutoCAD objects, the
EntityType property should be referenced instead.

EntityType

Integer code value indicating what type of AutoCAD object this reference represents. The integer code values have
named constants that can be used in VBA. The entity name (in English) has the characters a and c appended at the front.
For example, the constant for a circle entity can be referenced in the VBA code as acCircle.

Handle

The entity handle that can be used to interface with external databases. Each entity object is assigned a handle that
remains unique from one drawing session to the next making this string value perfect for indexing from other databases
back into AutoCAD.

Layer

The layer name for the object.

Linetype

The linetypes name for the object.

LinetypeScaleScale factor for the linetypes.

ObjectID

Like the handle, but a long integer instead of a string. Used when communicating with ARX applications.

Visible

Controls the visibility of the entity object. Setting an object to visible means that the layer controls whether the operator
can see it or not. When set to not visible, the object does not appear on the display.

Curved Entity Objects

Certain entities are considered curved objects in AutoCAD. These objects include lines, arcs, circles, polylines, lightweight polylines, ellipses,
leaders, rays, splines, and xlines. All of them describe objects that involve curvilinear geometry. This means that they have many common
properties and methods that two or more will share. Keep in mind that these common items are the result of polymorphism, and as a
consequence they are really different routines for each type of object. But from the VBA programmer's perspective they are the same because
they essentially solve the same problem.

< previous page

page_89

next page >

< previous page

page_90

next page >

Page 90

The list presented below is by no means complete. There are methods and properties that exist for specific entities. In addition, not all curved
objects will support all of the methods and properties presented.

Method

What it does

AddVertex

Adds a new vertex to a lightweight polyline.

AppendVertex

Appends a new vertex point to a polyline object.

GetBulge

Gets the current bulge value at a given index in a lightweight or traditional polyline.

GetWidth

Gets the starting and ending width value at a given index in a polyline.

Offset

Calculates an offset and creates a new object that is the result of that offset.

SetBulge

Sets the bulge factor at a given index location.

SetWidth

Sets the starting and ending width value at a given index.

Property

What it's for

Area

The area enclosed by the object. Not applicable on objects without area, such as lines.

Center

Center point for arcs, circles, and ellipses.

Closed

Indicates if a polyline or lightweight polyline object is closed or open.

Coordinates

The points of a polyline or lightweight polyline object.

EndAngle

End angle for an arc or ellipse.

EndPoint

End point for an arc, line, or ellipse.

StartAngle

Start angle for an arc or ellipse.

StartPoint

Start point for an arc, line, or ellipse.

Thickness

Extrusion thickness of 2D objects. Also included in the text, solid, shape, and other objects.

Each of the entity objects will have some methods and properties that are unique to that particular entity object. Working with lines and
other simpler objects in VBA is pretty easy once you get a feel for the naming

< previous page

page_90

next page >

You're Reading a Free Preview

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