Message 1 of 7

Not applicable
05-16-2015
03:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
I need to iterate through the user selected cut lines and for every cutline, identify the solids crossing and slice them to that line. Below the code is working for single line selection. But for multiple lines selection, in the second iteration, getting the error.
Any help would be greatly appreciated.
Image: User Selecting Lines & Solids to Identify
Code:
Public Sub SliceSolid() Dim Doc As Document = Application.DocumentManager.MdiActiveDocument Dim DB As Database = Doc.Database Dim Ed As Editor = Doc.Editor Try Using Tr As Transaction = DB.TransactionManager.StartTransaction Dim BT As BlockTable = Tr.GetObject(DB.BlockTableId, OpenMode.ForRead) Dim BTR As BlockTableRecord = Tr.GetObject(BT(BlockTableRecord.ModelSpace), OpenMode.ForWrite) Dim SObjPrRes As PromptSelectionResult = Ed.GetSelection If SObjPrRes.Status = PromptStatus.OK Then Dim SSet As SelectionSet = SObjPrRes.Value For Each Obj As SelectedObject In SSet Dim Ent As Entity = Tr.GetObject(Obj.ObjectId, OpenMode.ForRead) If Obj.ObjectId.ObjectClass.DxfName = "LINE" Then Dim L As Line : L = Ent Dim PT1 As Point3d = L.StartPoint : Dim PT2 As Point3d = L.EndPoint Ed.WriteMessage(vbLf & "Line Start : " & L.StartPoint.ToString & " - Line End :" & L.EndPoint.ToString) Dim CrossSelection As SelectionSet = SelectObjectsByCrossingWindow(L.StartPoint, L.EndPoint) 'PrintSelectionSetObjectIds(CrossSelection) 'SliceSolidsByPoints(CrossSelection, L.StartPoint, L.EndPoint) Using Tr2 As Transaction = DB.TransactionManager.StartTransaction For Each Obj2 As SelectedObject In CrossSelection If Obj2.ObjectId.ObjectClass.DxfName = "3DSOLID" Then Dim Sol3D As Solid3d = Tr2.GetObject(Obj2.ObjectId, OpenMode.ForWrite) Dim Pt3 As Point3d = New Point3d(PT1.X, PT1.Y, PT1.Z) Dim Pt4 As Point3d = New Point3d(PT1.X, PT1.Y, PT1.Z + 10) Dim Pt5 As Point3d = New Point3d(PT2.X, PT2.Y, PT1.Z + 10) Dim acPlane As Plane = New Plane(Pt3, Pt4, Pt5) Dim Sol3DSlice As Solid3d = Sol3D.Slice(acPlane, True) BTR.AppendEntity(Sol3DSlice) Tr2.AddNewlyCreatedDBObject(Sol3DSlice, True) Ed.WriteMessage(vbLf & "New Solid Created: " & Sol3DSlice.ObjectId.ToString()) End If Next Tr2.Commit() End Using End If Next End If Tr.Commit() End Using Catch ex As Exception MsgBox(ex.ToString, , "Sub - " & System.Reflection.MethodBase.GetCurrentMethod.Name) Clipboard.SetText(ex.ToString) End Try End Sub
Error:
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Autodesk.AutoCAD.Runtime.DisposableWrapper.Attach(IntPtr unmanagedPointer, Boolean autoDelete)
at Autodesk.AutoCAD.DatabaseServices.Solid3d.Slice(Plane plane, Boolean negativeHalfToo)
at ClassLibrary1.SliceSolids.SliceSolid()
Solved! Go to Solution.