I need help with my script

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
maximumrfan
Posts: 8
Joined: September 16th, 2010, 8:13 pm

I have been working on my "MRFCameraRig" script for a while, and for some reason, any time I add something to it, something else fails. I added a user interface to it the first time, and then the user interface failed on every screen except for my big monitor. Now I finally got the user interface down, but the heart of it (the camera rig creator) will not work.
Link to the script : http://secretnetworkc2c.maximumrfan.ope ... nload=true
The code that has worked for me every time except for now is as followed:

var proj = app.project;
var undoStr = "MRFCameraRig Simple Version";
if (proj){
var myComp = app.project.activeItem;
if (myComp != null && (myComp instanceof CompItem)){
app.beginUndoGroup(undoStr);
var w = myComp.width /2 ;
var h = myComp.height /2 ;
var newCamera = myComp.layers.addCamera("MRFCamera",[w,h]);
newCamera.position.setValue([w,h]);
var myLayer = myComp.selectedLayers;
if (myLayer) {
var newNull = myComp.layers.addNull();
newNull.source.name = "MRFCameraRig";
newNull.threeDLayer = true;
newNull.shy = false;
newNull.enabled = true;
newCamera.parent = newNull;
var URC = newNull("Effects").addProperty("Checkbox Control");
URC.name = 'Use Rotation Controls';
URC.value = true
var pitch = newNull("Effects").addProperty("Angle Control");
pitch.name = 'X Rotation';
var heading = newNull("Effects").addProperty("Angle Control");
heading.name = 'Y Rotation';
var bank = newNull("Effects").addProperty("Angle Control");
bank.name = 'Z Rotation';
var tracking = newNull("Effects").addProperty("ADBE Slider Control");
tracking.name = 'Tracking (Zoom)';
tracking.slider.setValue(0);
var UPC = newNull("Effects").addProperty("Checkbox Control");
UPC.name = 'Use Position Controls'
var xPosition = newNull("Effects").addProperty("ADBE Slider Control");
xPosition.name = 'X Position';
xPosition.slider.setValue([w]);
var yPosition = newNull("Effects").addProperty("ADBE Slider Control");
yPosition.name = 'Y Position';
yPosition.slider.setValue([h]);
var zPosition = newNull("Effects").addProperty("ADBE Slider Control");
zPosition.name = 'Z Position';
zPosition.slider.setValue(0);
var camPositionExpression = 'UPC = effect("Use Position Controls")("Checkbox"); \r x = effect("X Position")("Slider"); \r y = effect("Y Position")("Slider"); \r z = effect("Z Position")("Slider"); \r cPV = value; \r dPV = value; \r if(UPC == 0){cPV = dPV} else {cPV = [x, y, z]};'
newNull.position.expression = camPositionExpression;
var positionExpression = 'value - [0, 0,cameraOption.zoom] + [0, 0,thisComp.layer("MRFCameraRig").effect("Tracking (Zoom)")("Slider")];';
newCamera.position.expression = positionExpression;
var orientationExpression = 'URC = effect("Use Rotation Controls")("Checkbox"); \r x = effect("X Rotation")("Angle"); \r y = effect("Y Rotation")("Angle"); \r z = effect("Z Rotation")("Angle"); \r cRV = value; \r dRV = value; \r if(URC == 0){cRV = dRV} else {cRV = [x, y, z];}';
newNull.orientation.expression = orientationExpression;
alert("Created by MRFPlugins." + "\r" +
"©2010-2012 Fiber Optic Shoe." + "\r" +
"Inspired by a tutorial on Maltaanon.com." + "\r" +
"http://www.youtube.com/maximumrfan." + "\r" +
"http://www.twitter.com/mdogtwilighter." + "\r" +
"Thanks to the people on aenhancers.com who helped me get this thing working correctly!", "MRFCameraRig"
);
app.endUndoGroup();
} else {
alert("Select a layer for crying out loud!", "MRFCameraRig");
}
} else {
alert("Select a comp to use the script silly!", "MRFCameraRig");
}
}
else
{
alert("Make a new project to use this awesometacular script!", "MRFCameraRig");
}
}

If you want to edit the script, please reply with a link to the script. :)
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Something like this maybe?

Code: Select all

{
		// Created By MRFPlugins
		// ©2010-2012 Fiber Optic Shoe
		// http://www.youtube.com/maximumrfan/
		// http://www.twitter.com/mdogtwilighter/
		// Inspired by a tutorial on Maltaanon.com
		// If you want to be credited, then you need to (A) add a comented line above places where you added code with your username (B) reply to the thread with this file attached to the reply (C) in the reply tell me your twitter and youtube usernames (if you have them)
		// Please don't steal my code. I have worked a long time on it. 
	
	function buildUI(thisObj)
	{
		var pal = (thisObj instanceof Panel) ? thisObj : new Window(thisObj, "MRFCameraRig", undefined, { resizeable:true } );
		if (pal != null) {		
			var res = 
			"""group { 
				orientation:'column', alignment:['fill','fill'], 
				tp: Panel {
					type:'tabbedpanel', alignment:['fill','fill'], alignChildren:['fill','center'], 
					tpBasic: Panel {
						type:'tab', text:'Create', alignChildren:['center','center'],
						uwc: Checkbox { text:'Use Wiggler Controls' }, 
						btnCreate: Button { text:'Create' }, 
					},
					tpAdvanced: Panel {
						type:'tab', text:'Change Log', alignChildren:['center','center'],
						btnVersion1: Button { text:'Version 1' },
						btnVersion2: Button { text:'Version 2' },
						btnVersion3: Button { text:'Version 3' },						
					},
					tpMore: Panel {
						type:'tab', text:'More', alignChildren:['center','center'],
						btnCredits: Button { text:'Credits' },
						btnWUT: Button { text:'Why Use MRFCameraRig?' },
						
					},
				},
			}""";
			var container = pal.myGroup = pal.add(res);
			
			//We need the Create button function
			
			// Set up the callbacks
			container.tp.tpBasic.btnCreate.onClick = makeRig;
			container.tp.tpAdvanced.btnVersion1.onClick = function () {alert("Inital Release Version", "Version 1 Features");}
			container.tp.tpAdvanced.btnVersion2.onClick = function () {alert("Added User Interface", "Version 2 Features");}
			container.tp.tpAdvanced.btnVersion3.onClick = function () {alert("Updated User Interface, Fixed UI Scaling Bug, Works In The 'ScriptUI Panels' Folder", "Version 3 Features");}
			container.tp.tpMore.btnCredits.onClick = function () {alert("Created by MRFPlugins" + "\r" + "©2010-2012 Fiber Optic Shoe" + "\r" + "Inspired by a tutorial on Maltaanon.com", "MRFCameraRig");}
			container.tp.tpMore.btnWUT.onClick = function () {alert("You may not know this, but the camera in after effects is pretty flawed. Sure it's good for moving back and forth, left and right, but if you want to add curves it gets pretty tricky. You have to monitor every keyframe or else you could mess it up." + "\r" + "This is where a camera rig comes in. A camera rig is comprised of a 3d null object, and a camera that is parented to the null object. This eliminates the 'swoop' effect that the normal camera has.", "MRFCameraRig");}			
			
			pal.layout.layout(true);
			container.minimumSize = container.size;
			
			pal.onResizing = pal.onResize = function ()
			{
				this.layout.resize();
			}
		}
		
		return pal;
	}

	function makeRig() {
		var proj = app.project;
		var undoStr = "MRFCameraRig Simple Version";
		if (proj){
			var myComp = app.project.activeItem;
			if (myComp != null && (myComp instanceof CompItem)){
				app.beginUndoGroup(undoStr);
				var w = myComp.width /2 ;
				var h = myComp.height /2 ;
				var newCamera = myComp.layers.addCamera("MRFCamera",[w,h]);
				newCamera.position.setValue([w,h]);
				var myLayer = myComp.selectedLayers;
				if (myLayer) {
					var newNull = myComp.layers.addNull();
					newNull.source.name = "MRFCameraRig";
					newNull.threeDLayer = true;
					newNull.shy = false;
					newNull.enabled = true;
					newCamera.parent = newNull;
					var URC = newNull("Effects").addProperty("Checkbox Control");
					URC.name = 'Use Rotation Controls';
					URC.value = true
					var pitch = newNull("Effects").addProperty("Angle Control");
					pitch.name = 'X Rotation';			
					var heading = newNull("Effects").addProperty("Angle Control");
					heading.name = 'Y Rotation';
					var bank = newNull("Effects").addProperty("Angle Control");
					bank.name = 'Z Rotation';
					var tracking = newNull("Effects").addProperty("ADBE Slider Control");
					tracking.name = 'Tracking (Zoom)';
					tracking.slider.setValue(0);				
					var UPC = newNull("Effects").addProperty("Checkbox Control");
					UPC.name = 'Use Position Controls'
					var xPosition = newNull("Effects").addProperty("ADBE Slider Control");
					xPosition.name = 'X Position';
					xPosition.slider.setValue([w]);				
					var yPosition = newNull("Effects").addProperty("ADBE Slider Control");
					yPosition.name = 'Y Position';
					yPosition.slider.setValue([h]);
					var zPosition = newNull("Effects").addProperty("ADBE Slider Control");
					zPosition.name = 'Z Position';
					zPosition.slider.setValue(0);
					var camPositionExpression = 'UPC = effect("Use Position Controls")("Checkbox"); \r x = effect("X Position")("Slider"); \r y = effect("Y Position")("Slider"); \r z = effect("Z Position")("Slider"); \r cPV = value; \r dPV = value; \r if(UPC == 0){cPV = dPV} else {cPV = [x, y, z]};'
					newNull.position.expression = camPositionExpression;
					var positionExpression = 'value - [0, 0,cameraOption.zoom] + [0, 0,thisComp.layer("MRFCameraRig").effect("Tracking (Zoom)")("Slider")];';
					newCamera.position.expression = positionExpression;
					var orientationExpression = 'URC = effect("Use Rotation Controls")("Checkbox"); \r x = effect("X Rotation")("Angle"); \r y = effect("Y Rotation")("Angle"); \r z = effect("Z Rotation")("Angle"); \r cRV = value; \r dRV = value; \r if(URC == 0){cRV = dRV} else {cRV = [x, y, z];}';
					newNull.orientation.expression = orientationExpression;
					alert("Created by MRFPlugins." + "\r" +
					"©2010-2012 Fiber Optic Shoe." + "\r" +
					"Inspired by a tutorial on Maltaanon.com." + "\r" +
					"http://www.youtube.com/maximumrfan." + "\r" +
					"http://www.twitter.com/mdogtwilighter." + "\r" +
					"Thanks to the people on aenhancers.com who helped me get this thing working correctly!", "MRFCameraRig");
					app.endUndoGroup();
				} else {
					alert("Select a layer for crying out loud!", "MRFCameraRig");
				}
			} else {
				alert("Select a comp to use the script silly!", "MRFCameraRig");
			}
		} else {
			alert("Make a new project to use this awesometacular script!", "MRFCameraRig");
		}
	}
	
	
	// main code:
	var win = null;
	
	if (this instanceof Panel)
		win = buildUI(this);
	else
		win = buildUI("palette");
	if (win != null) {
		if (win instanceof Window)
			win.show();
		else
			win.layout.layout(true);
	}
}
maximumrfan
Posts: 8
Joined: September 16th, 2010, 8:13 pm

Paul Tuersley wrote:Something like this maybe?

Code: Select all

{
		// Created By MRFPlugins
		// ©2010-2012 Fiber Optic Shoe
		// http://www.youtube.com/maximumrfan/
		// http://www.twitter.com/mdogtwilighter/
		// Inspired by a tutorial on Maltaanon.com
		// If you want to be credited, then you need to (A) add a comented line above places where you added code with your username (B) reply to the thread with this file attached to the reply (C) in the reply tell me your twitter and youtube usernames (if you have them)
		// Please don't steal my code. I have worked a long time on it. 
	
	function buildUI(thisObj)
	{
		var pal = (thisObj instanceof Panel) ? thisObj : new Window(thisObj, "MRFCameraRig", undefined, { resizeable:true } );
		if (pal != null) {		
			var res = 
			"""group { 
				orientation:'column', alignment:['fill','fill'], 
				tp: Panel {
					type:'tabbedpanel', alignment:['fill','fill'], alignChildren:['fill','center'], 
					tpBasic: Panel {
						type:'tab', text:'Create', alignChildren:['center','center'],
						uwc: Checkbox { text:'Use Wiggler Controls' }, 
						btnCreate: Button { text:'Create' }, 
					},
					tpAdvanced: Panel {
						type:'tab', text:'Change Log', alignChildren:['center','center'],
						btnVersion1: Button { text:'Version 1' },
						btnVersion2: Button { text:'Version 2' },
						btnVersion3: Button { text:'Version 3' },						
					},
					tpMore: Panel {
						type:'tab', text:'More', alignChildren:['center','center'],
						btnCredits: Button { text:'Credits' },
						btnWUT: Button { text:'Why Use MRFCameraRig?' },
						
					},
				},
			}""";
			var container = pal.myGroup = pal.add(res);
			
			//We need the Create button function
			
			// Set up the callbacks
			container.tp.tpBasic.btnCreate.onClick = makeRig;
			container.tp.tpAdvanced.btnVersion1.onClick = function () {alert("Inital Release Version", "Version 1 Features");}
			container.tp.tpAdvanced.btnVersion2.onClick = function () {alert("Added User Interface", "Version 2 Features");}
			container.tp.tpAdvanced.btnVersion3.onClick = function () {alert("Updated User Interface, Fixed UI Scaling Bug, Works In The 'ScriptUI Panels' Folder", "Version 3 Features");}
			container.tp.tpMore.btnCredits.onClick = function () {alert("Created by MRFPlugins" + "\r" + "©2010-2012 Fiber Optic Shoe" + "\r" + "Inspired by a tutorial on Maltaanon.com", "MRFCameraRig");}
			container.tp.tpMore.btnWUT.onClick = function () {alert("You may not know this, but the camera in after effects is pretty flawed. Sure it's good for moving back and forth, left and right, but if you want to add curves it gets pretty tricky. You have to monitor every keyframe or else you could mess it up." + "\r" + "This is where a camera rig comes in. A camera rig is comprised of a 3d null object, and a camera that is parented to the null object. This eliminates the 'swoop' effect that the normal camera has.", "MRFCameraRig");}			
			
			pal.layout.layout(true);
			container.minimumSize = container.size;
			
			pal.onResizing = pal.onResize = function ()
			{
				this.layout.resize();
			}
		}
		
		return pal;
	}

	function makeRig() {
		var proj = app.project;
		var undoStr = "MRFCameraRig Simple Version";
		if (proj){
			var myComp = app.project.activeItem;
			if (myComp != null && (myComp instanceof CompItem)){
				app.beginUndoGroup(undoStr);
				var w = myComp.width /2 ;
				var h = myComp.height /2 ;
				var newCamera = myComp.layers.addCamera("MRFCamera",[w,h]);
				newCamera.position.setValue([w,h]);
				var myLayer = myComp.selectedLayers;
				if (myLayer) {
					var newNull = myComp.layers.addNull();
					newNull.source.name = "MRFCameraRig";
					newNull.threeDLayer = true;
					newNull.shy = false;
					newNull.enabled = true;
					newCamera.parent = newNull;
					var URC = newNull("Effects").addProperty("Checkbox Control");
					URC.name = 'Use Rotation Controls';
					URC.value = true
					var pitch = newNull("Effects").addProperty("Angle Control");
					pitch.name = 'X Rotation';			
					var heading = newNull("Effects").addProperty("Angle Control");
					heading.name = 'Y Rotation';
					var bank = newNull("Effects").addProperty("Angle Control");
					bank.name = 'Z Rotation';
					var tracking = newNull("Effects").addProperty("ADBE Slider Control");
					tracking.name = 'Tracking (Zoom)';
					tracking.slider.setValue(0);				
					var UPC = newNull("Effects").addProperty("Checkbox Control");
					UPC.name = 'Use Position Controls'
					var xPosition = newNull("Effects").addProperty("ADBE Slider Control");
					xPosition.name = 'X Position';
					xPosition.slider.setValue([w]);				
					var yPosition = newNull("Effects").addProperty("ADBE Slider Control");
					yPosition.name = 'Y Position';
					yPosition.slider.setValue([h]);
					var zPosition = newNull("Effects").addProperty("ADBE Slider Control");
					zPosition.name = 'Z Position';
					zPosition.slider.setValue(0);
					var camPositionExpression = 'UPC = effect("Use Position Controls")("Checkbox"); \r x = effect("X Position")("Slider"); \r y = effect("Y Position")("Slider"); \r z = effect("Z Position")("Slider"); \r cPV = value; \r dPV = value; \r if(UPC == 0){cPV = dPV} else {cPV = [x, y, z]};'
					newNull.position.expression = camPositionExpression;
					var positionExpression = 'value - [0, 0,cameraOption.zoom] + [0, 0,thisComp.layer("MRFCameraRig").effect("Tracking (Zoom)")("Slider")];';
					newCamera.position.expression = positionExpression;
					var orientationExpression = 'URC = effect("Use Rotation Controls")("Checkbox"); \r x = effect("X Rotation")("Angle"); \r y = effect("Y Rotation")("Angle"); \r z = effect("Z Rotation")("Angle"); \r cRV = value; \r dRV = value; \r if(URC == 0){cRV = dRV} else {cRV = [x, y, z];}';
					newNull.orientation.expression = orientationExpression;
					alert("Created by MRFPlugins." + "\r" +
					"©2010-2012 Fiber Optic Shoe." + "\r" +
					"Inspired by a tutorial on Maltaanon.com." + "\r" +
					"http://www.youtube.com/maximumrfan." + "\r" +
					"http://www.twitter.com/mdogtwilighter." + "\r" +
					"Thanks to the people on aenhancers.com who helped me get this thing working correctly!", "MRFCameraRig");
					app.endUndoGroup();
				} else {
					alert("Select a layer for crying out loud!", "MRFCameraRig");
				}
			} else {
				alert("Select a comp to use the script silly!", "MRFCameraRig");
			}
		} else {
			alert("Make a new project to use this awesometacular script!", "MRFCameraRig");
		}
	}
	
	
	// main code:
	var win = null;
	
	if (this instanceof Panel)
		win = buildUI(this);
	else
		win = buildUI("palette");
	if (win != null) {
		if (win instanceof Window)
			win.show();
		else
			win.layout.layout(true);
	}
}
Thank you! It works perfectly now! *adds your name to the credits section* :)
Post Reply