updating properties of all parts within assembly

updating properties of all parts within assembly

alan.wedge
Enthusiast Enthusiast
2,423 Views
6 Replies
Message 1 of 7

updating properties of all parts within assembly

alan.wedge
Enthusiast
Enthusiast

Hi,

 

I am trying to write an ilogic script that will update specified properties of parts when the property is changed for the assembly.

 

I dont want to use custom properties as they dont do what i need for the next step, i would prefer to use some of the default properties.

0 Likes
Accepted solutions (1)
2,424 Views
6 Replies
Replies (6)
Message 2 of 7

Ralf_Krieg
Advisor
Advisor

Hello

 

Traverse the referenced documents of the assembly and run the update sub on every part document.

Add the rule to the "Property change" trigger of the assembly document.

 

Sub Main
	Dim oAssDoc As AssemblyDocument = ThisDoc.Document
	Dim oRefedDoc As Document
	For Each oRefedDoc In oAssDoc.AllReferencedDocuments
		If oRefedDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
			UpdateProps(oRefedDoc)
		End If
	Next
End Sub

Private Sub UpdateProps(ByVal oDoc As Inventor.Document)
	
	' ... your code for updating iProps
	' iProperties.Value("Project", "Part Number") = "somePartNumber"
	' iProperties.Value("Summary", "Title") = "someTitle"
	' iProperties.Value("Custom", "CustomPropertyName") = "someCustomValue"
	
End Sub

 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 7

el_jefe_de_steak
Collaborator
Collaborator

Actually the code provided by @Ralf_Krieg will only set the iProperty value of the parent assembly.

 

You have to use something like this instead:

 

Sub Main
	Dim oAssDoc As AssemblyDocument = ThisDoc.Document
	For Each oRefedDoc As Document In oAssDoc.AllReferencedDocuments
		If oRefedDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Or oRefedDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			UpdateProps(oRefedDoc)
		End If
	Next
End Sub

Private Sub UpdateProps(ByVal oDoc As Inventor.Document)
	
	oDoc.PropertySets("Design Tracking Properties")("Part Number").Value = iProperties.Value("Project", "Part Number")
	oDoc.PropertySets("Design Tracking Properties")("Description").Value = iProperties.Value("Project", "Description")
	oDoc.PropertySets("Document Summary Information")("Title").Value = iProperties.Value("Summary", "Title")
	
End Sub

 

 

 

There is a great blog post that explains how to access/set all of the specific iProperty values: https://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html 

 

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @alan.wedge.  Do you just want to monitor for when certain specific iProperties in your main assembly change, then copy the value of that changed iProperty down to all part documents in every lower level of the assembly?  Likely the most efficient way to do that would be to create a custom event handler code that is designed to only react to those specific property changes.  But if you want to keep it simple, we can use the "iProperty Change" event in the Event Triggers dialog and an iLogic rule, as @Ralf_Krieg suggested.  If you are going to be making tons of iProperty changes in your main assembly, but most of them are not the ones that need to be copied down, and this assembly is heavily used, I would suggest going the custom event handler route, to limit all that processing to a minimum, so it won't bog Inventor down, but otherwise the simpler route should be just fine.

 

Anyways, here is an alternate iLogic rule you may like to use for this process.  Within the first part of the rule is where you would specify the names of the iProperties you want to monitor for changes.  Then when the 'iProperty Change' event happens, this rule will run, then check to see if any of these specified properties have been 'dirtied' (changed since the file was opened or last saved).  If any of those properties have been 'dirtied' they will be copied down to every part document, in every level of the assembly.  Since that 'iProperty Change' event can be triggered by 'any' iProperty change, I'm thinking that by checking the 'Dirty' status, we might help reduce unnecessary processing.

Here is the code I wrote for a process like that:

Sub Main
	Dim oADoc As AssemblyDocument = ThisDoc.Document
	'specify which Assembly iProperties to monitor for changes
	'then when they change, their values will be pushed to the parts
	Dim oPropNames As New List(Of String)
	oPropNames.Add("Keywords") '<<<< CHANGE THIS AS NEEDED >>>>
	oPropNames.Add("Comments") '<<<< CHANGE THIS AS NEEDED >>>>
	oPropNames.Add("Category") '<<<< CHANGE THIS AS NEEDED >>>>
	oPropNames.Add("Project") '<<<< CHANGE THIS AS NEEDED >>>>
	
	'Dirty = created/edited/modified since open or last save
	For Each oSet As PropertySet In oADoc.PropertySets
		If Not oSet.Dirty Then Continue For
		For Each oProp As Inventor.Property In oSet
			If Not oProp.Dirty Then Continue For
			For Each oName In oPropNames
				If oProp.Name = oName Then
					PushToParts(oADoc.AllReferencedDocuments, oProp)
				End If
			Next
		Next
	Next
	'MsgBox("Finished.",,"")
End Sub

Sub PushToParts(oRefDocs As DocumentsEnumerator, oProp As Inventor.Property)
	Dim oParts As List(Of PartDocument) = oRefDocs.Cast(Of Inventor.Document).Where(Function(d) _
	d.DocumentType = DocumentTypeEnum.kPartDocumentObject).Cast(Of PartDocument).ToList
	For Each oPDoc In oParts
		Try
			oPDoc.PropertySets.Item(oProp.Parent.Name).Item(oProp.Name).Value = oProp.Value
		Catch
			'what to do if that fails (nothing right now)
		End Try
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 7

el_jefe_de_steak
Collaborator
Collaborator
Very thorough and well thought out!
0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Thank you, but I just noticed that I could have added more to the Catch side of the Try...Catch block.  Some code to create the iProperty if it was not found.  I guess I was thinking about how he didn't want to work with 'custom' iProperties, so I figured it wouldn't be needed.  That being the case, I probably could have limited the loop of property sets in the Sub Main area, so it wouldn't try to look into the 'custom' property set, just to possibly make it more efficient.  There are all sorts of possibilities there.

 

It also doesn't bother attempting to look into things like checking which model state is currently active at each part, or whether the file is somehow read only, like library/content center/etc.  There are all sorts of possible complications, but I was just trying to keep it simple to start.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

alan.wedge
Enthusiast
Enthusiast

Thank you for the help, your answer was perfect and the code runs great.

0 Likes