I use follow code, Creat custom information.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim value As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swModel.AddCustomInfo3 "", "MyProp3", swCustomInfoNumber, "3"
swModel.AddCustomInfo3 "", "MyProp4", swCustomInfoNumber, "4"
Dim retval() As String
Dim i As Integer
retval = swModel.GetCustomInfoNames2("")
For i = 0 To UBound(retval)
swApp.SendMsgToUser2 retval(i), 0, 0
Next
Dim count As Long
count = swModel.GetCustomInfoCount2("")
'swApp.SendMsgToUser2 "You have " & count & " custom properties.", 0, 0
swApp.SendMsgToUser2 _
"You have " & count & " custom properties.", 0, 0
End Sub
Result see Graph
Target demand:
How to change Custom value
e.g. value/text expression 3 change 10
e.g. value/text expression 4 change 11
Thanks very much.
Hi Yong, you should use the IModelDocExtension::CustomPropertyManager instead for managing your custom properties...it is very simple and efficientto use.
There are methods for Adding (Add2), gettings (Get4), deleting (Delete), setting (Set) and more.
You can implement CustomPropertyManager to either config specific properties (swModel.Extension.CustomPropertyManager("ConfigName")) or for the custom tab (Just send in empty "ConfigName" -> "").
Once you have the CustomPropertyManager you can call the methods mentioned above.
I typically test to see if the custom property exists so I can be sure my code will do the right thing. The reason I do this is because if you use the Set method, if the custom property doesn't exists, it won't work, and you can't be sure whether it failed because the value you tried setting was invalid or if the property didn't exist in the first place.
Here's an example for what you're trying to do:
Hope this helps,
Filipe