iProperties Update Help

iProperties Update Help

layochim
Enthusiast Enthusiast
46 Views
2 Replies
Message 1 of 3

iProperties Update Help

layochim
Enthusiast
Enthusiast

I've been working with a rule to update my "Part Number" iProperties with the first 12 characters of the filename to all iams and ipts within the iams that contain the first 5 characters of the filename.  This rule is what i've got but the iproperties are not updating.  

 

' Get the current document's file path and name
Dim filePath As String
filePath = ThisDoc.Document.FullFileName

' Extract the first 5 characters of the filename (optional)
Dim prefix As String
prefix = Mid(filePath, 1, 5)

' Ensure the filename has at least 12 characters
If Len(filePath) >= 12 Then
    ' Extract the filename without extension
    Dim fileName As String
    fileName = System.IO.Path.GetFileNameWithoutExtension(filePath)
    
    ' Extract the first 12 characters of the filename
    Dim partNumber As String
    partNumber = Mid(fileName, 1, 12)

    ' Access the iProperties of the document
    Dim oPropSet As PropertySet
    oPropSet = ThisDoc.Document.PropertySets.Item("Design Tracking Properties")
    
    ' Check if "Part Number" property exists and update it
    If Not oPropSet.Item("Part Number") Is Nothing Then
        oPropSet.Item("Part Number").Value = partNumber
    Else
        ' If the Part Number property is not found, throw an error or handle it
        MessageBox.Show("Part Number property not found!")
    End If
End If
0 Likes
47 Views
2 Replies
Replies (2)
Message 2 of 3

J_Pfeifer_
Advocate
Advocate

You're working in an assembly where you want to modify the part number of the components of the assembly? If that's the case you've got to actually open or store those objects in memory. My understanding is, parts within an assembly are displayed with limited information. You have to load the part, similar to how you have to edit a part within an assembly to edit that part. 

 

Without gaining access to the parts or sub assemblies I'm not sure these parameters are exposed to you (component occurrences or opening the file invisibly behind the scenes). You might just be editing the primary top level assembly (oPropSet = Thisdoc.Document.PropertySets.item("Design Tracking properties)) document properties. Would require me to runs some tests. 

 

Lastly, is this the entire code? or just what's in a loop?

0 Likes
Message 3 of 3

layochim
Enthusiast
Enthusiast

Ah you're right, I was only modifying the top-level(parent) assembly, I did not notice this.

This is the entire code I got.

 

The goal would be for all iams within the top level and ipts within the iams to have the Part Number updated.

0 Likes