How to unselect "Display sheet Format" in VBA

Use this space to ask how to do whatever you're trying to use SolidWorks to do.
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

How to unselect "Display sheet Format" in VBA

Unread post by Jacomuller »

G'Day
I use a macro to insert a new custom size sheet in a Solidworks 2019 drawing. (I have created a custom template "TAG_MW_Single_View".) The macro work well and it sets all properties as required. The only thing missing is to deselect "Display sheet format". I have recorded macro when I do it manually and the code for that is:

Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Part.ClearSelection2 True
boolstatus = Part.SetupSheet5("MW Sheet", 12, 12, 1, 20, False, "C:\SWDVault\Engineering\Z00 -
Solidworks\sheetformat\TAG_MW_Single_View.slddrt", 0.42, 0.297, "Default", False)
End Sub

The "Part.ClearSelection2 True" is the code that clears the box, but if I use it in my code it does not work.

I have also tried "swDraw.SheetFormatVisible = False" and that use to work but for some reason it is not working anymore. I must have changed some code somewhere else.

Regards
Jaco
by gupta9665 » Tue Oct 29, 2024 11:02 pm
You need to get the current sheet, and then turn off the sheet format visibility.

Try
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim currentsheet As Sheet
Dim boolstatus As Boolean

Sub main()

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

boolstatus = Part.SetupSheet5("MW Sheet", 12, 12, 1, 20, False, "C:\SWDVault\Engineering\Z00 - Solidworks\sheetformat\TAG_MW_Single_View.slddrt", 0.42, 0.297, "Default", False)

Set currentsheet = swModel.GetCurrentSheet
currentsheet.SheetFormatVisible = False

End Sub
Go to full post
User avatar
SPerman
Posts: 2056
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 14
x 2227
x 1878
Contact:

Re: How to unselect "Display sheet Format" in VBA

Unread post by SPerman »

-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

Re: How to unselect "Display sheet Format" in VBA

Unread post by Jacomuller »

#SPerman - I have tried it before and it use to work, but for some reason it is not working now. This is my code:

Code: Select all

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As Sheet
Dim SelMan As SldWorks.SelectionMgr
Dim retval As Boolean
Dim vSheetProps As Variant
Dim TemplateName As String
Dim instance As ISheet

Sub main()
    TemplateName = "C:\SWDVault\Engineering\Z00 - Solidworks\sheetformat\TAG_MW_Single_View.slddrt"
    Set swApp = Application.SldWorks
    Set swDraw = swApp.ActiveDoc
    'swApp.SendMsgToUser "Complete"
    
    
    retval = swDraw.NewSheet3("MW Sheet", swDwgPapersUserDefined, swDwgTemplateCustom, 1, 20, False, TemplateName , 0.08, 0.08, "MW View") ' TAG_MW_Single_View.slddrt
    swDraw.ActivateSheet ("MW Sheet")
   ' Get the drawing document
    
    ' Get the active document
    Set swModel = swApp.ActiveDoc
'    swDraw.SheetFormatVisible = False
    instance.SheetFormatVisible = False
    
    
    .......more code
    
 
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

Re: How to unselect "Display sheet Format" in VBA

Unread post by Jacomuller »

In a similar case, how do I set "Display all configuration of the same part as one item" as "Part configuration Grouping" with VBA code?
image.png
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

Re: How to unselect "Display sheet Format" in VBA

Unread post by Jacomuller »

Hi @RonE

Do you have some wisdom about this issue? It should be very similar to the problem you solved earlier - I am just not skilled enough to connect the dots. grumph

Regards

Jaco
User avatar
gupta9665
Posts: 412
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 434
x 450

Re: How to unselect "Display sheet Format" in VBA

Unread post by gupta9665 »

You need to get the current sheet, and then turn off the sheet format visibility.

Try
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim currentsheet As Sheet
Dim boolstatus As Boolean

Sub main()

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

boolstatus = Part.SetupSheet5("MW Sheet", 12, 12, 1, 20, False, "C:\SWDVault\Engineering\Z00 - Solidworks\sheetformat\TAG_MW_Single_View.slddrt", 0.42, 0.297, "Default", False)

Set currentsheet = swModel.GetCurrentSheet
currentsheet.SheetFormatVisible = False

End Sub
Deepak Gupta
SOLIDWORKS Consultant/Blogger
Jacomuller
Posts: 47
Joined: Wed Mar 01, 2023 6:55 pm
Answers: 2
x 33
x 4

Re: How to unselect "Display sheet Format" in VBA

Unread post by Jacomuller »

Thanks @gupta9665 . It is now working fine.
Post Reply