Orienting the camera's direction so that it's perfectly orthogonal

Hi guys, I am using a space mouse to walk through long narrow corridors and want to orient the camera so that it’s perfectly parallel to the world axes. Wondering if there’s a script or python that can do this. I’ve attached a short video that might help explain what I’m trying to do. Thank you.


You can set this up pretty easily with Grasshopper, @efestwin’s ghpyanimation add-on (cf. SetActiveCamera component), and a simple number slider which would control the camera movement along the desired axis. I don’t know anything about space mice.

Props for the descriptive video. Must be a first around here. :slight_smile:

1 Like

Yikes! I was hoping for something simpler like a macro I could attach to an alias or a python script.

Hi @cosmas, i guess for a static perspective view, it’s possible. But once you move the camera (and target) with the space mouse, it must deviate. Below is a script with 6 options, you can either change the camera or the target to the opposite x,y,z coordinate.

To try it first time, change to _4View, make perspective viewport active and enable the _Camera so you can see it in top view when choosing one of the options.

OrthoCamera.py (2.7 KB)

btw, small mouse tip: Start to rotate the perspective view using RMB, then hold Shift + Ctrl, it will snap the camera to the closest axis and switch it to a parallel projection. If you change the projection back to perspective in the properties panel, the camera and target will be aligend in 2 axes, eg. x and z or y and z.

You can “rotate out” of a parallel projection into perspective if you hold Shift + Ctrl before using RMB too.

1 Like

Hi @clement Clement - thank you for the Python script. I installed it as an alias and when I run the alias I’m not getting any options (you mentioned it would have 6 options.) Also when I try to move my camera through the model using the 3d connexion mouse now the camera just zooms in instead of “dollying” in. Would you mind watching the attached quick video and let me know what you think? Thank you.

For some reasons it seems your perspective viewport turned into a parallel view… reset your viewports.

I’ve put @clement 's script (cool tool!!) into a button on the toolbar, it works.
But you have to put the whole path to where the .py file is stored.
Something like this:
!-RunPythonScript “C:\Users\maje\Downloads\OrthoCamera.py”
You can also have more combinations by specifing the option, like:
!-RunPythonScript “C:\Users\maje\Downloads\OrthoCamera.py” _CameraToTargetX _Enter

Also, this “Rotate” flag on the SpaceMouse dropdown menu:
2022-02-21 20_40_40-Window
might interest you.
If you disable it, the rotation is turned off, and you will be able to pan only, with the SpaceMouse.
You toggle it with:
!-_SpaceMouse _Rotate _Enter

(Many interesting options on !-_SpaceMouse , you might want to give a chance to “Dominant” option… )

Also, when you turn on the Camera Frustum with F6, you can select it and turn on its control points and move them…

1 Like

Hi @cosmas,

hm, if you open the script in the editor (type _EditPythonScript) and run it from there, do you see the commandline options ? it should look something like this:

btw. i see it states “press Enter when done” which is nonsense, if you choose one of the options, it will be done :wink:

As for the part when you can only zoom, this is likely the case if your view is not perpective but using a parallel projection. You can verify this in the properties panel if nothing is selected.

Also note what Riccardo replied. If you do not see the options come up by using the alias, check if there is a space behind the command section. I would run the script like so from a button or alias, this should show the options:

! _-RunPythonScript "C:\YourPathToTheScript\OrthoCamera.py"

Of course you can call one of the options as Riccardo shows above, this way you won’t see the options as it directly calls one. (btw. the _Enter at the end of Riccardo’s example should not be required, once an option is clicked or send to the commandline, it will perform it’s action and exit the script)

any better ?


1 Like

Thank you guys. It works!