@_gile,
Unfortunately this also crashes AutoCAD. Just using the surface crashes AutoCAD. Using the plane of the surface works but is not a solution for me.
Omitting the boolean value gives me a visual studio error:

I'm using AutoCAD 2020 and Visual studio 2017. DLL is compiled for .Net framework 4.7.
Referencefiles are ObjectARX2020 versions.
This is my vb.net code:
<CommandMethod("slicetest", CommandFlags.Modal)> Public Shared Sub SliceTest()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
Dim db As Database = doc.Database
Using trx As Transaction = db.TransactionManager.StartTransaction()
Dim btr As BlockTableRecord = TryCast(trx.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
Dim peo As New PromptEntityOptions(vbLf & "Select polyline: ")
peo.SetRejectMessage(vbLf & "Select POLYLINE!!!")
peo.AddAllowedClass(GetType(Autodesk.AutoCAD.DatabaseServices.Polyline), True)
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then Return
Dim plPath As Autodesk.AutoCAD.DatabaseServices.Polyline = TryCast(per.ObjectId.GetObject(OpenMode.ForWrite), Autodesk.AutoCAD.DatabaseServices.Polyline)
Dim Dia As Double = 100
Dim circ As New Circle(plPath.StartPoint, New Vector3d(0, 0, 1), Dia / 2)
Dim sol As New Solid3d With {
.RecordHistory = True
}
Dim sob As New SweepOptionsBuilder With {
.Align = SweepOptionsAlignOption.AlignSweepEntityToPath
}
sol.CreateSweptSolid(circ, plPath, sob.ToSweepOptions())
btr.AppendEntity(sol)
trx.AddNewlyCreatedDBObject(sol, True)
Dim solids = New List(Of Solid3d) From {
sol
}
For i As Integer = 1 To plPath.NumberOfVertices - 2
Dim tempList = New List(Of Solid3d)()
Dim vec As New Vector3d
Dim plnsrf As New PlaneSurface
Dim srf As New Autodesk.AutoCAD.DatabaseServices.Surface
If plPath.GetSegmentType(i) = SegmentType.Arc Then
vec = plPath.GetPointAtParameter(i).GetVectorTo(plPath.GetPointAtParameter(i - 1))
Dim acDBObjColl As New DBObjectCollection()
acDBObjColl.Add(New Circle(plPath.GetPointAtParameter(i), vec, (Dia / 2)))
Dim circleregion As New DBObjectCollection()
circleregion = Region.CreateFromCurves(acDBObjColl)
plnsrf.CreateFromRegion(circleregion(0))
srf.CopyFrom(plnsrf)
srf = TryCast(srf, Autodesk.AutoCAD.DatabaseServices.Surface)
btr.AppendEntity(srf)
trx.AddNewlyCreatedDBObject(srf, True)
End If
If plPath.GetSegmentType(i - 1) = SegmentType.Arc Then
vec = plPath.GetPointAtParameter(i).GetVectorTo(plPath.GetPointAtParameter(i + 1))
Dim acDBObjColl As New DBObjectCollection()
acDBObjColl.Add(New Circle(plPath.GetPointAtParameter(i), vec, (Dia / 2)))
Dim circleregion As New DBObjectCollection()
circleregion = Region.CreateFromCurves(acDBObjColl)
plnsrf.CreateFromRegion(circleregion(0))
srf.CopyFrom(plnsrf)
srf = TryCast(srf, Autodesk.AutoCAD.DatabaseServices.Surface)
btr.AppendEntity(srf)
trx.AddNewlyCreatedDBObject(srf, True)
End If
For Each sol In solids
Try
'Dim newSolid = sol.Slice(srf, True) 'Slicing with surface crashes AutoCAD
'sol.Slice(srf, True).Dispose() 'Slicing with surface crashes AutoCAD
Dim newSolid = sol.Slice(srf.GetPlane, True) 'Slicing with plane works, but no solution to my problem
'sol.Slice(srf.GetPlane, True).Dispose()
btr.AppendEntity(newSolid)
trx.AddNewlyCreatedDBObject(newSolid, True)
tempList.Add(newSolid)
Catch
ed.WriteMessage(vbLf & "Failed to slice.")
End Try
Next
solids.AddRange(tempList)
Next
trx.Commit()
End Using
End Sub
In the last part (The for next loop) I have commented out some of the options to play around.
This code makes a solid pipe with (diameter 100). At this stage I only want to deal with arcsegments in the polyline.
See below for a screenshot of a polyline I'm using.
