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

explode hatch

1 REPLY 1
Reply
Message 1 of 2
gwhitcherQ98HZ
159 Views, 1 Reply

explode hatch

Can a hatch pattern be exploded. The hatch pattern does not have an option to explode

 

 

 Public Sub explode(doc As Document, db As Database, ed As Editor)
        Try
            Dim explodecount As Integer = 0
            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" Or id.ObjectClass.Name = "AcDbHatch" Then
                            Dim br
                            If id.ObjectClass.Name = "AcDbBlockReference" Then
                                br = CType(tr.GetObject(id, OpenMode.ForRead), BlockReference)
                                br.ExplodeToOwnerSpace()
                            Else
                                br = CType(tr.GetObject(id, OpenMode.ForRead), Hatch)
                            End If

                            Dim ent As Entity = DirectCast(tr.GetObject(id, OpenMode.ForRead, False), Entity)
                            br.UpgradeOpen()
                            br.Erase()
                            br.DowngradeOpen()
                            explodecount += 1
                        End If
                    Next
                    tr.Commit()
                End Using
            End Using
           
        Catch ex As Exception

        End Try
    End Sub

 

1 REPLY 1
Message 2 of 2
_gile
in reply to: gwhitcherQ98HZ

Hi,

The Entity class provides an Explode method which can be used by any instance of a class deriving from Entity.

 

You can define your own ExplodetoOwnerSpace for Hatch (or other types of Entity).

 

        private static void ExplodeToOwnerSpace(Hatch hatch, Transaction tr)
        {
            var ownerSpace = (BlockTableRecord)tr.GetObject(hatch.OwnerId, OpenMode.ForWrite);
            var entitySet = new DBObjectCollection();
            hatch.Explode(entitySet);
            foreach (Entity entity in entitySet)
            {
                ownerSpace.AppendEntity(entity);
                tr.AddNewlyCreatedDBObject(entity, true);
            }
        }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report