Hi gang,
I just learned how to use global variables in a Main/Private sub situation. Now I need to know how to "transpose" function arguments from the Main to the Sub function. In the following iLogic, the "Call Iteration(...)" uses some arguments in the Main sub <oAsmDoc.ComponentDefinition.Occurrences, 1> and I don't know what they mean.
The Private Sub re-uses that information in a different way <Occurrences as ComponentOccurrences, Niveau As Integer>, apparently defining the Occurrences as an argument and defining the Niveau variable in there as well.
What I want to do is use a For Each AllReferencedDocuments function to access each part only once, and not use Occurrences that revisits all identical parts in the assembly.
Can someone show me how to achieve this, and explain how to use those arguments?
Thank you.
Here is the code, shortened
*********
Class This rule
(Some global variables)
Main Sub(...)
....(Some stuff)
Call Iteration(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub
Private Sub Iteration(Occurrences as ComponentOccurrences, Level As Integer)
'look at the files referenced by the assembly
Dim oRefDoc As ComponentOccurrence
For Each oRefDoc In Occurrences
(Access each part and do stuff)
'If the Component it finds is an assembly, continue digging
If oRefDoc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call Iteration(oRefDoc.SubOccurrences, Level + 1)
End Sub
End Class
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Your web page suggestion was helpful, thank you. I did have to do a lot of trial and error to find out how to pass arguments from Main sub to Private sub, although in the context I was in, I did not need any arguments!
Here is my new code, still incomplete, but much more advanced:
SyntaxEditor Code Snippet
Class ThisRule Dim oAsmDoc As Inventor.Document Dim ChoixListe As String Sub Main() 'define the active document as an assembly file Dim oRefDoc As Inventor.Document oAsmDoc = ThisApplication.ActiveDocument 'check that the active document is an assembly file If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("SVP activer cette fonction dans un assemblage.", "Erreur 18") Exit Sub End If
'---No Arguments Call oChoix() End Sub
'---Ain't nobody got time for Arguments!
'---I know I could have incorporated this into the Main Sub
'---I'll add in some stuff later Private Sub oChoix() Dim StatAct As String Dim ChoixStat As New ArrayList ChoixStat.add("Disponible") ChoixStat.add("Pour Approbation") ChoixStat.add("Pour Fabrication") ChoixListe=InputListBox("Choisir quel statut vous voulez voir", ChoixStat, "", Title := "Personne ne lit ici", ListName := "Choisir :")
'---See? No Arguments! Call Iter() End Sub
'---Still No Arguments! This made me want to scream! Private Sub Iter() Dim ChoixNum as Integer If ChoixListe = "Disponible" Then ChoixNum = 1 ElseIf ChoixListe = "Pour Approbation" Then ChoixNum = 2 ElseIf ChoixListe = "Pour Fabrication" Then ChoixNum = 3 Else End If Dim Liste As New ArrayList 'look at the files referenced by the assembly For Each oRefDoc In oAsmDoc.AllReferencedDocuments If iProperties.Value(oRefDoc.DisplayName, "Status", "Design State")=ChoixNum Then Liste.Add((iProperties.Value(oRefDoc.DisplayName, "Summary", "Title")) & " - " & (iProperties.Value(oRefDoc.DisplayName, "Project", "Part number"))) Else End If Next ChoixListe=InputListBox("Statut demand�: " & ChoixListe, Liste, "Pour Approbation", Title := "Personne ne lit ici", ListName := "Statuts") End Sub End Class
Basically I'm writing a routine that will identify parts and assemblies that are not "Released", move their PDF files so the Production department cannot print them (prevents from producing parts with not-up-to-date drawings). I can then set them as "Released" when I'm done, and the routine will produce the new drawings. I have most of the file-manipulation code elsewhere. Soon I'll have to marry the two, so wish me luck.