Seperating AutoCAD surfaces with two seperate entities in one object

Seperating AutoCAD surfaces with two seperate entities in one object

sbouwens
Explorer Explorer
350 Views
1 Reply
Message 1 of 2

Seperating AutoCAD surfaces with two seperate entities in one object

sbouwens
Explorer
Explorer

 

Hello,

 

I'm currently working on a .net project related to slicing surfaces based on several boundaries. However, i've encountered a problem with this challenge. The problem occurs when a autocad surface is sliced in the middle, and a new surface with two or more seperate bodies is created, as seen in the image below.  Slicing this outside surface then results in an eNoIntersections error. Hence, it is needed to seperate the outside surface into two seperate entities . Then only the surface that intersects with the boundary can be selected an no error should occur.

 

sbouwens_0-1660219253985.png

 

The code snippet (VB.NET) that currently performs the task of slicing the surface is attached below:

   Dim surfaceInsideBounds = DirectCast(sliceObject, Autodesk.AutoCAD.DatabaseServices.Surface)
                                        Dim sliceResults As SurfaceSliceResults = surfaceInsideBounds.SliceBySurface(SweptSurface)
                                        Dim surfaceOutsideBounds As Autodesk.AutoCAD.DatabaseServices.Surface = sliceResults.NegativeHalfSurface
                                        surfaceOutsideBounds.SetDatabaseDefaults()
                                        surfaceOutsideBounds.Layer = sliceObject.Layer
                                        surfaceOutsideBounds.Color = sliceObject.Color
                                        btr.AppendEntity(surfaceOutsideBounds)
                                        trans2.AddNewlyCreatedDBObject(surfaceOutsideBounds, True)

The surface inside the boundary and outside the boundary needs to be preserved in this process.

 

I'm looking for a similar method as described in Separate Solid Complexes into Separate Solids - AutoCAD DevBlog

with solid.SeparateBody(), but then for AutoCAD Surfaces. Can anyone provide some help?

 

With kind regards,

Stan Bouwens

0 Likes
351 Views
1 Reply
Reply (1)
Message 2 of 2

sbouwens
Explorer
Explorer

I'm currently stuck with the idea of exploding the surface with seperate bodies, and then unioning the parts that intersect with each other. Somewhere between lines 20-31 it somehow goes wrong.

 

       For Each oid In userSelectionIds
            Dim surfaceToSplit As Autodesk.AutoCAD.DatabaseServices.Surface = TryCast(acTrans.GetObject(oid, OpenMode.ForWrite), Autodesk.AutoCAD.DatabaseServices.Surface)
            Dim surfDBOBJColl As New DBObjectCollection
            Using acDBObjColl As New DBObjectCollection()
                surfaceToSplit.Explode(acDBObjColl)
                For Each DBObject In acDBObjColl
                    If DBObject.GetType() = GetType(Autodesk.AutoCAD.DatabaseServices.Surface) Then
                        surfDBOBJColl.Add(DirectCast(DBObject, Autodesk.AutoCAD.DatabaseServices.Surface))
                    ElseIf DBObject.GetType() = GetType(Autodesk.AutoCAD.DatabaseServices.Region) Then
                        Dim surface As New Autodesk.AutoCAD.DatabaseServices.Surface()
                        surface.SetDatabaseDefaults()
                        surface = Autodesk.AutoCAD.DatabaseServices.Surface.CreateFrom(DirectCast(DBObject, Autodesk.AutoCAD.DatabaseServices.Region))
                        surfDBOBJColl.Add(surface)
                    Else
                        ed.WriteMessage(vbLf & "Exploded entity is not a Surface or a Region")
                    End If
                Next
            End Using

            For Each motherSurface In surfDBOBJColl
ResetJoin:
                For Each toJoinSurface In surfDBOBJColl
                    If toJoinSurface = motherSurface Then Continue For
                    Dim intersectEntity As Entity() = motherSurface.BooleanIntersect(toJoinSurface)
                    If intersectEntity IsNot Nothing Then
                        motherSurface.BooleanUnion(toJoinSurface)
                        surfDBOBJColl.Remove(toJoinSurface)
                        GoTo ResetJoin
                    End If
                Next
            Next

            For Each joinedSurface In surfDBOBJColl
                joinedSurface.Layer = surfaceToSplit.Layer
                joinedSurface.Color = surfaceToSplit.Color
                btr.AppendEntity(joinedSurface)
                acTrans.AddNewlyCreatedDBObject(joinedSurface, True)
            Next

            surfaceToSplit.Erase()
        Next

        acTrans.Commit()

 

Can anyone provide me some guidance on joining surfaces together that overlap?

 

0 Likes