Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So this code to run a rule in certain parts in a assembly works perfectly when the open part document boolean is True.
Dim oDoc As PartDocument = ThisApplication.Documents.Open(oFileName, True)
Its kind of annoying on large assemblies to have to watch every part be opened and closed.
Is there a reason why the code wont run my rule when the boolean is false or is inventor just not able to run the external rule if the part is not opened visually and I just have to deal with it?
Thanks
Private Sub Main()
Dim asmDoc As AssemblyDocument
asmDoc = ThisApplication.ActiveDocument
' Call the function that traverses the assembly
Call Iterate(asmDoc.ComponentDefinition.Occurrences,1)
' Update the view.
ThisApplication.ActiveView.Update
End Sub
Sub Iterate(Occurrences As ComponentOccurrences, Level As Integer)
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oPart As ComponentOccurrence
'set rules to be ran
Dim sRuleName As String = "BASE_QTY_CHANGE_RULE 1"
'''Iterate through part occurrences in assembly
For Each oPart In Occurrences
Dim oFileName As String = oPart.Definition.Document.FullFileName
'Check to see if occurance is a Part
If oPart.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
'Set part type to be changed.
If oPart.Name.Contains("STR.") Then
'Open Part document True opens visually.
Dim oDoc As PartDocument = ThisApplication.Documents.Open(oFileName, True)
auto = iLogicVb.Automation
Try
'run desired rule
auto.RunExternalRule(oDoc, sRuleName)
Catch
MessageBox.Show("Cannot find a rule with the name " & sRuleName & "." & vbLf & "Please try again.", "Open and run")
End Try
'''Close the document with SAVE (as False), without SAVE (As True)
oDoc.Close(False)
End If
'recursively call sub to traverse through occurance if it is a subassembly
ElseIf oPart.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Call Iterate(oPart.SubOccurrences, Level)
End If
Next
End Sub
Solved! Go to Solution.