Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Create custom iProperty for subcomponents & subassemblies from within parent assembly

iogurt1
Advocate

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
Reply
Accepted solutions (1)
292 Views
2 Replies
Replies (2)

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

iogurt1
Advocate
Advocate

Thanks @JelteDeJong, works perfectly now!

0 Likes