Create or modify custom properties of children from assembly

Create or modify custom properties of children from assembly

peterjoachim
Enthusiast Enthusiast
537 Views
1 Reply
Message 1 of 2

Create or modify custom properties of children from assembly

peterjoachim
Enthusiast
Enthusiast

After scouring through the forums I was able to piece together the code below (My coding skills are very weak). It works but needs some modifications I can't quite figure out.

'the document is being opened
Dim openDoc As Document = ThisDoc.Document

Dim ETOproset As PropertySet
Dim ETOProperty As Inventor.Property
Dim ETO As Double
Dim ETOHasDrawing As Boolean = False

'This code opens every document related to this assembly
For Each doc As Document In openDoc.AllReferencedDocuments
'This code allows loops to continue if the wanted parameters dont exist in the part or assembly	
On Error Resume Next

ETOproset = doc.PropertySets.Item("Inventor User Defined Properties")
ETOproset.Add(ETOHasDrawing, "TotalETOHasDrawing")

Next

 In short, what I'm trying to do is, from a top level assembly, apply this...

iProperties.Value("Custom", "TotalETODrawing") = iProperties.Value("Project", "Part Number") & "-Sht1#J:\" & (Left(ThisDoc.FileName, 6)) & "\MECH\DETAILS\" & iProperties.Value("Project", "Part Number") & "-Sht1.pdf#"
iProperties.Value("Custom", "TotalETOHasDrawing") = True

...to all components that are NOT in a library. This would be applied at the component level so the part# would reflect each components part# and not the assembly part#. Also if those properties already exist on some components, I would like it to overwrite it with these new values.

Any help would be greatly appreciated.

0 Likes
Accepted solutions (1)
538 Views
1 Reply
Reply (1)
Message 2 of 2

peterjoachim
Enthusiast
Enthusiast
Accepted solution

After reading a few Mod the Machine articles I've figured it out. Feel free to critique my code though as I'm very green.

Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document

If openDoc.DocumentType = kAssemblyDocumentObject Then    
	For Each docFile In openDoc.AllReferencedDocuments
		If docFile.IsModifiable = True Then			

			Dim customPropSet As PropertySet	
			customPropSet = docFile.PropertySets.Item("Inventor User Defined Properties")
			
			Dim partNumber As String
			partNumber = docFile.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
			
			Dim property1Name As String
			property1Name = "TotalETODrawing"
			
			Dim property1Value As String
			property1Value = partNumber & "-Sht1#J:\" & (Left(partNumber, 6)) & "\MECH\DETAILS\" & partNumber & "-Sht1.pdf#"
			
			Dim property2Name As String
			property2Name = "TotalETOHasDrawing"
			
			Dim property2Value As Boolean
			property2Value = True
			
			Try
				customPropSet.Item(property1Name).Value = property1Value
				Catch ex As Exception					
				customProp = customPropSet.Add(property1Value, property1Name)
			End Try
			Try
				customPropSet.Item(property2Name).Value = property2Value
				Catch ex As Exception					
				customProp = customPropSet.Add(property2Value, property2Name)		
			End Try
				
		End If
	Next
	Else
	MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If

 

0 Likes