Discussion:
API: Delete all custom properties
(too old to reply)
Sam
2008-05-13 17:44:39 UTC
Permalink
I have found several examples of how to do this but none seem to work,
I need a macro that I can run that will delete all custom properties
regardless of property name.

I have a macro that will add custom properties and it is written so
that it does not require solidworks, it uses windows to create the
custom property. I would like to do the same for deleting the custom
properties.

Can someone please provide some sample code showing how to delete all
custom properties?

Thanks,

Sam
Philippe Guglielmetti
2008-05-13 18:49:24 UTC
Permalink
This function works inside a SolidWorks VBA Macro :

'**
'Delete all file of configuration properties
'@param doc Required. SldWorks.ModelDoc2 object.
'@param conf Optional. String. Default value is "".
'@param emptyonly Optional. Boolean. Default value is False. if
True, deletes only the properties without any value
'@return Boolean . true if all were deleted
Public Function DeleteAllProps( _
doc As SldWorks.ModelDoc2, _
Optional ByVal conf As String = "", _
Optional emptyonly As Boolean = False _
) As Boolean
DeleteAllProps = True
Dim names As Variant
names = doc.GetCustomInfoNames2(conf)
Dim name As Variant
For Each name In names
If emptyonly And doc.GetCustomInfoValue(conf, name) <> "" Then
GoTo continue ' don't delete
DeleteAllProps = DeleteAllProps And
doc.DeleteCustomInfo2(conf, name)
continue:
Next name
End Function

To delete properties outside of SolidWorks, you'll need to create an
application, not a macro, and link to a .dll (which I don't recall the
name at the moment) to access standard Windows properties. I'm not
even sure you can delete them this way, but I'm absolutely sure you
can't delete configuration specific properties this way.

Loading...