Script to Switch viewport to Default Camera?

SasqwachSasqwach Posts: 25

I frequently like to switch between the top, back and perspective views in Daz while working on my main camera angle, tho while it is handy to have shortcuts for views I would like to make a small script that would find the "Default Camera" in scene and switch to it immediately.

Have tried tinkering with Mcj's scripts to "find and select a camera" but not switch view to that camera

var vmgr = MainWindow.getViewportMgr();

var vport = vmgr.getActiveViewport().get3DViewport();

var cam = vport.getCamera();

if( Scene.findNode( cam.name ) ) //must be in the scene

{

Scene.selectAllNodes( false );

cam.select( true ); //selects but doesnt switch

cam......Switch to selected cam in viewport HERE!?

}

 

Sorry incredibly amatuer question but been looking thru the Api and can seem to find means to "switch" viewport to the selected camera via script.

 

Any ideas ?

Post edited by Sasqwach on

Comments

  • vport.setCamera( cam );

  • Thanks!  tho doesnt seem to do quite what I was expecting, selects the camera but still wont switch to the Default Camera if I am in any other viewpoert mode ie Perspective, Front, etc

  • hmm, not sure why
    .

  • Richard HaseltineRichard Haseltine Posts: 102,848
    edited January 2017

    This works, except for the UV view (which I suspect is because it isn't a 3d view no, it doesn't fail at getting the 3D Viewport so I'm not quite sure what it is tripping on):

    // try to get the Default Cameravar cam = Scene.findNodeByLabel( "Default Camera" );if ( cam ) {	// work our way down to the 3D viewport	var vwmgr = MainWindow.getViewportMgr();	if ( vwmgr ) {		var vwport = vwmgr.getActiveViewport();		if ( vwport ) {			var tdvwport = vwport.get3DViewport();			if ( tdvwport ) {				// make the Default Camera active				tdvwport.setCamera( cam );			}		}	}}

     

    Post edited by Richard Haseltine on
  • SasqwachSasqwach Posts: 25
    edited January 2017

    You Sir, are a hero!

    That works perfectly I can bind to a shortcut and have my own icon for quick flipping now !

    Many, Many Thanks !

    PS Are there any other good daz scripting resources / texts other than the API guide ? It's quite cumbersome to work thru

    Post edited by Sasqwach on
  • Have you looked at Rob's samples? They are release under the CC Attribution Unported license. http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/start

  • Thanks I had a look at that area already; was more the actual API docs I found to be a bit tricky to find what I was looking for - Guess it's time to study !

  • bluejauntebluejaunte Posts: 1,923

    Is there a way to switch viewport to one of the view cameras like "Perspective View"? Couldn't find out how to do that.

Sign In or Register to comment.