API: Delete all custom properties

Discussion in 'SolidWorks' started by Sam, May 13, 2008.

  1. Sam

    Sam Guest

    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
     
    Sam, May 13, 2008
    #1
  2. 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.
     
    Philippe Guglielmetti, May 13, 2008
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.