Sort Interference Results using iLogic

Sort Interference Results using iLogic

Anonymous
Not applicable
437 Views
0 Replies
Message 1 of 1

Sort Interference Results using iLogic

Anonymous
Not applicable

Hello,

 

This is my first post in the forum, and I'm certainly not a programmer so please bear with me.

 

I have an iLogic rule that I've created that will go through the interference results and count and display them individually, but they just appear in whatever order Inventor decides. I would like to sort interference results by volume and then display them in order of largest volumes first. I'm only concerned with keeping the OccurrenceOne , OccurrenceTwo , and Volume properties together.  I've attempted to use an ArrayList to no avail.

 

The code I have is posted below.

 

Any help would be appreciated.

 

Sub Main

'check this file is an assembly
Dim doc As Document = ThisApplication.ActiveDocument
If doc.DocumentType = kPartDocumentObject Then
MessageBox.Show("This rule can only be run in an assembly file!", "ERROR")
Return
End If  

Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oAsmDoc.ComponentDefinition

' Add each occurrence in the assembly to the object collection.
Dim oCheckSet As ObjectCollection
oCheckSet= ThisApplication.TransientObjects.CreateObjectCollection
Dim oOcc As ComponentOccurrence
For Each oOcc In oAsmCompDef.Occurrences
     oCheckSet.Add (oOcc)
Next

' Call the AnalyzeInterference method, passing in a single' collection. This will cause it to compare everything against' everything else.

Dim oResults As InterferenceResults
oResults = oAsmCompDef.AnalyzeInterference(oCheckSet)
Dim oResult As InterferenceResult
'''''''''''''''''''''''''''''
'FILTERING GOES HERE

'''''''''''''''''''''''''''''
'Count and display number of interferences.

Dim Result_Count As Integer
Result_Count = 0


For Each oResult In oResults
    
Result_Count = Result_Count + 1
    
Next
' Display the results of the interference.
MessageBox.Show(Result_Count & " Interferences found ","iLogic")

 'Iterate through And display Each interference individually

Dim answer As String
Dim oIntBody As SurfaceBody
Dim oBody As SurfaceBody
Dim oSurfaceGraphics As SurfaceGraphics
Dim oClientGraphics As ClientGraphics
Dim oSurfacesNode As GraphicsNode
iCount = 0
Dim x As Integer 
x=1
For Each oResult In oResults
        iCount = iCount + 1
        
        oResult.OccurrenceOne.SetRenderStyle(100609,oAsmDoc.RenderStyles.Item("Yellow"))
        oResult.OccurrenceTwo.SetRenderStyle(100609,oAsmDoc.RenderStyles.Item("Cyan"))
        
'''''''''''''''''''''''''''''
        'Create temporary surface for displaying interfering body
            ' Create the ClientGraphics object.
            oClientGraphics = oAsmCompDef.ClientGraphicsCollection.Add("Sample3DGraphicsID")
    
            ' Create a new graphics node within the client graphics objects
            oSurfacesNode = oClientGraphics.AddNode(1)
    
            oIntBody = oResults.Item(iCount).InterferenceBody
        
            oBody = oIntBody
        
            ' Create client graphics based on the transient body
            oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oBody)
            oSurfacesNode.RenderStyle = oAsmDoc.RenderStyles.Item("Red")
            oSurfaceGraphics.BurnThrough=True
            ' Update the view to see the resulting curves
            ThisApplication.ActiveView.Update    
    
'''''''''''''''''''''''''''''
    'Display Interference Result
        answer = MessageBox.Show("     " & FullOccurrenceName(oResult.OccurrenceOne) & "      (Colored Yellow)" _
        & vbLf & "interferes with " _
        & vbLf & "     " & FullOccurrenceName(oResult.OccurrenceTwo) & "      (Colored Cyan)" _
        & vbLf & "" _
        & vbLf & " Interference (Colored Red)" _
        & vbLf & "Volume: " & Round(oResult.Volume/16.3871,5) & " in^3", _
        " Interference "& iCount & " of "& Result_Count,MessageBoxButtons.OKCancel)
        
        oResult.OccurrenceOne.AppearanceSourceType = 100612 'kPartAppearance
        oResult.OccurrenceTwo.AppearanceSourceType = 100612 'kPartAppearance
        oClientGraphics.Delete
        
    'When user clicks cancel
    If answer= 2 Then 
            'Color Return to Normal
             For Each oOcc In oAsmDoc.ComponentDefinition.Occurrences 
                ' Set each occurrence to use the part defined color. 
              oOcc.SetRenderStyle(StyleSourceTypeEnum.kPartRenderStyle)
            Next 

    Return 

End If

Next

'Color Return to Normal
For Each oOcc In oAsmDoc.ComponentDefinition.Occurrences 
 ' Set each occurrence to use the part defined color. 
  oOcc.SetRenderStyle(StyleSourceTypeEnum.kPartRenderStyle)
Next

End Sub

' Used to display the full path of an occurrence. This is the path of the' occurrence within the assembly structure.
Private Function FullOccurrenceName(Occ As ComponentOccurrence) As String
Dim i As Integer
For i = 1 To Occ.OccurrencePath.Count
If i = 1 Then
FullOccurrenceName = Occ.OccurrencePath.Item(i).Name
Else
FullOccurrenceName = FullOccurrenceName & "\" & Occ.OccurrencePath.Item(i).Name
End If
Next
End Function

 

0 Likes
438 Views
0 Replies
Replies (0)