.NET

Reply
Member
wcruzcc
Posts: 4
Registered: ‎06-02-2009
Message 1 of 4 (186 Views)

Unit one Solid3D with Another Solid3D - BooleanOperationType.BoolUnite

186 Views, 3 Replies
04-25-2013 07:37 PM

Been scratching my head on this one. I think I have eveything correct but it's not working, see below.

 

Dim F3D As New Solid3d 'these have been assigned a Solid3D
Dim addSolid as New Solid3d 'these have been assigned a Solid3D

F3D.BooleanOperation(BooleanOperationType.BoolUnite, addSolid)

 

If you see anything wrong, please let me know. Thanks.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 4 (159 Views)

Re: Unit one Solid3D with Another Solid3D - BooleanOperationType.BoolUnite

04-26-2013 09:04 AM in reply to: wcruzcc

Try this code, tested on A2010 only

        <CommandMethod("u3")> _
        Public Sub UnionTestCommand()

            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            Dim db As Database = doc.Database

            Dim ed As Editor = doc.Editor

            Dim ename1 As Entity
            Dim ename2 As Entity

            Dim id1 As ObjectId
            Dim id2 As ObjectId

            ' Select a solids

            Dim peo As New PromptEntityOptions(vbLf & "Select a first solid ")

            peo.SetRejectMessage(vbLf & "Must be solid3d object...")

            peo.AddAllowedClass(GetType(Solid3d), True)

            Dim per As PromptEntityResult = ed.GetEntity(peo)

            If per.Status <> PromptStatus.OK Then

                Return
            End If

            id1 = per.ObjectId

            peo = New PromptEntityOptions(vbLf & "Select second solid ")

            per = ed.GetEntity(peo)

            If per.Status <> PromptStatus.OK Then

                Return
            End If

            id2 = per.ObjectId

            Dim tr As Transaction = db.TransactionManager.StartTransaction()

            Using tr

                ename1 = TryCast(tr.GetObject(id1, OpenMode.ForRead, False), Entity)

                If ename1 Is Nothing Then Return

                ename2 = TryCast(tr.GetObject(id2, OpenMode.ForRead, False), Entity)

                If ename2 Is Nothing Then Return

                Dim sol1 As Solid3d = TryCast(ename1, Solid3d)

                Dim sol2 As Solid3d = TryCast(ename2, Solid3d)

                sol1.UpgradeOpen()

                sol2.UpgradeOpen()

                ' This will merge the geometry of the input solid sol1 

                ' into the geometry of solids[0] and then erase the geometry of 

                ' the input solid sol2
                sol1.BooleanOperation(BooleanOperationType.BoolUnite, sol2)

                ' We should delete sol2 otherwise we leave a solid with 

                ' degenerate geometry (i.e. zero geometry) in the database

                ' and that could cause issues

                sol2.Erase()

                tr.Commit()
            End Using

        End Sub

 See this article for more

http://adndevblog.typepad.com/autocad/2012/07/solids-created-with-booleanoper-may-crash-autocad-on-s...

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Member
wcruzcc
Posts: 4
Registered: ‎06-02-2009
Message 3 of 4 (148 Views)

Re: Unit one Solid3D with Another Solid3D - BooleanOperationType.BoolUnite

04-26-2013 01:47 PM in reply to: Hallex
It did not work, see below. It breaks right after "MsgBox("2"). FYI, I'm using AcadCad 2014
&nbsp;
&nbsp;
Dim ed As Editor = AcadDoc.Editor
Dim ename1 As Entity
Dim ename2 As Entity
Dim id1 As ObjectId
Dim id2 As ObjectId

id1 = F3D.ObjectId 'F3D &amp; addSolid are already "Solid3D" at this point.
id2 = addSolid.ObjectId 'F3D &amp; addSolid are already "Solid3D" at this point.

Dim tr As Transaction = db.TransactionManager.StartTransaction()
MsgBox("1")
Using tr
MsgBox("2")
ename1 = TryCast(tr.GetObject(id1, OpenMode.ForRead, False), Entity)
MsgBox("3")
If ename1 Is Nothing Then Return
MsgBox("4")
ename2 = TryCast(tr.GetObject(id2, OpenMode.ForRead, False), Entity)
MsgBox("5")
If ename2 Is Nothing Then Return
MsgBox("6")
Dim sol1 As Solid3d = TryCast(ename1, Solid3d)
Dim sol2 As Solid3d = TryCast(ename2, Solid3d)
MsgBox("Volume: " + sol1.MassProperties.Volume.ToString)
MsgBox("7")
sol1.UpgradeOpen()
MsgBox("8")
sol2.UpgradeOpen()
MsgBox("9")
sol1.BooleanOperation(BooleanOperationType.BoolUnite, sol2)
MsgBox("10")
sol2.Erase()
MsgBox("11")
tr.Commit()
MsgBox("Volume: " + sol1.MassProperties.Volume.ToString)
End Using
&nbsp;
ADN Support Specialist
Balaji_Ram
Posts: 699
Registered: ‎03-21-2011
Message 4 of 4 (111 Views)

Re: Unit one Solid3D with Another Solid3D - BooleanOperationType.BoolUnite

05-02-2013 10:23 PM in reply to: wcruzcc

Hi,

 

I tried the code snippet that Hallex shared in AutoCAD 2014 and it worked fine.

 

If you continue to have this issue, can you please provide the sample project and the drawing for me to reproduce the behavior ?

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

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