updating properties of all parts within assembly and that it is in the same location

updating properties of all parts within assembly and that it is in the same location

Luis.TorresPZK9R
Participant Participant
347 Views
3 Replies
Message 1 of 4

updating properties of all parts within assembly and that it is in the same location

Luis.TorresPZK9R
Participant
Participant

Hi,

 

I am trying to write an ilogic script that will update specified properties of parts when the property is changed for the assembly and that it is in the same location. The code I have is the following:

 

 

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("REFERENCE") '<<<< CHANGE THIS AS NEEDED >>>>	
	oPropNames.Add("ENS") '<<<< CHANGE THIS AS NEEDED >>>>	
	oPropNames.Add("PN") '<<<< CHANGE THIS AS NEEDED >>>>		
	oPropNames.Add("Stock Number") '<<<< 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

 

 

0 Likes
Accepted solutions (2)
348 Views
3 Replies
Replies (3)
Message 2 of 4

A.Acheson
Mentor
Mentor
Accepted solution

Hi @Luis.TorresPZK9R 

 

Where would you like help with what you have written? I haven't tested this but maybe it is not working for you. If so can you attach the error messages your getting and a description of what it is and isn't doing. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 4

Luis.TorresPZK9R
Participant
Participant

Hi @A.Acheson 

In the previous code, I want to add that I only take the pieces that are in the same folder location, where the assembly is.

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor
Accepted solution

Hi @Luis.TorresPZK9R 

 

Use System.IO using help page here to check the directory of each document. You will need to supply the assembly directory as string to the sub routine as an argument and then compare the partdocument directory. 

Dim asmDir As String = IO.Path.GetDirectoryName(oADoc.FullFileName)

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes