Set/Restore viewport

 From:  Michael Gibson
2891.7 In reply to 2891.1 
Hi Michael T, here are some scripts that may be useful - set these up on some shortcut keys.


Save view:

script: /* Save snapshot of current view into view stack */ var vp = moi.ui.mainWindow.viewpanel.getViewport('3D'); var data = new Object; data.camera = vp.cameraPt; data.target = vp.targetPt; var cm = moi.command; var views = new Array(); try { v = cm.getOption( 'views' ); if ( v ) views = v; } catch(e) {} views.push( data ); cm.setOption( 'views', views );


Restore view:

script: /* Restore the next view in the saved view stack */ var cm = moi.command; var views = null; try { views = cm.getOption( 'views' ); } catch(e) {} if ( views ) { var lastrestored = -1; try { lastrestored = cm.getOption( 'last_restored_view' ); } catch(e) {} var i = lastrestored + 1; if ( i >= views.length ) i = 0; var data = views[i]; var vp = moi.ui.mainWindow.viewpanel.getViewport('3D'); vp.setCameraAndTarget( data.camera, data.target ); cm.setOption( 'last_restored_view', i ); }


Clear saved views:

script: /* Clear the saved view stack */ moi.command.setOption( 'views', 0 );



Paste in each of those scripts for the command part of a new keyboard shortcut.

You might try setting up something like the saved view one on Shift+V, the restore view one on just plain V, and the clear saved views one on Alt+V (or whatever keys you wish).


So the way it works is that each time you press the "Save view" one, it will record a new saved view in an internal list so you can record one, then adjust the view a bit, record another one, etc... You can hit the "Restore view" key to cycle through those saved views one by one. If you want to start over again, hit the "Clear saved views" key and the saved stack will be removed.


The saved view stack in this case is only a runtime thing, it is not saved with your file and there isn't any method for fine tuning or replacing a view in the middle of the stack so it is fairly crude but it might give you at least the basic mechanism to set up several steps and "replay" them.

- Michael

EDIT: updated scripts to work with v3 as well now.

EDITED: 26 Jun 2013 by MICHAEL GIBSON