Page 1 of 1

get and set state of rotate about scene floor

Posted: Tue Nov 16, 2021 12:40 pm
by colt
I am trying to make a macro that will rotate my model about each axis. So far I have it working with the following code. Eventually each axis will be assigned its own hotkey so I can nudge the rotation of my model with high precision.

Code: Select all

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swConfig As SldWorks.Configuration
Dim swActiveView As SldWorks.ModelView
Dim swScene As SldWorks.swScene
Dim i As Integer
Dim a As Double

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swActiveView = swModel.ActiveView
Set swConfig = swModel.GetActiveConfiguration
Set swScene = swConfig.GetScene

a = 0.015707
For i = 1 To 200
    'swScene.FloorAlignment = swSceneFloorAlign_e.swSceneFloorAlign_VIEW  'had no effect
    swActiveView.RotateAboutAxis a, 0, 0, 0, 1, 0, 0
Next i

For i = 1 To 200
    'swScene.FloorAlignment = swSceneFloorAlign_e.swSceneFloorAlign_VIEW
    swActiveView.RotateAboutAxis a, 0, 0, 0, 0, 1, 0
Next i

For i = 1 To 200
    'swScene.FloorAlignment = swSceneFloorAlign_e.swSceneFloorAlign_VIEW
    swActiveView.RotateAboutAxis a, 0, 0, 0, 0, 0, 1
Next i
End Sub
However, there is a problem if the model is set to "Rotate about scene floor". The rotateAboutAxis calls go wonky, resulting in incorrect rotation of the model. The simplest fix would be to set "Rotate about scene floor" to false before calling rotateAboutAxis, and then restore its value after the call.

How can I do this? Macro recorder does not register changing the value of "Rotate about scene floor", so my hopes are not high.

Re: get and set state of rotate about scene floor

Posted: Wed Nov 17, 2021 10:06 am
by RonE
Hi colt,

you could check "HKCU\SOFTWARE\SolidWorks\SOLIDWORKS 2020\General" for the value of "View Rotate About Vertical" (1 is on, 0 is off).

Unfortunately SOLIDWORKS seems to update the registry only after opening the system options dialog and exiting it with OK or by closing the program.

To toogle the behavior you could use the following line:

swApp.runcommand 3071 , ""

Maybe someone else knows a reliable way to get the current status of that option.

Kind regards
RonE