Delete all display states

Hi all;
The display states poluge my "part" and "asm" files (among other things because of the unfolded, mechanically welded, and each configuration creation (sometimes I forget to uncheck the "link appearances" box)).
I found a bit of macro that deletes all display states -except the current one- and unchecks the "Link appearance states to configurations" box

[vb]

  1. Dim swApp As Object 
  2.  
  3. Dim part As Object 
  4. Dim boolstatus As Boolean 
  5. Dim longstatus As Long 
  6. Dim longwarnings As Long 
  7. Dim modelDoc As SldWorks.ModelDoc2 
  8.  
  9.  
  10. Sub main() 
  11.  
  12. Set swApp = Application.SldWorks 
  13. Set modelDoc = swApp.ActiveDoc 
  14. Set part = swApp.ActiveDoc 
  15. boolstatus = modelDoc.RemoveAllDisplayStates 
  16. End Sub

[vb]

only this macro only works on parts.
Do you know how to modify the code to apply to both parts and assemblies?

Note: keeping in mind that I am a Solidworks macro nozzle....

Kind regards.

Hello

I think you should use the SldWorks.AssemblyDoc command in other lines like this:

 

Dim swApp As Object 

Dim part As Object

Dim assy As Object

Dim boolstatus As Boolean

Dim longstatus As Long

Dim longwarnings As Long

Dim modelDoc As SldWorks.ModelDoc2

Dim AssyDoc As SldWorks.AssemblyDoc

 

Sub main() 

 

Set swApp = Application.SldWorks

Set modelDoc = swApp.ActiveDoc

Set part = swApp.ActiveDoc

Set AssyDoc=swApp.ActiveDoc

boolstatus = modelDoc.RemoveAllDisplayStates

Set assy = swApp.ActiveDoc

boolstatus = AssyDoc.RemoveAllDisplayStates

End Sub

 

I'm looking to make a condition (I'm a nozzle also in VBA so there you go..)

1 Like

Thank you Azrod

But how did I not think of it.

Does that mean I'm a notch below your nozzle level? (I'm joking of course).

I'll look for examples of part/Assembly conditions.

Thank you again, I think it's the right track.

2 Likes

"Does that mean I'm a notch below your nozzle level? (Just kidding, of course)."

Ahah I hope not, but my level in VBA is REALLY limited to the bare minimum.

At the level of a "Hello World" and even :p

Hoping I helped you (and me too!)..

2 Likes

wow... I just noticed that the command: "RemoveAllDisplayStates"

also removes appearances (those of the current material) in all display states.... That's not good! I'll have to look for something else.

 

Are you on the right version of SolidWorks? Maybe it's a bug:(

A little update is necessary?

I work with Solidworks 2014 SP4 and Solidworks 2016 Sp4.

It's the same on both versions....

Hello, it's normal that it also removes appearances, it's not a bug. 

Link to the doc

> Removes all display states and appearances from this part document.

 

I'll let you see how to use the DeleteDisplayState function in the doc, you have to tell it the name of the display state to be deleted. To do this, you will need to make a loop that retrieves all the display states.

Hello;

Thank you KVuilleumier for this information. I'm going to dig aside... and take the opportunity to do a training on APIs, it won't hurt me.