Create custom iProperty for subcomponents & subassemblies from within parent assembly

Create custom iProperty for subcomponents & subassemblies from within parent assembly

iogurt1
Advocate Advocate
345 Views
2 Replies
Message 1 of 3

Create custom iProperty for subcomponents & subassemblies from within parent assembly

iogurt1
Advocate
Advocate

Hey everyone. Our goal is to create a new iProperty called "TEST" in just the first level of children of an assembly. With this code, it does what we want, but it goes all the way down, if there are subassemblies with parts in them. Is it possible to only run this on the top level items? Thanks!

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all Of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 
			
		If iProperties.Value(oOccurrence.Name, "Status", "Status") = ""
	    iProperties.Value(oOccurrence.Name, "Custom", "TEST") = iProperties.Value(oOccurrence.Name, "Project", "Part Number") & iProperties.Value(oOccurrence.Name, "Project", "Revision Number")
	    Else
	    iProperties.Value(oOccurrence.Name, "Custom", "TEST") = iProperties.Value(oOccurrence.Name, "Project", "Part Number") & iProperties.Value(oOccurrence.Name, "Project", "Revision Number") & "_P" & iProperties.Value(oOccurrence.Name, "Status", "Status")
	    End If  

Next

'auf .iam Ebene
		If iProperties.Value("Status", "Status") = ""
	    iProperties.Value("Custom", "TEST") = iProperties.Value("Project", "Part Number") & iProperties.Value("Project", "Revision Number")
	    Else
	    iProperties.Value("Custom", "TEST") = iProperties.Value("Project", "Part Number") & iProperties.Value("Project", "Revision Number") & "_P" & iProperties.Value("Status", "Status")
	    End If  

 

0 Likes
Accepted solutions (1)
346 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

you can try this:

Dim doc As AssemblyDocument = ThisDoc.Document

For Each oOccurrence As ComponentOccurrence In doc.ComponentDefinition.Occurrences

    If iProperties.Value(oOccurrence.Name, "Status", "Status") = "" Then
        iProperties.Value(oOccurrence.Name, "Custom", "TEST") = iProperties.Value(oOccurrence.Name, "Project", "Part Number") & iProperties.Value(oOccurrence.Name, "Project", "Revision Number")
    Else
        iProperties.Value(oOccurrence.Name, "Custom", "TEST") = iProperties.Value(oOccurrence.Name, "Project", "Part Number") & iProperties.Value(oOccurrence.Name, "Project", "Revision Number") & "_P" & iProperties.Value(oOccurrence.Name, "Status", "Status")
    End If

Next

'auf .iam Ebene
If iProperties.Value("Status", "Status") = "" Then
    iProperties.Value("Custom", "TEST") = iProperties.Value("Project", "Part Number") & iProperties.Value("Project", "Revision Number")
Else
    iProperties.Value("Custom", "TEST") = iProperties.Value("Project", "Part Number") & iProperties.Value("Project", "Revision Number") & "_P" & iProperties.Value("Status", "Status")
End If

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

iogurt1
Advocate
Advocate

Thanks @JelteDeJong, works perfectly now!

0 Likes