I have the following problem:
I can not write custom properties to a masterpart. If I open a standard part, then it has a reference to the masterpart. I want to access the custom properties of the master part and edit them using vb.net.
This is the code I have so far:
Dim bMasterPart As Boolean = False If Not oDoc Is Nothing Then If oDoc.Type = DocumentTypeConstants.igPartDocument Then Dim oPart As SolidEdgePart.PartDocument = oDoc Dim oPartfamilyMembers As SolidEdgePart.FamilyMembers = oPart.FamilyMembers If oPartfamilyMembers.Count > 0 Then bMasterPart = True Try Dim oCustom As SolidEdgeFramework.Properties oCustom = oPart.Properties("Custom") Dim oProperty As SolidEdgeFramework.Property Dim bFoundProperty As Boolean = False For i As Integer = 1 To oCustom.Count oProperty = oCustom.Item(i) If oProperty.Name = sName Then oProperty.Value = sValue oCustom.Save() bFoundProperty = True End If Next If bFoundProperty = False Then oCustom.Add(sName, sValue) oCustom.Save() End If oCustom.Save() If Not (oCustom Is Nothing) Then Marshal.ReleaseComObject(oCustom) oCustom = Nothing End If Catch ex As Exception MsgBox("ex: " & ex.Message.ToString) End Try End If End If End If
In the debugger the properties are set correctly, but if open the Masterpart and look at the edited custom property, it still has the previous value... ?
What I tried so far is:
Opening each masterpart is not an option because this takes to long in large assemblies.
What else can I try? I hope someone can help me. Am I missing something?
I came into the same problem for just standard parts that are not part of a family members. I would assume the solution for that would work for FOP as well. You have to check for the custom property and if it exists then you have to delete the property and than add the property back in.
Below is the code for how to do this approach for files that are open and for ones that are closed
Dim objPropertySets As SolidEdgeFileProperties.PropertySets = Nothing Dim objProperties As SolidEdgeFileProperties.Properties = Nothing Dim objProperty As SolidEdgeFileProperties.Property = Nothing 'objPropertySets.Open(openfile, False) 'For files that are closed 'objDocument = objApplication.ActiveDocument 'For Files that are open 'objPropertySets = objDocument.Properties 'For Files that are open objProperties = objPropertySets.Item("Custom") Try If Not (objProperties.Item("Dash_Number") Is Nothing) Then objProperty = objProperties.Item("Dash_Number") ' Delete last custom property objProperty.Delete() objProperty = objProperties.Add("Dash_Number", StringValue) End If Catch ex As Exception objProperty = objProperties.Add("Dash_Number", StringValue) End Try