Cycle Camera Views

Smart people ~ Great Scripts
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Cycle Camera Views

Post by trueBlue »

Really wanted a script that would Set the Camera view from any and all Cameras in the Scene
Best I could come up with is by name only
If there is a better way, please do share
If not, with the below script, is there a way to skip a cycle if the camera does not exist?

In other words, say there is only one Camera, 3 in the scene
When you run this script, it sets the Camera, 3 view

Currently, you have to run this script until it reaches cycle 4

Code: Select all

var cycle = 0;
function Execute(params)
{
util = System.CreateDO('Clintons3D Package/Utility functions')
if(typeof(Clintons3dPlugin) == "undefined") {
	System.Alert("Clintons3dPlugin is Required!\n\nInstall the Clintons3dPlugin.rsx in the Package Manager");
	params.SetTerminationFlag()
	return;
}
if(Node.SubObjectCount("/D3DView")==0) return;

if(cycle==0 && Node.Exists(Space.CurrentScene() + "/EntryPoint")) {
	Node.Select(Space.CurrentScene() + "/EntryPoint")
	var cmd = '';cmd += 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from the EntryPoint Camera", 2000)
	Space.Unselect()
}
if(cycle==1 && Node.Exists(Space.CurrentScene() + "/Camera")) {
	Node.Select(Space.CurrentScene() + "/Camera")
	var cmd = '';cmd += 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from Camera", 2000)
	Space.Unselect()
}
	if(cycle==2 && Node.Exists(Space.CurrentScene() + "/Camera, 1")) {
	Node.Select(Space.CurrentScene() + "/Camera, 1")
	var cmd = '';cmd += 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from Camera, 1", 2000)
	Space.Unselect()
}
if(cycle==3 && Node.Exists(Space.CurrentScene() + "/Camera, 2")) {
	Node.Select(Space.CurrentScene() + "/Camera, 2")
	var cmd = '';cmd += 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from Camera, 2", 2000)
	Space.Unselect()
}
if(cycle==4 && Node.Exists(Space.CurrentScene() + "/Camera, 3")) {
	Node.Select(Space.CurrentScene() + "/Camera, 3")
	var cmd = '';cmd += 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from Camera, 3", 2000)
	Space.Unselect()
}
if(cycle==5 && Node.Exists(Space.CurrentScene() + "/Camera, 4")) {
	var cmd = '';cmd += 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from Camera, 4", 2000)
	Space.Unselect()
}
if(cycle==6 && Node.Exists(Space.CurrentScene() + "/Camera, 5")) {
	Node.Select(Space.CurrentScene() + "/Camera, 5")
	var cmd = '';cmd += 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from Camera, 5", 2000)
	Space.Unselect()
}
if(cycle==7 && Node.Exists(Space.CurrentScene() + "/Camera, 6")) {
	Node.Select(Space.CurrentScene() + "/Camera, 6")
	var cmd = '';cmd += 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from Camera, 6", 2000)
	Space.Unselect()
}
cycle++;
cycle = cycle % 8;
}
User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Cycle Camera Views

Post by clintonman »

This will read the cameras in the scene and cycle through them no matter what there names are.

Code: Select all

var cycle = -1;

function Execute(params) 
{
	var util = System.CreateDO('Clintons3D Package/Utility functions')
	if (typeof (Clintons3dPlugin) == "undefined") {
		System.Alert("Clintons3dPlugin is Required!\n\nInstall the Clintons3dPlugin.rsx in the Package Manager");
		params.SetTerminationFlag()
		return;
	}
	if (Node.SubObjectCount("/D3DView") == 0) return;

	var sceneCameras = GetSceneCameras();

	cycle++;
	cycle = cycle % sceneCameras.length;

	var camName = Node.ShortName(sceneCameras[cycle]);

	Node.Select(sceneCameras[cycle])

	var cmd = 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';
	RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from " + camName, 2000)
	Space.Unselect()
}

function GetSceneCameras()
{
	var cams = [];
	var scene = Space.CurrentScene();
	for(var i=0;i<Node.SubObjectCount(scene);i++) {
		var node = scene + "/" + Node.SubObject(scene, i);
		if(Node.IsCamera(node)) {
			cams.push(node);
		}
	}
	return cams;
}
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Cycle Camera Views

Post by trueBlue »

Sweeeet! :bananacheers:
Can something be done with the Status Message running when there is no Camera in the scene?
Also, the EntryPoint camera:
Does not work with the Status Massage by name?
Does not seem to set the view, sometimes?... Still testing this
If possible, it would be great if the EntrPoint camera sets the view first! .... perfecto :mrgreen:
User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Cycle Camera Views

Post by clintonman »

"Can something be done with the Status Message running when there is no Camera in the scene?"

if(sceneCameras.length == 0) return;

"Does not work with the Status Massage by name?"
I think status doesn't work if you switch too quickly between them. Try going slowly to see if it shows.

"If possible, it would be great if the EntrPoint camera sets the view first!"
No way I know of except I think if you delete and then undo on the other cameras it will push them back to be the last things in the scene.
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Cycle Camera Views

Post by trueBlue »

Try with no cameas and an EntrPoint camera in a scene
User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Cycle Camera Views

Post by clintonman »

trueBlue wrote: 22 Jan 2022, 05:19 Try with no cameas and an EntrPoint camera in a scene
It shows the view from the entry point camera, cause there's no other cameras.
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Cycle Camera Views

Post by trueBlue »

I tried putting in

Code: Select all

if(sceneCameras.length == 0) return;
but i get undefined errors

When there is a Camera or Cameras in the scene, this script seems to work okay on first runs
Also, if a Camera is selected

But there is something odd going on with this script when you remove all cameras from the scene and rerun it
The new camera is not being selected and so the script does not work
If I open and close the script, it starts to work
Try testing with and without cameras in the scene
Comment out //Space.Unselect()
Make sure that any new cameras are unselected before running this script
You should see that nothing gets selected
User avatar
clintonman
Captain
Posts: 5422
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Cycle Camera Views

Post by clintonman »

trueBlue wrote: 22 Jan 2022, 16:46 I tried putting in

Code: Select all

if(sceneCameras.length == 0) return;
but i get undefined errors

When there is a Camera or Cameras in the scene, this script seems to work okay on first runs
Also, if a Camera is selected

But there is something odd going on with this script when you remove all cameras from the scene and rerun it
The new camera is not being selected and so the script does not work
If I open and close the script, it starts to work
Try testing with and without cameras in the scene
Comment out //Space.Unselect()
Make sure that any new cameras are unselected before running this script
You should see that nothing gets selected
Here it is with the added line which also fixes the bug.
Without the 'if(sceneCameras.length == 0) return;' line it is dividing by 0 giving invalid value for cycle.

Code: Select all

var cycle = -1;

function Execute(params) 
{
	var util = System.CreateDO('Clintons3D Package/Utility functions')
	if (typeof (Clintons3dPlugin) == "undefined") {
		System.Alert("Clintons3dPlugin is Required!\n\nInstall the Clintons3dPlugin.rsx in the Package Manager");
		params.SetTerminationFlag()
		return;
	}
	if (Node.SubObjectCount("/D3DView") == 0) return;

	var sceneCameras = GetSceneCameras();

	if(sceneCameras.length == 0) return;

	cycle++;
	cycle = cycle % sceneCameras.length;

	var camName = Node.ShortName(sceneCameras[cycle]);

	Node.Select(sceneCameras[cycle])

	var cmd = 'UUFS = Node.AccessFnSet("Widgets/UUFunctionSet");UUFS.SetCamera();';
	RsApp.RunScriptBuffer(cmd);
	util.SetStatusMessage("Viewing from " + camName, 2000)
	Space.Unselect()
}

function GetSceneCameras()
{
	var cams = [];
	var scene = Space.CurrentScene();
	for(var i=0;i<Node.SubObjectCount(scene);i++) {
		var node = scene + "/" + Node.SubObject(scene, i);
		if(Node.IsCamera(node)) {
			cams.push(node);
		}
	}
	return cams;
}
Clinton Reese

http://clintons3d.com
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Cycle Camera Views

Post by trueBlue »

Awesome! :bananathumb:
Works perfect, thank you!
Cam Toolbar.png
You do not have the required permissions to view the files attached to this post.
User avatar
trueBlue
Captain
Posts: 5208
Joined: 06 Jul 2009, 22:50
Type the number ten into the box: 10

Re: Cycle Camera Views

Post by trueBlue »

Using your cycle script, I added Cycle Select to your Select scripts
Select Cycle panel.png
Can you take a look at the scripts?
I think the 3D Groups and Skeletons work pretty well
Maybe there is a better way
You do not have the required permissions to view the files attached to this post.
Post Reply