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

Unit one Solid3D with Another Solid3D - BooleanOperationType.BoolUnite

3 REPLIES 3
Reply
Message 1 of 4
wcruzcc
452 Views, 3 Replies

Unit one Solid3D with Another Solid3D - BooleanOperationType.BoolUnite

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.

3 REPLIES 3
Message 2 of 4
Hallex
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
Message 3 of 4
wcruzcc
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;
Message 4 of 4
Balaji_Ram
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

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost