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 164

Sub ViewAttribs()
Dim E1 As Object
Dim ATS As Variant
Dim EA As AcadAttributeReference
Dim MS As AcadModelSpace
Set MS = ThisDrawing.ModelSpace
I = MS.Count - 1
For J = 0 To I
Set E1 = MS.Item(J)
If E1.EntityType = acBlockReference Then
ATS = E1.GetAttributes
K = UBound(ATS) + 1
If K > 0 Then

S$ = "Found block - " & E1.Name & _
" - with " & Str$(K) & " attributes { "
For L = 0 To K - 1
Set EA = ATS(L)
S$ = S$ + EA.TagString & "/" & EA.TextString & " "

Next L
S$ = S$ & "}"
MsgBox S$

End If
End If
Next J
End Sub

You create attribute definitions with the AddAttribute( ) method just like adding other entities into the drawing
database. You can use AddAttribute( )with model space, paper space, or with a block definition object. Adding
attributes to model and paper space is not as common when working in VBA. When creating new attribute definitions it
will most likely be in a block reference.

< previous page

page_164

next page >

< previous page

page_165

next page >

Page 165

The parameters to the AddAttribute( ) method are the text height, attribute generation mode, prompt string, insert point, tag string, and default
value string. The insert point is supplied as an array of three double precision real numbers. The attribute generation mode is an integer code
number from the following table.

Mode

What it means

AcAttributeModeInvisible

Attribute is invisible and cannot be seen by operator.

AcAttributeModeConstant

Attribute value is constant and cannot be changed.

AcAttributeModeVerify

Operator will be requested to verify entry of attribute data.

AcAttributeModePreset

Sets the value of the attribute to the default value automatically on insert.

If the application requires that the attribute take on more than one mode, simply add these constants together. Mixing some of the codes will
not make much sense (such as verify and constant modes); however, there are many cases in which constant or preset attributes are expected to
be invisible, requiring a combination of mode settings.

Attribute definition and references contain many of the same properties. The most important ones are listed in the table below; most of the
others match the basic text object in their usage and names. Like other entities, there are methods for computing intersections and other
edit manipulations; however, you will not use them when manipulating attribute references as often as the ones listed below.

Property

What it is

Height

Text height of the attribute.

InsertionPointThe point where the text starts.

Mode

This is the integer mode value as described in the previous table. Use these constants to preserve your code from one
release of AutoCAD to the next. This value is only in the attribute definition and does not appear in the reference.

(table continued on next page)

< previous page

page_165

next page >

< previous page

page_166

next page >

Page 166

(table continued from previous page)

Property

What it is

PromptStringThis is the prompt string the user sees when the attribute is being referenced inside AutoCAD. This string is only in the
attribute definition and does not appear in the attribute reference.

TagString

The tag for the attribute. The tag is used when referencing the attribute in the attribute extract.

TextString

In an attribute reference, this value is the text entered by the user (or application). For an attribute definition, this string is
the default value of the attribute.

Working with attributes is quite easy inside of VBA. You can add and manipulate them within block object definitions, and when you use them in
a drawing, you'll find them only when you're accessing the block reference objects specifically. Compared with the techniques you use to get at
attributes inside of the AutoLISP environment, this is a vast improvement.

< previous page

page_166

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)//-->