Change config in plans (vba)

Hello

I am looking for a charitable soul to help me make a program to change the configurations in the drawing. Let me explain.

I have a room with several configs, I have to make a plan for each config (so a different sheet for each config). I already have a macro to copy/paste the sheets, and a macro to rename the sheets (the same name as the name of the configs). Now I'm looking for a code to go through each sheet and change the reference configuration of the drawing according to the name of my sheet or directly according to the name of my config.

I found a macro on code stack but it does everything (copy/paste renames and changes config), I tried to modify it so that it just changes the config. So it works but only on the last sheet. I can't get curly on the leaves. In addition, I want the 3 steps to be independent, hence my problem.

Anyone have an idea?

Codestack Macro:

The macro propagates the configurations from the referenced document to the sheets of SOLIDWORKS drawings (codestack.net)

The end of the code edit:

Sub CopySheet(draw As SldWorks.DrawingDoc, sheet As SldWorks.sheet, SheetName As String)

Dim swNewSheet As SldWorks.sheet
Set swNewSheet = draw.sheet(draw. GetSheetNames()(draw. GetSheetCount() - 1))
            
Dim vViews As Variant
vViews = swNewSheet.GetViews
            
Set swDraw = swApp.ActiveDoc
Dim vSheetNames As Variant
vSheetNames = swDraw.GetSheetNames
            
Dim i As Integer
Sun j As Integer
            
For j = 0 TB UBound(vSheetNames)
            
For i = 0 TB UBound(vViews)
                
Dim swView As SldWorks.View
Set swView = vViews(i)
                
swView.ReferencedConfiguration = SheetName
                
Next i
Next j

End Sub

Hello

FYI, this is a feature that exists in the SmartDrawings tool of myCADtools:

https://help.visiativ.com/mycadtools/2022/fr/SmartDrawings4.html

You can test the tool for 30 days: 

https://www.lynkoa.com/mycadtools

Have a nice day

Philippe

1 Like

Thank you for the answer but I wish I could do without

I continued to work on the code, but I don't understand everything there. Indeed, my code goes well on each page, locates the views well but changes the configuration only of the last sheet. It is this point that I do not understand. Why does the configuration of the last page change but not the others?

I put my code in PJ, if anyone has an idea it would be top top top.

Thank you

Edit: After a bit of tinkering I realized that the config changes on the last page (with the right config) but if I edit my code so that the config changes on another page it always changes for the same config (the last one) and not the config corresponding to the name of the page


macro28.swp

Hello;

Your "SheetName" value is not "variable"...
Just above the row swView.ReferencedConfiguration = SheetName
Add Set SheetName = SheetNames(j)

Note: do not hesitate to use the "step by step" mode (F8) of the VB editor (with the local Variables visualization window active).
            This makes it much easier to understand the code and find errors....


Kind regards

1 Like

Hello

Unfortunately, the correction does not work.

Kind regards

Hello

Unfortunately, the correction does not work.

Kind regards