Script: store/restore viewport view [SOLVED]
On 23/02/2016 at 02:13, xxxxxxxx wrote:
Here's the thing:
I'm almost always working in a maximized viewport, and fancy switching the view by keyboard shortcuts. ((CTRL-2: front, CTRL-5: top, CTRL-6: right ...).
This is of course possible, BUT: I want C4D to remember the views!
Softimage does exactly that. Work in one big view, switch around views, and always see again what you just saw before.
What happens now in C4D is that switching views (top, front, ...) also RESETS this view, so re-panning and re-zooming is necessary, which slows down the workflow considerably!
Example: I work in some camera (maximized) view, switch to maybe top view, pan and zoom around, work on something, switch back to camera view, do something else, and switch back to top view - oops, "top" has forgotten where it just was a moment ago, and again, panning and zooming is necessary.
Very annoying! Believe me in that, please.
The workaround for the moment: I minimize the VP, move the cursor over another view I need, and maximize again. Yet this forces C4D to redraw all shown viewports, and this can be slow, too, especially in huge scenes.
Now, my keyboard shortcuts then would trigger a script that:
- stores the momentary view,
- switches the view and restores it to what was remembered before.
Sounds easy, but I cannot find script examples, so I need to ask pretty much for everything:
- are front, top, etc. views also cameras, internally?
- how do I get the camera of the active viewport? (the maximized one, or the framed one when there are 4 VPs). I suppose this will return a CameraObject?
- what's a good place to store global variables/objects? (what CameraObject.GetProjection, GetZoom etc. returned)
Thanks for any help!!
On 24/02/2016 at 01:57, xxxxxxxx wrote:
a script can only be executed from the Script Manager. So a script cannot react to events. If you want to react to events you have to create a plugin, maybe a MessageData plugin that catches the event. Changing the view projection triggers the EVMSG_CHANGE event message.
If you use a plugin instead of a script it should be no problem to store data.
You can get the currently active document with GetActiveDocument(). Then you can get the currently active viewport window with GetActiveBaseDraw(). From that BaseDraw you can check if there is a scene camera with GetSceneCamera(); if no scene camera is set you can access the editor camera with GetEditorCamera() (you find some related code in the "LookAtCamera" example plugin).
On 26/02/2016 at 01:07, xxxxxxxx wrote:
Thanks, Sebastian! I'll give it a try shortly.