- UID
- 307531
- 积分
- 57
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-8-12
- 最后登录
- 1970-1-1
|
发表于 2005-12-2 19:24:57
|
显示全部楼层
简单
AutoCAD自带的VBA帮助里关于“快属性编辑”一句经典的话:
[' Note: There is no SetAttributes. Once you have the variant array, you have the objects.
(翻译:'注意:没有SetAttributae这个方法; 你一旦拥有了属性Variant数组,你有拥有了这个对象。)] 意思很简单:当你通过GetAttribute获取了块的属性(比如赋给Dim varAttributes As Variant它了,
),那么,varAttributes这个变量就能代表“块属性”这个对象,你可以对它进行操作,就能编辑块的属性值。这个做法在VBA的对象里很少见。
现在借花献佛,把Autocad自带的例子给你看看。
================================================
================================================
================================================
Sub Example_GetAttributes()
' This example creates a block. It then adds attributes to that
' block. The block is then inserted into the drawing to create
' a block reference.
' Create the block
Dim blockObj As AcadBlock
Dim insertionPnt(0 To 2) As Double
insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
Set blockObj = ThisDrawing.Blocks.Add(insertionPnt, "TESTBLOCK")
' Define the attribute definition
Dim attributeObj As AcadAttribute
Dim height As Double
Dim mode As Long
Dim prompt As String
Dim insertionPoint(0 To 2) As Double
Dim tag As String
Dim value As String
height = 1#
mode = acAttributeModeVerify
prompt = "Attribute Prompt"
insertionPoint(0) = 5#: insertionPoint(1) = 5#: insertionPoint(2) = 0
tag = "Attribute Tag"
value = "Attribute Value"
' Create the attribute definition object in model space
Set attributeObj = blockObj.AddAttribute(height, mode, prompt, insertionPoint, tag, value)
' Insert the block
Dim blockRefObj As AcadBlockReference
insertionPnt(0) = 2#: insertionPnt(1) = 2#: insertionPnt(2) = 0
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, "TESTBLOCK", 1#, 1#, 1#, 0)
ZoomAll
' Get the attributes for the block reference
Dim varAttributes As Variant
varAttributes = blockRefObj.GetAttributes
' Move the attribute tags and values into a string to be displayed in a Msgbox
Dim strAttributes As String
Dim I As Integer
For I = LBound(varAttributes) To UBound(varAttributes)
strAttributes = strAttributes & " Tag: " & varAttributes(I).TagString & _
" Value: " & varAttributes(I).textString & " "
Next
MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
' Change the value of the attribute
' Note: There is no SetAttributes. Once you have the variant array, you have the objects.[/COLOR]
' Changing them changes the objects in the drawing.
varAttributes(0).textString = "NEW VALUE!"
' Get the attributes
Dim newvarAttributes As Variant
newvarAttributes = blockRefObj.GetAttributes
' Again, display the tags and values
strAttributes = ""
For I = LBound(varAttributes) To UBound(varAttributes)
strAttributes = strAttributes & " Tag: " & varAttributes(I).TagString & _
" Value: " & varAttributes(I).textString & " "
Next '''////这个循环就在修改属性值!你要的在这儿。。。。
[/COLOR]
MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
End Sub
================================================
================================================
================================================.
师父就在身边:AutoCAD帮助-开发人员文档,是个好东东。 |
|