Page 1 of 1

Can't change Document Property

Posted: Mon Aug 21, 2023 12:57 pm
by loeb
Under Options->Document Properties->Drawing Sheets->Sheet format for new sheets,
I am trying to change the settings using the methods documented here: https://help.solidworks.com/2021/englis ... Sheets.htm

I have done this for other settings successfully, but just can't get it to work for these settings. Here's an example

Code: Select all

    Set ModelDocExtension = swModel.Extension
    
    BoolStatus = ModelDocExtension.SetUserPreferenceDouble(swUserPreferenceDoubleValue_e.swDetailingDimBreakGap, swUserPreferenceOption_e.swDetailingNoOptionSpecified, 0)
    BoolStatus = ModelDocExtension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDetailingDimBreakAroundArrow, swUserPreferenceOption_e.swDetailingNoOptionSpecified, 0)
    
    BoolStatus = ModelDocExtension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDrawingSheetUseDifferentSheetFormat, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True)
    BoolStatus = ModelDocExtension.SetUserPreferenceToggle(swUserPreferenceStringValue_e.swFileLocationsNewSheetFormat, swUserPreferenceOption_e.swDetailingNoOptionSpecified, SheetFormatP2)
The first two SET command work properly, but the last two won't complile. I get the "Method or data member not found" for "swDrawingSheetUseDifferentSheetFormat"

Thank you for your help.

Re: Can't change Document Property

Posted: Mon Aug 21, 2023 12:59 pm
by AlexB
The first one has a typo.
The last line, you have SetUserPreferenceToggle, when it should be SetUserPreferenceString

Code: Select all

Set swApp = Application.SldWorks

Dim swModel As ModelDoc2
Set swModel = swApp.ActiveDoc

Dim swExt As ModelDocExtension
Set swExt = swModel.Extension

swExt.SetUserPreferenceToggle swUserPreferenceToggle_e.swDrawingSheetsUseDifferentSheetFormat, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True
swExt.SetUserPreferenceString swUserPreferenceStringValue_e.swFileLocationsNewSheetFormat, swUserPreferenceOption_e.swDetailingNoOptionSpecified, "TEST"

Re: Can't change Document Property

Posted: Mon Aug 21, 2023 2:07 pm
by loeb
Thank You, AlexB. I would have never caught that "typo" since I copied it verbatim from the SW API help pages.

I can't figure out is what the proper syntax is for calls like this. I originally used the "BoolStatus = swApp.SetUserPreference..." form because that's what SW has in examples such as https://help.solidworks.com/2021/englis ... ple_VB.htm

Thank you again for your help!
AlexB wrote: Mon Aug 21, 2023 12:59 pm The first one has a typo.
The last line, you have SetUserPreferenceToggle, when it should be SetUserPreferenceString

Code: Select all

Set swApp = Application.SldWorks

Dim swModel As ModelDoc2
Set swModel = swApp.ActiveDoc

Dim swExt As ModelDocExtension
Set swExt = swModel.Extension

swExt.SetUserPreferenceToggle swUserPreferenceToggle_e.swDrawingSheetsUseDifferentSheetFormat, swUserPreferenceOption_e.swDetailingNoOptionSpecified, True
swExt.SetUserPreferenceString swUserPreferenceStringValue_e.swFileLocationsNewSheetFormat, swUserPreferenceOption_e.swDetailingNoOptionSpecified, "TEST"

Re: Can't change Document Property

Posted: Mon Aug 21, 2023 3:23 pm
by AlexB
loeb wrote: Mon Aug 21, 2023 2:07 pm I can't figure out is what the proper syntax is for calls like this.
The syntax I used ignores the return value because I didn't really need it for my example. If you use the syntax you initially had, you can monitor the "BoolStatus" to make sure it returns "True" and verify your change was indeed made.