Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

Ilogic to use part of filename to populate iProperty

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
aurel_e
168 Views, 2 Replies

Ilogic to use part of filename to populate iProperty

Hi all,

 

I need to add to all the components (parts and subassies) of an assembly an iproperty that is an extract of the filename

I tried the code below but is working just for the parts not the subassies.

 

Sub Main
	On Error Resume Next
	Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
	Dim oLeafOccs As ComponentOccurrencesEnumerator = oAsmDef.Occurrences.AllLeafOccurrences
	'when you turn this on, you should also turn it back off when done
	ThisApplication.SilentOperation = True

	
	Dim oOcc As ComponentOccurrence
	For Each oOcc In oLeafOccs
		
		
		iProperties.Value(oOcc.Name, "Custom", "PN5") =(Mid(oOcc.Name, 11, 3))
	Next
End Sub
2 REPLIES 2
Message 2 of 3
FINET_Laurent
in reply to: aurel_e

Hello @aurel_e,

 

The issue you are facing is that the AllLeafOccurrences collection contains each single part of the assembly. 

To perform the desired task, you will need a recursive function that will go through each occurrences, & sub-occurences if present, thus englobing also the assemblies. Here a code with no error handling :

Sub Main
	On Error Resume Next
	Dim doc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim acd As AssemblyComponentDefinition = doc.ComponentDefinition
	
	addProperty(acd.Occurrences)
	
End Sub

Sub addProperty(occs As Inventor.ComponentOccurrences) 'recursive
	For Each occ As Inventor.ComponentOccurrence In occs
		iProperties.Value(occ.Name, "Custom", "PN5") = (Mid(occ.Name, 11, 3))		
		
		If occ.SubOccurrences.Count > 0 Then addProperty(occ.SubOccurrences)
				
	Next
End Sub

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 3
aurel_e
in reply to: FINET_Laurent

Perfect. I had to add that 

On Error Resume Next

  on the 2nd part of the code to make it work.

 

Many thanks.

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

Post to forums  

Autodesk Design & Make Report