- <CommandMethod("TcExplodeAtt")>
- Public Sub TcExplodeAtt()
- On Error Resume Next
- Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
- Dim acCurDb As Database = acDoc.Database
- Dim acEditor As Editor = acDoc.Editor
- Dim acTypValAr(0) As TypedValue
- acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT,ATTDEF"), 0) '过滤参照块和属性
- Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
- Dim acSSPrompt As PromptSelectionResult = acEditor.GetSelection(acSelFtr)
- If acSSPrompt.Status <> PromptStatus.OK Then
- Exit Sub
- End If
- Dim acSSet As SelectionSet = acSSPrompt.Value
- Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
- For Each OBJ As Object In acSSet
- Dim E As Entity = acTrans.GetObject(OBJ.ObjectId, OpenMode.ForWrite)
- If E.GetRXClass.DxfName = "INSERT" Then
- Dim BRef As BlockReference = CType(E, BlockReference)
- Dim AttCollection As AttributeCollection
- AttCollection = BRef.AttributeCollection
- If AttCollection.Count < 1 Then
- BRef.ExplodeToOwnerSpace()
- BRef.Erase()
- Else
- 'Dim AttRef As AttributeReference
- 'For I As Int16 = 0 To AttCollection.Count - 1
- ' AttRef = acTrans.GetObject(AttCollection(I), OpenMode.ForRead, False)
- ' If AttRef.IsMTextAttribute = False Then
- ' Dim DBT As DBText = New DBText()
- ' DBT.Rotation = AttRef.Rotation
- ' DBT.TextString = AttRef.TextString
- ' DBT.WidthFactor = AttRef.WidthFactor
- ' DBT.Height = AttRef.Height
- ' DBT.TextStyleId = AttRef.TextStyleId
- ' DBT.LayerId = AttRef.LayerId
- ' DBT.LinetypeId = AttRef.LinetypeId
- ' DBT.Position = AttRef.Position
- ' AddEnt(DBT)
- ' Else
- ' Dim DBT As MText = AttRef.MTextAttribute
- ' AddEnt(DBT)
- ' End If
- 'Next
- '以下方法分解后AttDef可能缺失
- Dim DBC As DBObjectCollection = New DBObjectCollection
- 'BRef.ExplodeToOwnerSpace()
- BRef.Explode(DBC)
- Dim N As Long = 0
- For Each dbObj As DBObject In DBC
- Dim acEnt As Entity = dbObj
- If acEnt.GetRXClass().DxfName.ToUpper = "ATTDEF" Then
- Dim DBT As DBText = New DBText()
- Dim AttRef As AttributeReference
- AttRef = acTrans.GetObject(AttCollection(N), OpenMode.ForWrite, False)
- DBT.Rotation = AttRef.Rotation
- DBT.TextString = AttRef.TextString
- DBT.WidthFactor = AttRef.WidthFactor
- DBT.Height = AttRef.Height
- DBT.TextStyleId = AttRef.TextStyleId
- DBT.LayerId = AttRef.LayerId
- DBT.LinetypeId = AttRef.LinetypeId
- DBT.Position = AttRef.Position
- AddEnt(DBT)
- N = N + 1
- Else
- AddEnt(acEnt)
- End If
- 'MsgBox("Exploded Object: " & acEnt.GetRXClass().DxfName)
- Next
- BRef.Erase()
- End If
- Else
- Dim DBT As DBText = New DBText()
- Dim AttRef As AttributeDefinition = CType(E, AttributeDefinition)
- DBT.Rotation = AttRef.Rotation
- DBT.TextString = AttRef.TextString
- DBT.WidthFactor = AttRef.WidthFactor
- DBT.Height = AttRef.Height
- DBT.TextStyleId = AttRef.TextStyleId
- DBT.LayerId = AttRef.LayerId
- DBT.LinetypeId = AttRef.LinetypeId
- DBT.Position = AttRef.Position
- AddEnt(DBT)
- E.Erase()
- End If
- Next
- acTrans.Commit()
- End Using
- If Err.Number > 0 Then
- MsgBox(Err.Description)
- End If
- End Sub
|