- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hi,
I am trying to configure the assembly template, to ensure that the custom properties are reflected in each part of this assembly, as long as these parts are in the same location that the assembly was saved and that the parts that are not in the same location , remain with the properties of each part.
I have the following code:
Sub SetPropertiesBasedOnLocation()
' Gets the location of the assembly
Dim assemblyDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim assemblyPath As String = System.IO.Path.GetDirectoryName(assemblyDoc.FullFileName)
' Iterate through the assembly parts
For Each occurrence As ComponentOccurrence In assemblyDoc.ComponentDefinition.Occurrences
' Gets the location of the part
Dim partPath As String = System.IO.Path.GetDirectoryName(occurrence.Definition.Document.FullFileName)
' Compare the part location to the assembly location
If String.Compare(assemblyPath, partPath, StringComparison.OrdinalIgnoreCase) = 0 Then
' Matches the properties of the assembly to the part
CopyProperties(assemblyDoc, occurrence.Definition.Document)
End If
Next
End Sub
Sub CopyProperties(sourceDoc As Document, targetDoc As Document)
' Copy the properties of the source document to the destination document
For Each prop As Property In sourceDoc.PropertySets.Item("Inventor Summary Information").Properties
Try
targetDoc.PropertySets.Item("Inventor Summary Information").Set(prop.Name, prop.Value)
Catch ex As Exception
' You can handle exceptions here if necessary
End Try
Next
End Sub
Solved! Go to Solution.