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: 

SubAssembly part access question

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
drfleau
523 Views, 2 Replies

SubAssembly part access question

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

2D or not 2D. There is no question!
We are born cold, naked and hungry. Then things get worse.
2 REPLIES 2
Message 2 of 3
MechMachineMan
in reply to: drfleau

http://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 3
drfleau
in reply to: MechMachineMan

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.

 

 

 

2D or not 2D. There is no question!
We are born cold, naked and hungry. Then things get worse.

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

Post to forums  

Autodesk Design & Make Report