.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Exploding all blocks

3 REPLIES 3
Reply
Message 1 of 4
gwhitcherQ98HZ
187 Views, 3 Replies

Exploding all blocks

I am using this code. It produces no errors but does not explode the blocks in the drawing. WShat am I missing

Try
Dim objs As DBObjectCollection = New DBObjectCollection()
Using lk As DocumentLock = doc.LockDocument()
Using tr As Transaction = db.TransactionManager.StartTransaction()

Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim modelBtr As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead)
For Each id As ObjectId In modelBtr
If id.ObjectClass.Name = "AcDbBlockReference" Then
Dim ent As Entity = DirectCast(tr.GetObject(id, OpenMode.ForRead, False), Entity)
ent.Explode(objs)
ent.UpgradeOpen()
ent.Erase()
End If
Next
tr.Commit()
End Using
End Using
Catch ex As Exception

End Try
3 REPLIES 3
Message 2 of 4

Firstly, please post your code by clicking "</>" button above the message window, so that the code would be easier to read.

 

Your code DOES explode the block correctly (thus, no error). However, since you call the method Explode(DBObjectCollection), then it is UP TO YOU to decide what to do with the DBObjects generated, which are not database-residing. Since your code did nothing with them, thus they are lost (you should disposed them!) in the memory and it appears to you that nothing left after the explosion.

 

If the purpose for explosion is to leave the generated block elements in the same space as the block reference is, you should add each DBObject in the collection into the Model/PaperSpace by your own code; or better yet, you can simply call ExplodeToOwnerSpace(), which automatically adds the explosion elements into the same Space as the BlockReference (you still have to erase the block reference by your code, if necessary). That is, Explode(DBObjectCollection) or ExplodeToOwnerSpace() method does not do exactly the same as the command "EXPPLODE"

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 4

Sorry for being such a newb. I'm a little confused by your answer. I casted as an entity. It doesn't appear to allow for ExplodeToOwnerSpace. If I cast as a BlockReference it does but it does not put the exploded parts back into modelspace in their original location and leaves the block in tact.

 

How do I remove the block and get the exploded parts put into their place?

Message 4 of 4

I found the issue, upon opening the drawing, I wasn't resetting the dwg database to the newly opened doc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta