- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I suspect the solution to my problem is pretty simple, but I'll probably get pretty heavy on the explanation of what I am doing, hopefully to alleviate any confusion.
This code was originally a VBA macro, but due to its terrible x64 performance, I have been transitioning it to VB.NET. I have tried to keep it as close to the VBA code as possible, until I can get it to produce the same results as the VBA source.
In the meantime, the code seems to function correctly, however, when I select larger object sets (the maximum number is not consistent), I get an eGeneralModelingFailure from VB.NET and "The Boolean operation on solid/or surface bodies failed. Modeling Operation Error: Access Violation" in the AutoCAD commandline.
My code is shown, but I have pared it down to what I think are the essential concepts. The error is occuring in the IdentifyObject Sub, when I set sRegion1 to a section using SectionPlane. I am not interested in keeping the results of sRegion1 or the XPlode array once I've made them, hence I don't add them to the database or anything. I am concerned that maybe I should be disposing them or clearing them somehow. Any ideas or advice would be appreciated. Thanks!
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports System.Windows.Forms
Imports System.Security.Permissions
Imports System.Security
Imports System.IO
Public Class FLACSmcrWriter
<CommandMethod("A2F")> _
Public Sub AutoCAD2FLACS()
Dim ObjectArray() As ObjectId 'Solid3d
'Got user selected 3dsolids via filter and put all ObjectIDs into ObjectArray
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
For I = 0 To UBound(ObjectArray)
objFlacs = New FLACSObject 'a custom object
ProcessObject(acTrans.GetObject(ObjectArray(I), OpenMode.ForWrite), objFlacs)
Next I
End Using
'Writing some stuff out to text files
End Sub
Private Sub ProcessObject(ByVal obj As Solid3d, ByRef objFlacs As FLACSObject)
'Minor custom object setup
'Determine object shape, orientation, and properties
Call IdentifyObject(obj, Direction, Length, Radius, Width, Height, minP)
'Some other stuff
End Sub
Private Sub IdentifyObject(ByRef obj As Solid3d, ByRef Direction As String, ByRef Length As Double, ByRef Radius As Double, ByRef Width As Double, ByRef Height As Double, ByRef minP As Point3d)
Dim maxP As Point3d
Dim pnt1 As Point3d
Dim sRegion1 As Region
Dim xPlode As DBObjectCollection = New DBObjectCollection
Dim xCount As Long
Dim eye As Long
rCount = 0
xObj = 0
pnt1 = ChangePoint(minP, minP, minP)
minP = obj.GeometricExtents.MinPoint
maxP = obj.GeometricExtents.MaxPoint
Dim SectionPlane As Plane = New Plane(pnt1, pnt2, maxP)
sRegion1 = obj.GetSection(SectionPlane)
If Not sRegion1 Is Nothing Then
sRegion1.Explode(xPlode)
xCount = xPlode.Count - 1
For eye = 0 To xCount
If TypeOf xPlode.Item(eye) Is Ellipse Or TypeOf xPlode.Item(eye) Is Circle Then
xObj = 1
End If
Next eye
Else
Exit Sub
End If
xPlode.Clear()
'Lots of other similar tests ...
End Sub
End Class
Solved! Go to Solution.