Page 1 of 1

How to unselect "Display sheet Format" in VBA

Posted: Thu Oct 24, 2024 6:17 pm
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

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

Posted: Thu Oct 24, 2024 6:51 pm
by SPerman

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

Posted: Thu Oct 24, 2024 8:23 pm
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
    
 

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

Posted: Sun Oct 27, 2024 5:40 pm
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

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

Posted: Tue Oct 29, 2024 5:48 pm
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

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

Posted: Tue Oct 29, 2024 11:02 pm
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

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

Posted: Wed Oct 30, 2024 1:51 am
by Jacomuller
Thanks @gupta9665 . It is now working fine.