Can't change Document Property

Programming and macros
User avatar
loeb
Posts: 46
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 34
x 8

Can't change Document Property

Unread post 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.
Attachments
image.png
by AlexB » 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"
Go to full post
User avatar
AlexB
Posts: 434
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 21
x 240
x 383

Re: Can't change Document Property

Unread post 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"
User avatar
loeb
Posts: 46
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 34
x 8

Re: Can't change Document Property

Unread post 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"
User avatar
AlexB
Posts: 434
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 21
x 240
x 383

Re: Can't change Document Property

Unread post 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.
Post Reply