Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Analyze interference run time error

0 REPLIES 0
Reply
Message 1 of 1
m_klibi
105 Views, 0 Replies

Analyze interference run time error

I have a code to analyze interference here is the important part of my code

Public Sub MoveAllToBoundingBoxTest()
Dim oApp As Application
Set oApp = ThisApplication

Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = oApp.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = oAsmDoc.ComponentDefinition

Dim oTG As TransientGeometry
Set oTG = oApp.TransientGeometry

Dim constraints As AssemblyConstraints
Set constraints = oAsmCompDef.constraints

Dim i As Integer
For i = constraints.Count To 1 Step -1
constraints.Item(i).Delete
Next i

Dim l As Integer
l = oAsmCompDef.Occurrences.Count

' Initialize the interference matrices with -1 (unprocessed)


Dim interferenceMatrix() As Integer
Dim interferenceMatrixx() As Integer
Dim interferenceMatrixxx() As Integer
Dim interferenceMatrixNegX() As Integer
Dim interferenceMatrixNegY() As Integer
Dim interferenceMatrixNegZ() As Integer


ReDim interferenceMatrix(l, l)
ReDim interferenceMatrixx(l, l)
ReDim interferenceMatrixxx(l, l)
ReDim interferenceMatrixNegX(l, l)
ReDim interferenceMatrixNegY(l, l)
ReDim interferenceMatrixNegZ(l, l)

' Initialize an array to store occurrence names
Dim occurrenceNames() As String
ReDim occurrenceNames(l)
For i = 1 To l
occurrenceNames(i) = oAsmCompDef.Occurrences(i).Name
Next i


Dim oVector As Vector
Set oVector = oTG.CreateVector(0.00001, 0, 0)

' Loop through all occurrences for X-axis movement
For i = 1 To l
Set oOccurrence = oAsmCompDef.Occurrences(i)

' Store the original position of the current occurrence
Dim originalMatrix As Matrix
Set originalMatrix = oOccurrence.Transformation

' Apply the movement
Dim oMatrix As Matrix
Set oMatrix = oOccurrence.Transformation
oMatrix.Cell(1, 4) = oMatrix.Cell(1, 4) + oVector.X
oOccurrence.Transformation = oMatrix

' Check for interferences on X-axis
Dim oCheckSet As ObjectCollection
Set oCheckSet = oApp.TransientObjects.CreateObjectCollection
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmCompDef.Occurrences
oCheckSet.Add oOcc
Next oOcc

Dim oResults As InterferenceResults
Set oResults = oAsmCompDef.AnalyzeInterference(oCheckSet)

' Process the interference results on X-axis
Dim oResult As InterferenceResult
For Each oResult In oResults
Dim movingIDX As Integer, otherIDX As Integer
movingIDX = 0
otherIDX = 0
Dim movingNameX As String, otherNameX As String
movingNameX = oOccurrence.Name ' Name of the currently moving occurrence

' Determine the IDs for moving and other occurrences
For j = 1 To l
If occurrenceNames(j) = movingNameX Then
movingIDX = j
Debug.Print "Moving Occurrence: " & movingNameX & " mapped to ID: " & movingIDX
End If

If oResult.OccurrenceOne.Name = movingNameX Then
otherNameX = oResult.OccurrenceTwo.Name
Else
otherNameX = oResult.OccurrenceOne.Name
End If

If occurrenceNames(j) = otherNameX Then
otherIDX = j
End If
Next j

' Validate and record the interference
If movingIDX = 0 Or otherIDX = 0 Then
Debug.Print "Mapping error: one of the occurrences did not match."
Else
If movingIDX > 0 And otherIDX > 0 Then
interferenceMatrix(movingIDX, otherIDX) = 1
Debug.Print "Interference recorded between (moving) " & movingNameX & " and (stationary) " & otherNameX
End If
End If
Next oResult
oOccurrence.Transformation = originalMatrix
Next i
 the rest of the code moves the parts on other axes and check for interferences: The code works but with some assemblies i get the error message run time error method analyzeinterference of object assemblycomponentdefinition failed. My hypothesis is that the api has difficulty to read some interferences what do you think    ?

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report