Page 1 of 1

recorded macro not working

Posted: Thu May 12, 2022 9:24 am
by steph
Hello

I recorded a macro in solidworks 2022 sp2.0 in a drawing containing a flat pattern to turn off the bendlines (the new button in the hide all types toolbar). The recorded code for that particular action is:

boolstatus = Part.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayBendLines, False)

Strangely, when I run that macro, this does not seem to have any effect. the rest of the macro runs fine, no error message either. What's up?

Re: recorded macro not working

Posted: Thu May 12, 2022 9:32 am
by Jordan Brown
"False" should turn off, and "True" should turn on.

So if you have the bendlines showing, and then run the macro, they do not turn off?

Hard to say what the issue is without seeing more lines from the code. A little more to work with would be helpful :)

Jordan

Re: recorded macro not working

Posted: Thu May 12, 2022 9:38 am
by AlexB
The SetUserPreferenceToggle needs to be used by either your ISldWorks (usually called swApp) or your IModelDocExtension (usually called swExt)

In your code, you can try one of the following two lines to see which one works:

Code: Select all

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayBendLines, False)
boolstatus = swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayBendLines, False)

Re: recorded macro not working

Posted: Thu May 12, 2022 9:39 am
by steph
Right, they should turn off but they dont.
here this the whole recorded macro

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.Extension.SelectByID2("Feuille1", "SHEET", 0.194074973469761, 0.193992140430351, 0, False, 0, Nothing, 0)
boolstatus = Part.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplaySketches, False)
boolstatus = Part.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayBendLines, False)

' Save
Dim swErrors As Long
Dim swWarnings As Long
boolstatus = Part.Save3(1, swErrors, swWarnings)
End Sub

Re: recorded macro not working

Posted: Thu May 12, 2022 9:47 am
by AlexB
steph wrote: Thu May 12, 2022 9:39 am Right, they should turn off but they dont.
here this the whole recorded macro

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.Extension.SelectByID2("Feuille1", "SHEET", 0.194074973469761, 0.193992140430351, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplaySketches, swUserPreferenceOption_e.swDetailingNoOptionSpecified, False)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayBendLines, swUserPreferenceOption_e.swDetailingNoOptionSpecified, False)

' Save
Dim swErrors As Long
Dim swWarnings As Long
boolstatus = Part.Save3(1, swErrors, swWarnings)
End Sub
Building on my previous post, the above corrections should work.

Edit: I didn't test the code but the extension set toggle method was missing an argument

Re: recorded macro not working

Posted: Thu May 12, 2022 10:01 am
by steph
Hi, I get runtime error 449, argument not optional when I try with the .extension.

Re: recorded macro not working

Posted: Thu May 12, 2022 10:39 am
by AlexB
steph wrote: Thu May 12, 2022 10:01 am Hi, I get runtime error 449, argument not optional when I try with the .extension.
Apologies. I haven't tested it but I updated my previous post with the corrections as well that should hopefully work.
AlexB wrote: Thu May 12, 2022 9:47 am boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplaySketches, swUserPreferenceOption_e.swDetailingNoOptionSpecified, False)
boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDisplayBendLines, swUserPreferenceOption_e.swDetailingNoOptionSpecified, False)

Re: recorded macro not working

Posted: Thu May 12, 2022 1:00 pm
by steph
Thanks for your efforts, No more error message but the "bendline" part still doesn't work. This is a new feature and maybe Solidworks didn't quite finish it......

Re: recorded macro not working

Posted: Thu May 12, 2022 1:33 pm
by AlexB
steph wrote: Thu May 12, 2022 1:00 pm Thanks for your efforts, No more error message but the "bendline" part still doesn't work. This is a new feature and maybe Solidworks didn't quite finish it......
Yeah, I wouldn't be surprised if it isn't fully functional... just like any new feature. I expect that's the correct function to call based on the format of similar things in the View -> Hide menu, but I don't have 2022 to test it out. Good luck!

Re: recorded macro not working

Posted: Thu May 12, 2022 1:36 pm
by steph
This workaround works and fits my needs, it's just too bad I wasted a few hours on this when it should have taken a few minutes.
Thanks again

boolstatus = Part.SetUserPreferenceToggle(swUserPreferenceToggle_e.swViewDisplayHideAllTypes, True)