Macro to Delete Sheet2

Hello

 

I want to be able to delete sheet2 (if it exists) in a drawing with the help of a macro. (SW2014)

I first tried recording a macro but it doesn't work, then I found a lot of leads on the internet but none of them work for the moment.

 

Here is an example (non-functional) on 3D content central:

 

' Example macro with descriptions of how to add and delete Drawing Sheets. By Matthew Lorono, Copyright 2007 (fcsuper@aol.com)
' As an example, this code does not provide a usual function by itself.  By using this code in any way whatsoever, the user and
' any entities which the user represents agree to hold the original author free of all liability.
' Free distribution and use of this code in other free works are welcome.  If any portion of this code is used in other works, credit to
' the original author must be placed in that work in a user viewable location.  All other forms of distribution (i.e., not free) are
' prohibited without the expressed written consent by the original author.
' Distributed by: http://sw.fcsuper.com

Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

'Add Sheet
boolstatus = Part.NewSheet3("Bean", swDwgPaperCsize, swDwgTemplateCsize, 1, 1, False, 0, 0, 0, 0)

'Clear boolstatus for next operation (delete operation may not properly work while boolstatus = True)
boolstatus = False

'User input (so user can see what happened; not essential to the function of this macro)
MsgBox ("What's up?")

'Select Sheet
boolstatus = Part.Extension.SelectByID2("Bean", "SHEET", 0, 0, 0, False, 0, Nothing, 0)

'Delete Sheet
Part.EditDelete

End Sub

 

If you have an idea in advance, thank you.

Hello

If you have access to MyCADTools tools, INTEGRATION allows you to do this (it seems to me).

If not, wait @.PL!

1 Like

Not found in integration, it allows you to delete a layer but not a sheet.

The goal is precisely to launch this macro in integration.

1 Like

So at the time for me, I thought it was one of the possible actions. Sorry.

You can do this like:

 

 

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

swDrawing.ActivateSheet ("Sheet 2")

Set swSheet = swDrawing.GetCurrentSheet

 

swmodel. EditDelete

 

1 Like

Hello

You probably need to replace "SHEET" with "Sheet" or more likely "Sheet2".

The original macro will work if SolidWorks is in English...

FYI the 1st macro added the sheet but can't delete it.

For the macro of g.doyen ditto

SW displays a tooltip with none of these entities can be deleted.

Otherwise I also tried in the English macros to replace with Leaf or Leaf2, in vain.

So should we add the sheet or delete it? Or simply delete sheet 2 only if it exists?

Deleted Sheet2 if it exists.

1 Like

Ok, so the macro attachment works?


feuille2.txt

Unfortunately no, compilation error.

Here is the screen print:

As the picture is not great

It bugs on this line

Set swSheet = swDrawing.GetCurrentSheet

and more specifically on swDrawing (variable not defined)

Done in a hurry and not tested, it must be swdraw instead.
1 Like

try to replace with SwDraw;)

 

By the way, your 2nd sheet will necessarily be called "sheet2"?

For the mistake, that's right.

Sheet2 activates but the window with None of these entities can be deleted still appears... GRRR...

 

Otherwise, in our way of doing things, yes, Sheet1 is always the laser plane and Sheet2 is the folding plane.

I had time to test it tonight and now it works!

I put the macro in a tutorial on Lynkoa, you can find it here:

http://www.lynkoa.com/tutos/macro-solidworks-supprimer-une-feuille-d-une-mise-en-plan-0

 

PS: please choose this answer as the best!

1 Like

Sorry for the late reply. But Big network problem this morning.

I tested the last macro and it works great.

On the other hand, the pdf format completely breaks the layout when copying pasting.

But nothing serious.

Thank you very much to all those who helped and in particular to .PL, who deserved the best answer!

1 Like
Thank you. For your last problem, I didn't understand, you can open a new question if you want.