I am trying to write an algorithm (subroutine) to determine if a plane intersects a solid. I have prepared the code below which measures the minimum distance between each solid face to the plane, and it works, but it is very slow, especially as parts get larger and more complex.
Does anyone have an idea for a faster solution?
Thanks in advance
Sub Main()
Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim Solid1 As SurfaceBody = oCompDef.SurfaceBodies(1)
Dim Plane As WorkPlane = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select Plane")
MessageBox.Show(PlaneIntersectSolid(Solid1,Plane),"Does Plane intersect solid 1?")
End Sub
Function PlaneIntersectSolid(Solid1 As SurfaceBody, Plane As WorkPlane) As Boolean
For Each oFace As Face In Solid1.Faces
If ThisApplication.MeasureTools.GetMinimumDistance(Plane, oFace) = 0 Then
PlaneIntersectSolid = True
Exit Function
End If
Next
PlaneIntersectSolid = False
End Function
Solved! Go to Solution.
Solved by artemglushchenko21. Go to Solution.
Solved by artemglushchenko21. Go to Solution.
Can you provide some performance counters?
Faces count:
Vertices count:
Measured time:
Hi @aelqabbany,
try this approach (this is the Ilogic version):
Sub Main() Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition Dim Solid1 As SurfaceBody = oCompDef.SurfaceBodies(1) Dim workPlane As WorkPlane = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select Plane") Dim context As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap context.Add(IntersectionFound,true) Dim contextValueForIntersection As Double contextValueForIntersection = ThisApplication.MeasureTools.GetMinimumDistance(Solid1, workPlane.Plane, , , context) If (contextValueForIntersection = 0) Then MessageBox.Show("Intersection is found") Else MessageBox.Show("No intersection") End If End Sub
Check out my Add-Ins: Place Fasteners AddIn Quick Section View AddIn
😀
Wow, just wow.
I ran my script and yours in a part with 319 faces.
My script took 3.97 seconds and yours took less than 0.01 seconds.
Could you explain to me how you used the NameValueMap type to get the measurements so quickly? Did Inventor still have to take 319 distance measurements?
Thanks
I think some more optimal algorithms are used for measurements in this case (maybe not even actual distance measurments to the faces)
Using the NameValueMap is simple. You create an object and pass as an argument to MeasureTools.GetMinimumDistance method.
Please check Inventor Api for this method:
https://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-240D2F92-2701-4D9D-BCE7-02759538E2FC
Here is a good article as well:
https://adndevblog.typepad.com/manufacturing/2014/01/vector-of-minimum-distance.html
I find it very interesting that this code is working without throwing any errors, because according to the online help page for that method, a SurfaceBody object is not listed as a valid type of input entity. It certainly is nice that it is working here though.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.