recorded macro not working

Programming and macros
steph
Posts: 17
Joined: Fri Mar 26, 2021 6:45 am
Answers: 0
x 4

recorded macro not working

Unread post 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?
Jordan Brown
Posts: 26
Joined: Wed Jul 21, 2021 3:20 pm
Answers: 0
x 6
x 2

Re: recorded macro not working

Unread post 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
User avatar
AlexB
Posts: 452
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 401

Re: recorded macro not working

Unread post 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)
steph
Posts: 17
Joined: Fri Mar 26, 2021 6:45 am
Answers: 0
x 4

Re: recorded macro not working

Unread post 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
User avatar
AlexB
Posts: 452
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 401

Re: recorded macro not working

Unread post 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
steph
Posts: 17
Joined: Fri Mar 26, 2021 6:45 am
Answers: 0
x 4

Re: recorded macro not working

Unread post by steph »

Hi, I get runtime error 449, argument not optional when I try with the .extension.
User avatar
AlexB
Posts: 452
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 401

Re: recorded macro not working

Unread post 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)
steph
Posts: 17
Joined: Fri Mar 26, 2021 6:45 am
Answers: 0
x 4

Re: recorded macro not working

Unread post 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......
User avatar
AlexB
Posts: 452
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 24
x 243
x 401

Re: recorded macro not working

Unread post 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!
steph
Posts: 17
Joined: Fri Mar 26, 2021 6:45 am
Answers: 0
x 4

Re: recorded macro not working

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