INVENTOR API: How to check the Interference Between a Part and Body in Part

INVENTOR API: How to check the Interference Between a Part and Body in Part

Khoa_NguyenDang
Advocate Advocate
1,644 Views
4 Replies
Message 1 of 5

INVENTOR API: How to check the Interference Between a Part and Body in Part

Khoa_NguyenDang
Advocate
Advocate

Hi all, hope someone can help me in this problem 

I have an assembly file with 2 Part: A and B 

In Part A: Just have 1 body solid 

In Part B: Have more than 1 body solid (6 bodies) 

If in the Assembly Environment, I use Analyze Interference, it can check the interference for all body solid in Part B with Part A. And all this interference will be listed in the table 

OneCAD_Vietnam_0-1593263250588.png

So how i can code to access each one interference in that table.

At this time, i just know use InterferenceResult to check between 2 Part

Hope some one can help me, Thank you so much all guys !!!!!!

0 Likes
Accepted solutions (2)
1,645 Views
4 Replies
Replies (4)
Message 2 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Khoa_NguyenDang 

As far as I can tell there is no out of the box functionality to check which solid of "part 2" is interfering with "part 1".

The list in your sceenshot doesn't provide that information neither. In your screenshot the second part occurrence is called "Solid2:1" so it's not returning an internal solids name, just the name of the part occurrence.

 

If you want a list like this however you can get it. All that information is returned as InterferenceResults. See iLogic code below.

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oOcc1 As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "pick part 1") 'Pick first part
Dim oOcc2 As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "pick part 2") 'Pick second part
Dim oCheck As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oCheck.Add(oOcc1)
oCheck.Add(oOcc2)
Dim oResults As InterferenceResults = oAsm.ComponentDefinition.AnalyzeInterference(oCheck)
Dim oResultString As String
For Each oResult As InterferenceResult In oResults
	oResultString = oResultString & "Part 1: " & oResult.OccurrenceOne.Name & " - Part 2: " _
	& oResult.OccurrenceTwo.Name & " - Volume: " & oResult.Volume & vbCrLf
Next
MessageBox.Show(oResultString, "Interference results")

 

Message 3 of 5

Khoa_NguyenDang
Advocate
Advocate

Hi @JhoelForshav 

Thank you so much for your reply.  It works

Actually, I not really want to show the box like the picture 

I want to get the Solids name of Part in the InterferenceResult 

I can access to the OccurenceOne and OccurenceTwo of each InterferenceResult of InterferenceResults 

For example I want to get the exactly Solid in the Part which in the InterferenceResult. It is available to do it ?

 

0 Likes
Message 4 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Khoa_NguyenDang 

As I said, I don't think there's any "out of the box" function for this. However I think something like this might work 🙂

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oOcc1 As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "pick part 1") 'Pick first part
Dim oOcc2 As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Pick multibody part") 'Pick second part
Dim oCheck As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oCheck.Add(oOcc1)
oCheck.Add(oOcc2)
Dim oResults As InterferenceResults = oAsm.ComponentDefinition.AnalyzeInterference(oCheck)
Dim oResultString As String
Dim oDef1 As PartComponentDefinition = oOcc1.Definition
Dim oDef2 As PartComponentDefinition = oOcc2.Definition
For Each oResult As InterferenceResult In oResults
	Dim oPoint1 As Point = oResult.Centroid.Copy
	Dim oPoint2 As Point = oResult.Centroid.Copy
	Dim oMatrix1 As Matrix = oOcc1.Transformation
	oMatrix1.Invert
	oPoint1.TransformBy(oMatrix1)
	Dim oMatrix2 As Matrix = oOcc2.Transformation
	oMatrix2.Invert
	oPoint2.TransformBy(oMatrix2)
	Dim oPointArr1(2) As Double
	oPointArr1(0) = oPoint1.X
	oPointArr1(1) = oPoint1.Y
	oPointArr1(2) = oPoint1.Z

	Dim oPointArr2(2) As Double
	oPointArr2(0) = oPoint2.X
	oPointArr2(1) = oPoint2.Y
	oPointArr2(2) = oPoint2.Z

	Dim oSolid1 As String = ""
	Dim oSolid2 As String = ""

	For Each oSolid As SurfaceBody In oDef1.SurfaceBodies
		If oSolid.IsPointInside(oPointArr1) = ContainmentEnum.kInsideContainment Then oSolid1 = oSolid.Name
	Next
	For Each oSolid As SurfaceBody In oDef2.SurfaceBodies
		If oSolid.IsPointInside(oPointArr2) = ContainmentEnum.kInsideContainment Then oSolid2 = oSolid.Name
	Next
	If oSolid1 <> "" AndAlso oSolid2 <> ""
		oResultString = oResultString & oSolid1 & " in " & oOcc1.Name & " intersects with " & oSolid2 & " in " & oOcc2.Name & vbCrLf
	End If
Next
MessageBox.Show(oResultString, "Intersections")
Message 5 of 5

Khoa_NguyenDang
Advocate
Advocate

Hi @JhoelForshav 

Thank you for your code so much. I will try it. I hope it works for my project.