iLogic - rule process order

iLogic - rule process order

Anonymous
Not applicable
1,004 Views
3 Replies
Message 1 of 4

iLogic - rule process order

Anonymous
Not applicable

Hi All,

 

I have the following piece of code that is not running in the order I would like it to.

It should basically change all hole settings to 'Major', run 'Analyze Interference', then changed all hole settings back to 'Tap Drill'.

But it runs 'Analyze Interference' first then changes the hole settings, I don't understand why.

 

I'm not sure how Sub Main works, my guess is that I should be calling the hole setting pieces of the code as Sub's, is that correct?

 

Sub Main

' ********** References *********
' kThreadMajorDiameter 21761
' kThreadMinorDiameter 21762
' kThreadPitchDiameter 21763
' kThreadTapDrillDiameter 21764

' ********** Declarations 
iLogicVb.UpdateWhenDone = True
Dim partDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument) ' Set Variable if the Current Doc Type is Part
Dim assemDoc As AssemblyDocument = TryCast(ThisDoc.Document, AssemblyDocument) ' Set Variable if the Current Doc Type is Assembly

' ********** For a Component File
If (partDoc IsNot Nothing) Then ' If this is a part document
    partDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole Type
End If

' ********** For an Assembly File
If (assemDoc IsNot Nothing)Then ' If this is an Assembly document
    assemDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole in the Assembly File
    Dim docFile As Document ' Declare a Variable for each referenced document to loop thru
    i = 0
    For Each docFile In assemDoc.Allreferenceddocuments ' For all the documents referenced in the assembly
        If docFile.IsModifiable = True Then ' If the document is able to be modified
            Dim RefassemDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part
            Dim RefpartDoc As PartDocument = TryCast(docFile, PartDocument) ' Set Variable if the Current Doc Type is Assembly
            If (RefpartDoc IsNot Nothing) Then ' If this Doc is a Part
                
                RefpartDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole Type
            Else ' This Doc must be an assembly
                Dim RefAsmDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part
                Try
                RefAsmDoc.ModelingSettings.TappedHoleDiameter = 21761 ' Set the Tapped Hole Type
                Catch
                End Try
            End If
        End If
    Next
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
Dim iCount As Integer
iCount = 0
volume = InputBox("Set the minimum volume value (cm^3) to be excluded from the results", "Volume Threshold", "0.1")

For Each oResult In oResults
    If oResult.Volume > volume Then
        iCount = iCount + 1
    End If
Next
' Display the results of the interference.
MessageBox.Show(iCount & " Interferences found ","iLogic")

iCount = 0
For Each oResult In oResults
    If oResult.Volume > volume Then
        iCount = iCount + 1
        oResult.OccurrenceOne.SetRenderStyle(100609,oAsmDoc.RenderStyles.Item("Yellow"))
        oResult.OccurrenceTwo.SetRenderStyle(100609,oAsmDoc.RenderStyles.Item("Magenta"))
        
        MessageBox.Show("     " & FullOccurrenceName(oResult.OccurrenceOne) & "      (colored yellow)" _
        & vbLf & "interferes with " _
        & vbLf & "     " & FullOccurrenceName(oResult.OccurrenceTwo) & "      (colored magenta)" _
        & vbLf & "" _
        & vbLf & "Volume: " & Round(oResult.Volume,5) & " cm^3", _
        " Interference "& iCount)
        
        oResult.OccurrenceOne.AppearanceSourceType = 100612 'kPartAppearance
        oResult.OccurrenceTwo.AppearanceSourceType = 100612 'kPartAppearance
'        
    End If
Next

' ********** Declarations 
iLogicVb.UpdateWhenDone = True

' ********** For a Component File
If (partDoc IsNot Nothing) Then ' If this is a part document
    partDoc.ModelingSettings.TappedHoleDiameter = 21764 ' Set the Tapped Hole Type
End If

' ********** For an Assembly File
If (assemDoc IsNot Nothing)Then ' If this is an Assembly document
    assemDoc.ModelingSettings.TappedHoleDiameter = 21764 ' Set the Tapped Hole in the Assembly File
    Dim docFile As Document ' Declare a Variable for each referenced document to loop thru
    i = 0
    For Each docFile In assemDoc.Allreferenceddocuments ' For all the documents referenced in the assembly
        If docFile.IsModifiable = True Then ' If the document is able to be modified
            Dim RefassemDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part
            Dim RefpartDoc As PartDocument = TryCast(docFile, PartDocument) ' Set Variable if the Current Doc Type is Assembly
            If (RefpartDoc IsNot Nothing) Then ' If this Doc is a Part
                
                RefpartDoc.ModelingSettings.TappedHoleDiameter = 21764 ' Set the Tapped Hole Type
            Else ' This Doc must be an assembly
                Dim RefAsmDoc As AssemblyDocument = TryCast(docFile, AssemblyDocument) ' Set Variable if the Current Doc Type is Part
                Try
                RefAsmDoc.ModelingSettings.TappedHoleDiameter = 21764 ' Set the Tapped Hole Type
                Catch
                End Try
            End If
        End If
    Next
End If

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
Accepted solutions (1)
1,005 Views
3 Replies
Replies (3)
Message 2 of 4

NSBowser
Advocate
Advocate
Accepted solution

It appears that the code is operating in the correct order as you have described.

 

The setting of .TappedHoleDiameter = 21761 which appears in the first few blocks would be setting the holes to the Major Diameter.

All this occurs prior to the Analyze interference is run.

 

The only thing I can think, is that the change to the TappedHoleDiameter is not physically affecting the model before the Interference check runs.

Try adding a 'Document Update' after setting the Major diameters but before the interference checks.

 

Example:

oAsmDoc.Update2(True)

 


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
0 Likes
Message 3 of 4

Anonymous
Not applicable

Genius! Document update did the trick Smiley Happy

0 Likes
Message 4 of 4

NSBowser
Advocate
Advocate

Good, I'm glad the solution worked for you.

 

Please consider using the 'Mark as Solution' feature so that your post indicates it was solved and so future users with similar issues can quickly find the answers they need.


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
0 Likes