Macro removal all but 3 specific properties since drawing

Hi all

 

I'm looking to remove all solidworks properties from a drawing except 3 properties (NUMERO_PLAN, INDEX, DATE).

I found a macro  (see attachment) that removes all variables but I don't know how to add exceptions.

Anyone have an idea?

Thanks in advance

 

 


macro1.swp

You just have to add a simple condition:

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim cpm As CustomPropertyManager

Sub DeleteProps()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

Dim names() As String

Set cpm = swModel.Extension.CustomPropertyManager("")
names = cpm.GetNames

Dim i As Integer
For i = 0 To UBound(names)
Debug.Print names(i)
If names(i) <> "PROP1" Or names(i) <> "PROP2" Or names(i) <> "PROP3" Then cpm.Delete names(i)
Next

End Sub

Or if you have the tools, use the smartproperties tool of the Mycadtools utilities.

With this utility you can even apply it in batches.

https://help.visiativ.com/mycadtools/2020/fr/BatchProperties.html

 

 

1 Like

I tried the way  described sbadenis, but it still removes the CODE_ARTICLE &  NUMERO_PLAN property 

These are the properties of a drawing

Here's the macro

 

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim cpm As CustomPropertyManager

Sub DeleteProps()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

Dim names() As String

Set cpm = swModel.Extension.CustomPropertyManager("")
names = cpm. GetNames

Dim i As Integer
For i = 0 To UBound(names)
Debug.Print names(i)
If names(i) <> "CODE_ARTICLE" Or names(i) <> "NUMERO_PLAN" Then cpm. Delete names(i)
Next

End Sub


macro1.swp

Sorry you have to put an and instead of gold because you erase so different from pop& and so different from prop2

 

Be careful, the breakage is important.

If necessary for the test phase you can try this:

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim cpm As CustomPropertyManager

Sub DeleteProps()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

Dim names() As String

Set cpm = swModel.Extension.CustomPropertyManager("")
names = cpm.GetNames

Dim i As Integer
For i = 0 To UBound(names)
Debug.Print names(i)
If names(i) <> "Prop1" And names(i) <> "Prop2" Then Debug.Print names(i) & ": Effacé"
'If names(i) <> "Prop1" And names(i) <> "Prop2" Then cpm.Delete names(i)

Next

End Sub

And then you edit your macro and you launch it from the editor. And you check your execution window, it shows you the name of the property and then the name of the property: Deleted if it needs to delete it. Otherwise, it moves on to the next property.

I'll let you watch that.

2 Likes

thank you it was indeed And that you had to put