我做了一些改变,看看这是否有帮助。
有几件事表明,发布的代码依赖于未发布的代码。例如,从未设置用m_AttLayerNameNew引用的层名称。在我发布的代码中,我将其设置为一个测试层,我确保该层在图形中可用。
我做的另一个更改是防止例程使用标准AutoCAD blocks Modes\u Space和Paper\u Space运行GetAttributes()函数。
- Public Sub BlkDefAttLayerChg()
- Dim objAttribs As Collection
- Dim objAttrib As AcadAttribute
- Dim objBlock As AcadBlock
- Dim strAttribs As String
- Dim m_AttLayerNameNew As String
- Dim strattribsl As String
- '' get the block
- For Each objBlock In ThisDrawing.Blocks
-
-
- 'Set objBlock = ThisDrawing.Blocks.Item(objBlock.Name) ''''not needed
- If InStr(objBlock.Name, "_Space") = 0 Then 'Don't process Model and Paper space blocks
- Set objAttribs = GetAttributes(objBlock)
- '' show some information about each
- For Each objAttrib In objAttribs
-
- 'm_AttLayerNameNew = "TestLayer" ''''used for testing. Layer must be present
-
- objAttrib.Layer = m_AttLayerNameNew ' Assign new layer name
- strattribsl = objAttrib.Layer 'is this needed if it's already set in m_AttLayerNameNew
- Next
- End If
- Next
- End Sub
- Function GetAttributes(objBlock As AcadBlock) As Collection
- On Error Resume Next
- Dim objEnt1 As AcadEntity
- Dim objAttribute As AcadAttribute
- Dim coll As New Collection
- '' iterate the block
- For Each objEnt1 In objBlock
- '' if it's an attribute
- If objEnt1.ObjectName = "AcDbAttributeDefinition" Then
- '' cast to an attribute
- Set objAttribute = objEnt1
- '' add attribute to the collection
- coll.Add objAttribute, objAttribute.TagString '***This causes the error
- End If
- Next
- 'return collection
- Set GetAttributes = coll
- End Function
|