Add and Delete custom properties in SW2018SP4

Hi Guys,

I have visual basic code that i used to add and delete custom properties to a part in Solidworks. It worked fine in SW2017SP3 but now doesn't work in 2018SP4.

Here is the method i was using to Delete

retval = Part.DeleteCustomInfo("TextBox2")

To Add

retval = Part.AddCustomInfo("TextBox2", "Text", TextBox2.Text)

I don't know if there is something else i need to be uisng in SW2018SP4

Any help is appreciated.

Thanks

SolidworksApi/macros
Answers 9
JS
JS 2021-04-09 Best Answer

You haven't provided enough information.  In what way is it not working?  No results?  Wrong results?  Computer spontaneously combusts?

Both of  the DeleteCustomInfo methods (ModelDoc::DeleteCustomInfo  and ModelDoc2::DeleteCustomInfo) are marked as obsolete.  This doesn't mean they won't still work, but it is usually a good idea to change your code to use the recommended replacement:

2018 SOLIDWORKS API Help - ICustomPropertyManager Interface Members

JS
JS 2021-04-09

Thank you so much!

DG
DG 2021-04-09
<p>James Smith wrote:</p><p></p><p>Hi Deepak,</p><p>Yes it is working fine now i found the issue. what is the new method to view/get existing custom properties to populate in "<span style="color: #333333; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; font-size: 14px;">TextBox2.Text"</span></p><p style="min-height: 8pt; padding: 0px;"></p>

Try these codes

<p>Option Explicit</p><p>Dim swApp As SldWorks.SldWorks</p><p>Dim swModel As SldWorks.ModelDoc2</p><p>Dim cusPropMgr As SldWorks.CustomPropertyManager</p><p>Dim ValOut As String</p><p>Dim ResolvedValOut As String</p><p>Dim wasResolved As Boolean</p><p></p><p>Sub main()</p><p>    Set swApp = Application.SldWorks</p><p>    Set swModel = swApp.ActiveDoc</p><p>    cusPropMgr.Get5 "TextBox2", False, ValOut, ResolvedValOut, wasResolved</p><p>    Debug.Print ResolvedValOut</p><p>End Sub</p>
JS
JS 2021-04-09

Hi Deepak,

Yes it is working fine now i found the issue. what is the new method to view/get existing custom properties to populate in "TextBox2.Text"

currently i am using this which is also obslolete.

TextBox2.Text = Part.CustomInfo("TextBox2")

Thanks you for your help!

DG
DG 2021-04-09

​, that must have been old/existing property lying there as could would only do custom properties unless you change it to do configuration properties by adding the configuration name like has mentioned.

SA
SA 2021-04-09

Code as shown should update the Custom tab.  After you run your code, what do you see on the custom tab?  Did you change "" to "Default" accidentally?

JS
JS 2021-04-09

Hi Deepak,

Your example is working and i was able to update however it is not updating the "Custom Tab" its updating the values in "Configuration Specific" tab. Is there something else i should be using to update custom tab?

Thank You for all the help!

comment imagecomment image
DG
DG 2021-04-09

Try these codes

<p>Option Explicit</p><p>    Dim swApp           As SldWorks.SldWorks</p><p>    Dim swModel         As SldWorks.ModelDoc2</p><p>     Dim cusPropMgr As CustomPropertyManager</p><p>Sub Main ()</p><p></p><p>Set swApp = Application.SldWorks</p><p>Set swModel = swApp.ActiveDoc</p><p>Set cusPropMgr = swModel.Extension.CustomPropertyManager("")</p><p></p><p>' Use 1 or 2 as needed.</p><p>' 1 would delete an existing custom property having the same name and add the new custom property</p><p>' 2 would replace the value of an existing custom property having the same name</p><p>'cusPropMgr.Add3 <span style="color: #333333; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; font-size: 14px;">"TextBox2"</span>, 30, <span style="color: #333333; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; font-size: 14px;">TextBox2.Text</span>, 1 </p><p><span style="background-color: #f6f6f6;">cusPropMgr.Add3 </span><span style="color: #333333; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; font-size: 14px;">"TextBox2"</span><span style="background-color: #f6f6f6;">, 30, </span><span style="color: #333333; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; font-size: 14px;">TextBox2.Text</span><span style="background-color: #f6f6f6;">, 2 </span></p><p></p><p>swModel.Save</p><p></p><p>End Sub</p>
JS
JS 2021-04-09

Hi Jim

Basically no results it doesn't give me any errors seems like it worked but nothing gets added to the custom properties (Same code is working fine of SW2017 any old part opened in 2018 also works, Just the new stuff created using SW2018 isn't working) .

I saw that they are both obsolete and i looked at the new methods but couldn't figure out how to do the same using new method.

If anybody can just show me a simple example of how to add custom property using new method i can try that.

Thanks