Explode help

Explode help

ProfWolfMan
Advocate Advocate
1,054 Views
4 Replies
Message 1 of 5

Explode help

ProfWolfMan
Advocate
Advocate

 

Dear sirs,
Below is my code to bind all xrefs in current drawing.
(assumed that there is no nested xref)
Now i want to explode all of that binded xrefs(block references).
anyone can help me this?
--------------------------------------------------------------------------------------
Public Sub BindXrefDwgs()
        doc = Application.DocumentManager.MdiActiveDocument
        db = doc.Database
        Using docklock As DocumentLock = doc.LockDocument()
            Using DWGMTrans As Transaction = db.TransactionManager.StartTransaction
                Dim XrefGr As XrefGraph = db.GetHostDwgXrefGraph(True)
                Dim XrefGrCol As GraphNodeCollection = New GraphNodeCollection
                Dim xrefdwgs As New ObjectIdCollection
                Dim index As Integer = 0
                For index = 0 To XrefGr.NumNodes
                    XrefGrCol.Add(XrefGr.GetXrefNode(index))
                Next
                For Each XrefGrNode As XrefGraphNode In XrefGrCol
                    If XrefGrNode.XrefStatus <> XrefStatus.FileNotFound Then
                        xrefdwgs.Add(XrefGrNode.BlockTableRecordId)
                    End If
                Next
                Try
                    db.BindXrefs(xrefdwgs, False) 'bind
                Catch
                Finally
                    DWGMTrans.Commit()
                    DWGMTrans.Dispose()
                End Try
            End Using
        End Using
End Sub
--------------------------------------------------------------------------------------

 

Thanks & Regards,
G
0 Likes
Accepted solutions (1)
1,055 Views
4 Replies
Replies (4)
Message 2 of 5

chiefbraincloud
Collaborator
Collaborator

If you just want to explode the main Xref block and place all the resulting objects in Model or Paper space, then you just open the BlockReference and call ExplodeToOwnerSpace()

 

If you want more control over the objects, or want to explode nested blocks or whatever, then you open the BlockReference and call bref.Explode(DbObjectCollection).  You pass it an empty DbObjectCollection and the resulting objects created by the Explode are put into the Collection.  Then you are responsible for both Adding those objects to the Database and erasing the original object.

 

I have never used ExplodeToOwnerSpace, so I am not sure, but I think in that case you would also be responsible for erasing the original object, but the exploded objects are automatically added to whatever the parent BlockTableRecord was.

Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 3 of 5

ProfWolfMan
Advocate
Advocate

Hi,

 

Now i wrote a procedure to explode all block references.

But i got error msg as eCannotScaleNonUniformly.

I have uniformly scaled blocks only. Below is my code.

Anyone can help me, please.

 

note: code is attached.

Thanks & Regards,
G
0 Likes
Message 4 of 5

ProfWolfMan
Advocate
Advocate

hi,

 

now i try some other way using 'explodetoownerspace'.

but i did not achive result.

i got 'einvalidinput' error.

 

please help me.

Thanks & Regards,
G
0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

This worked for me with non-uniformed scaled blocks

 

        <CommandMethod("ExplodeBlocks")> _
        Public Sub ExplodeBlocks()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Using trx As Transaction = db.TransactionManager.StartTransaction

                Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)

                For Each btrObjId As ObjectId In bt

                    Dim btr As BlockTableRecord = btrObjId.GetObject(OpenMode.ForRead)

                    If btr.IsLayout Or btr.IsAnonymous Then
                        Continue For
                    End If
                    Dim objIdColl As ObjectIdCollection = btr.GetBlockReferenceIds(True, True)

                    For Each objId As ObjectId In objIdColl
                        Dim acBref As BlockReference = objId.GetObject(OpenMode.ForWrite)
                        MsgBox(acBref.Name)
                        acBref.ExplodeToOwnerSpace()
                    Next
                Next
                trx.Commit()
            End Using
        End Sub