recorded macro not working
recorded macro not working
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?
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?
-
- Posts: 26
- Joined: Wed Jul 21, 2021 3:20 pm
- x 6
- x 2
Re: recorded macro not working
"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
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
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:
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
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
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
Building on my previous post, the above corrections should work.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
Edit: I didn't test the code but the extension set toggle method was missing an argument
Re: recorded macro not working
Hi, I get runtime error 449, argument not optional when I try with the .extension.
Re: recorded macro not working
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
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
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
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)
Thanks again
boolstatus = Part.SetUserPreferenceToggle(swUserPreferenceToggle_e.swViewDisplayHideAllTypes, True)