3 Replies Latest reply on Feb 11, 2013 2:17 PM by Joy Garon

    Delete a configuration specific property using a wildcard?

    Joy Garon

      Hello All,


      I have a rougue custom property (something that was cut and paseted and mangeled) that I would like to get rid of - is it possible to use a wildcard to specifiy the name?

      eg: all property beginning with the text Description1

      swCustPropMgr.Delete "Description1*"


      Is this possible?




        • Re: Delete a configuration specific property using a wildcard?
          John Seyler

          you could use "InStr" which searches for one string in another and compare it to the property name

          • Re: Delete a configuration specific property using a wildcard?
            Keith Rice



            I assume you are using VBA?


            I'm not aware of any VBA function that uses the asterisk for a type of wildcard. Like John says, there are VBA functions will let you accomplish what you need, just not using an asterisk per se. Keep in mind that Instr() searches the string for any instance of a specified piece of text, so if by chance your property was called "myDescription1" then this property would be deleted even though "Description1" wasn't at the beginning. So you can use the Left() function to test if the first 12 characters of the string match "Description1" (case sensitive).


            This code will search all configuration specific custom properties and delete those beginning with "Description1".




            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

            Dim swCustPropMgr As SldWorks.CustomPropertyManager

            Dim vConfigNames As Variant

            Dim vCustPropNames As Variant

            Dim i As Integer

            Dim j As Integer


            Sub main()

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc


                vConfigNames = swModel.GetConfigurationNames

                For i = 0 To UBound(vConfigNames)

                    Set swCustPropMgr = swModel.Extension.CustomPropertyManager(vConfigNames(i))

                    vCustPropNames = swCustPropMgr.GetNames

                    For j = 0 To UBound(vCustPropNames)

                        If Left(vCustPropNames(j), 12) = "Description1" Then swCustPropMgr.delete vCustPropNames(j)

                    Next j

                Next i

            End Sub




            Hope this helps.



            Video Tutorials for the SolidWorks API