Modify existing custom prop
Modify existing custom prop
(OP)
Hi All,
I have a macro that reads a custom property from a part and then runs a routine on it to acquire another value. This value then needs to get set as another custom property. I have what I think works the first time if the custom property does not exits. It fails to rewrite the custom property if they change depending on the input. What kind of code can I use to basically force a rewrite of an existing property?
Below is the line where I write the new custom property.
Part.AddCustomInfo3 "", "UnitPrice", 30, Stlprice
It is possible that Stlprice value could change thus the custom prop called UnitPrice needs to change each time the macro runs.
Thanks.
I have a macro that reads a custom property from a part and then runs a routine on it to acquire another value. This value then needs to get set as another custom property. I have what I think works the first time if the custom property does not exits. It fails to rewrite the custom property if they change depending on the input. What kind of code can I use to basically force a rewrite of an existing property?
Below is the line where I write the new custom property.
Part.AddCustomInfo3 "", "UnitPrice", 30, Stlprice
It is possible that Stlprice value could change thus the custom prop called UnitPrice needs to change each time the macro runs.
Thanks.






RE: Modify existing custom prop
Add the following line of code before the addprops line that you have.
SwModel.DeleteCustomInfo2 "", "unitprice"
This deletes it and your line of code then recreates it with your new value.
Hope this helps
RE: Modify existing custom prop
part.DeleteCustomInfo2 "", "unitprice"
(not SwModel)
RE: Modify existing custom prop
RE: Modify existing custom prop
I usually double up on AddCustomInfo3 and CustomInfo2. This way the property gets added if it is not there and then changed if it already existed.
Note that these API calls are now obsolete. SW took a simple thing and made it "better" by way of the "Custom Property Manager". At least it's more complicated and makes their programmers feel a sense of validation.
RE: Modify existing custom prop
Thanks.
RE: Modify existing custom prop
CODE
Dim propertyManager As SldWorks.CustomPropertyManager
Set propertyManager = document.Extension.CustomPropertyManager(config)
If (propertyExists(propertyManager, propertyName)) Then
propertyManager.Set propertyName, value
Else
propertyManager.Add2 propertyName, swCustomInfoText, value
End If
End Sub
Function propertyExists(propertyManager As SldWorks.CustomPropertyManager, propertyName As String) As Boolean
Dim found As Boolean
found = False
If (propertyManager.Count > 0) Then
Dim propertyNames() As String
propertyNames = propertyManager.GetNames
Dim i As Integer
For i = LBound(propertyNames) To UBound(propertyNames)
If StrComp(propertyNames(i), propertyName) = 0 Then
found = True
Exit For
End If
Next i
End If
propertyExists = found
End Function
Eric
RE: Modify existing custom prop
RE: Modify existing custom prop
Part.AddCustomInfo3 "", "UnitPrice", 30, Stlprice
Thanks.
RE: Modify existing custom prop
30 = text property type
If your StlPrice variable is not a string, you may want to force it to be a string using CSTR
CODE
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: Modify existing custom prop
Wade
RE: Modify existing custom prop