- UID
- 1
- 积分
- 16111
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
How do I explode BlockReferences and convert the attributes to text, using VBA?
ID 74082
Applies to: AutoCAD 2000
AutoCAD 2000I
AutoCAD 2002
Date 7/24/2002
This document is part of Attribute Block Reference VBA
Question
Is there an example showing how to explode BlockReferences and convert the attributes
to text?
Answer
Note: This VBA example does not contain error checking. Keep in mind that Attributes
cannot be exploded so they are deleted and text is created at the same location.
Also the explode method explodes the blockReference creating entities but the
blockReference is not deleted. Using the erase method of the selectionset deletes
the blockReferences in this example. The following example assumes a block reference
named "testBlock":
Sub explodeBlkMakeText()
Dim sset As AcadSelectionSet
Dim filterType As Variant
Dim filterData As Variant
Dim p1(0 To 2) As Double
Dim p2(0 To 2) As Double
Dim grpCode(0) As Integer
Dim grpValue(0) As Variant
Dim blockRefObj As AcadBlockReference
Dim explodedObjects As Variant
Dim I As Integer
Dim varAttributes As Variant
Dim strForText As String
Dim txt As AcadText
Dim attInsertionPoint As Variant
Dim dHeight As Double
' select all blockreferences named testBlock
Set sset = ThisDrawing.SelectionSets.Add("TestSet")
grpCode(0) = 2
filterType = grpCode
grpValue(0) = "testBlock"
filterData = grpValue
sset.Select acSelectionSetAll, p1, p2, filterType, filterData
' iterate through selectionset
For Each blockRefObj In sset
If blockRefObj.HasAttributes = True Then
' Get the attributes for the block reference
varAttributes = blockRefObj.GetAttributes
' Create text entites where the attributes are
For I = LBound(varAttributes) To UBound(varAttributes)
strForText = varAttributes(I).TextString
attInsertionPoint = varAttributes(I).InsertionPoint
dHeight = varAttributes(I).Height
ThisDrawing.ModelSpace.AddText strForText, attInsertionPoint, dHeight
Next
End If
explodedObjects = blockRefObj.Explode
' Loop through the exploded objects
For I = 0 To UBound(explodedObjects)
' delete that attribute definition
If explodedObjects(I).ObjectName = "AcDbAttributeDefinition" Then
explodedObjects(I).Delete
End If
Next
Next blockRefObj
'erase the blocks that were exploded
sset.Erase
'delete the selectionset
sset.Delete
End Sub |
|