.NET

Reply
Distinguished Contributor
a7v1n
Posts: 216
Registered: ‎10-02-2008
Message 1 of 3 (473 Views)

get block subentity

473 Views, 2 Replies
04-12-2010 02:02 PM
hi. how do you get the subentities in a block? i want to compute the intersection of an entity in a block and a line in modelspace. thanks...
*Tony Tanzillo
Message 2 of 3 (473 Views)

Re: get block subentity

04-12-2010 02:15 PM in reply to: a7v1n
You use the explode() method to explode the block, and
then transform the resulting entities using the blockref's
BlockTransform property, and then check each exploded
entity for intersection with the model space entity.

That's how you do it.

If you what you are asking for is a detailed code example
showing how to do it, then I wouldn't wait hold my breath,
because it's fairly involved and not many here have the
time to provide that level of tutoring.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6371615@discussion.autodesk.com...
hi. how do you get the subentities in a block? i want to compute the
intersection of an entity in a block and a line in modelspace. thanks...
Mentor
JamieVJohnson2
Posts: 165
Registered: ‎08-26-2010
Message 3 of 3 (308 Views)

Re: get block subentity

08-09-2011 02:17 PM in reply to: *Tony Tanzillo

Sorry, I couldn't resist.  It is time to exhale and start breathing again.  Patrick Johnson posted some excellent code just for this issue.  I took it and modified it to use nested transactions (a process I find that dramatically speeds up code processing, and makes everything go back in 1 undo command).  Here is that code:

    Public Sub IntersectionPtsForBlocks(ByRef blk As BlockReference, ByRef ent As Entity, ByRef pts As Point3dCollection, ByRef trans As Transaction)
        Using trans2 As Transaction = trans.TransactionManager.StartTransaction
            Dim objs As DBObjectCollection = New DBObjectCollection()
            blk.Explode(objs)
            For Each obj As DBObject In objs
                Dim entBref As Entity = CType(obj, Entity)
                IntersectionPtsForEntities(entBref, ent, pts, trans2)
            Next
            For Each obj In objs
                obj.Dispose()
            Next
            trans2.Commit()
        End Using
    End Sub

    Public Sub IntersectionPtsForEntities(ByRef ent1 As Entity, ByRef ent2 As Entity, ByRef pts As Point3dCollection, ByRef trans As Transaction)
        Try
            If TypeOf ent1 Is Hatch Or TypeOf ent2 Is Hatch Then
                Exit Sub
            Else
                If (TypeOf ent1 Is BlockReference) And (ent1.Visible = True) Then
                    IntersectionPtsForBlocks(ent1, ent2, pts, trans)
                ElseIf (TypeOf ent2 Is BlockReference) And (ent1.Visible = True) Then
                    IntersectionPtsForBlocks(ent2, ent1, pts, trans)
                Else
                    If (ent1.Visible = True) Then
                        Dim intPts As New Point3dCollection
                        ent1.IntersectWith(ent2, Intersect.OnBothOperands, intPts, New IntPtr, New IntPtr)
                        For Each iPoint As Point3d In intPts
                            If Not pts.Contains(iPoint) Then pts.Add(iPoint)
                        Next
                    End If
                End If
            End If
        Catch ex As System.Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

 Hope this helps everybody in need, who may stumble across this post as I did.  Thank you everybody.

 

jvj

jvj
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.