Page 1 of 1

3D to 2D ScreenSpace .1b

Posted: May 6th, 2012, 8:18 pm
by vidjuheffex
Hello all,
Posting my first script out there. Works pretty simply, you select a 3d layer, then click one of the two buttons ('Link' or 'Bake') and the net result is an animated 2D null at the layers screen-space. More info and a download link at http://vidjuheffex.com/scripts/

That said, I would love for some people to look at the code. I have been learning JavaScript only for a few weeks now. For example right now I have Link and Bake executing two separate functions when bake is the same with the exception of one additional step. Not sure what the best way to pass a Boolean into a function would be (or if that is even the right approach). Also, I cobbled many parts of this from scripts as I was learning (THANK YOU ALL) and I noticed that none of the checks in the code seem to work, those that for example tell you to please have a comp active etc. Are these just way out of whack or am I missing something simple here. Anyway I look forward to updating this script and making many more.

UPDATE: version 0.2b is up, prompts work properly! All of them! (thanks Paul!)

Re: 3D to 2D ScreenSpace .1b

Posted: May 9th, 2012, 4:24 am
by Paul Tuersley
You could either set up your onClicks this way:

Code: Select all

myPanel.butLink.onClick = function() {
 LinkOrBake(true);
};
//////////////
function LinkOrBake(link) {
 if (link) {
or you could query the text in the button that called the function:

Code: Select all

 myPanel.butLink.onClick = LinkOrBake;
///////////////////////////
function LinkOrBake() {
 if (this.text == "Link") {
Your alerts are possibly failing because you have a variable called scriptName that you haven't defined. BTW alerts only have titles on Windows.

If you turn on "Enable Javascript Debugger" in the General prefs you will get errors which should point you in the right direction, instead of it silently failing.

Paul

Re: 3D to 2D ScreenSpace .1b

Posted: May 10th, 2012, 7:57 pm
by vidjuheffex
thanks! I'll have to give that a shot.

Re: 3D to 2D ScreenSpace .1b

Posted: May 10th, 2012, 8:27 pm
by vidjuheffex
hey there, so I removed the scriptName portion and it worked, but then I wanted it to check for it's status as a 3d layer,

if ((activeItem == null) || !(activeItem instanceof CompItem)) {
alert("Please select a composition.");
} else {
var selectedLayers = activeItem.selectedLayers[0];
if (activeItem.selectedLayers.length == 0) {
alert("Please select a 3d layer in the active comp.");
}

else if (activeItem.selectedLayers.threeDLayer == false){
alert("Please select a 3d layer in the active comp.");
}

the .threeDLayer check is not working? Any hints? (it's followed by the else that executes the script.

Re: 3D to 2D ScreenSpace .1b

Posted: May 10th, 2012, 11:57 pm
by Paul Tuersley
It should be:

else if (selectedLayers.threeDLayer == false){

Re: 3D to 2D ScreenSpace .1b

Posted: May 12th, 2012, 1:03 pm
by vidjuheffex
thanks!