Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why will not my script boot up everytime i open AE?

Explorer ,
Dec 06, 2013 Dec 06, 2013

As the header say i need to reload my script everytime i open AE. My script is a UI that i have doced to the side, however still I need to reload it every time i open AE. I have also tried to save the workspace as a preset, but still have to reload to use it.

I dont need to do this with other scripts, I is just my script.

Any tips?

Cheers

TOPICS
Scripting
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Dec 09, 2013 Dec 09, 2013

Hi JesB,

unfortunately... no ;(

Apparently you are confused with what is called "app.project.activeItem".

If you define a variable projItem = app.project.activeItem, at the moment the code is executed, it might point to, say, comp1.

Ten minutes later, the user has down something, the currently selected item is say, comp2, so app.project.activeItem is equal to comp2, but your projItem variable is STILL pointing to comp1, which has been the activeItem in the past, but no longer is (and even worse, it

...
Translate
Advocate ,
Dec 06, 2013 Dec 06, 2013

If your script UI panel is docked into the AE interface and you save the current workspace, it should automatically load each time AE is launched or that workspace is selected. Do you have some kind of launch code that runs before your script UI is created in your script. My guess is something is interfering with your script launching itself each time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 06, 2013 Dec 06, 2013

Hi David

Yes, my script UI panel is docked into the AE interface and I have saved it as a new workspace.

The script starts directly at the UI code, so I'm guessing that the fault lies elsewhere. Something that is quite strange is that it works just fine with other scripts.

JesB

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 07, 2013 Dec 07, 2013

Maybe a conflicting function name/variable/global? Could be something as simple as a typo or stacking order issue. Mostly just guessing here. I really have no way of telling without seeing any code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 07, 2013 Dec 07, 2013

Of course, my mistake..

Here is all the code I have in the script: (I have only tested the code in CS6.)

{

function myScript(thisObj) {

          function myScript_buildUI(thisObj) {

                    var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Layer tools", undefined, {resizeable:true});

                    myPanel.spacing = 1;

                    myPanel.margins = [0,0,0,0];

                    myPanel.preferredSize = [30,0];

                    res="group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

                        grp1: Group{orientation: 'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

                               addSolid: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Solid.png'},\

                               addLight: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Light.png'},\

                               addCamera: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Camera.png'},\

                               addRig: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/RIG.png'},\

                               addNullObject: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Null_2.png'},\

                               addAdjustmentLayer: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Adjustment_Layer.png'},\

                               preCompose: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Pre-Compose.png'},\

                               unPreCompose: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Un-precompose.png'},\

                               settings: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Settings.png'},\

                              },\

                         },\

                    }";

                    //Add resource string to panel

                    myPanel.grp = myPanel.add(res);

                   

       //All variables:

        var addSolidCtrl = myPanel.grp.grp1.addSolid;

        var addLightCtrl = myPanel.grp.grp1.addLight;

        var addCameraCtrl = myPanel.grp.grp1.addCamera;

        var addRigCtrl = myPanel.grp.grp1.addRig;

        var addNullObjectCtrl = myPanel.grp.grp1.addNullObject;

        var addAdjustmentLayerCtrl = myPanel.grp.grp1.addAdjustmentLayer;

        var preComposeCtrl = myPanel.grp.grp1.preCompose;

        var unPreComposeCtrl = myPanel.grp.grp1.unPreCompose;

        var settingsCtrl = myPanel.grp.grp1.settings;

       

        addSolidCtrl.helpTip = " Add solid";

        addLightCtrl.helpTip = "Add point light (Shift-click for more options)";

        addCameraCtrl.helpTip = "Add camera";

        addRigCtrl.helpTip = "Add simple camera rig";

        addNullObjectCtrl.helpTip = "Add null object";

        addAdjustmentLayerCtrl.helpTip = "Add adjustment layer";

        preComposeCtrl.helpTip = "Pre-Compose";

        unPreComposeCtrl.helpTip = "Un-PreCompose";

        settingsCtrl.helpTip = "Help & settings";

       

        var proj = app.project.activeItem;

        if(proj instanceof CompItem) {

       

        //Add a black Solit to active Comp

        addSolidCtrl.onClick = function(){

            proj.layers.addSolid([0, 0, 0], "Black Solid", proj.width, proj.height, 1.0,);

            }

      

       //Add a Point Light to active Comp and Shift-Click function

      // mouse click event handler for the button

        addLightCtrl.addEventListener("click", function(k) {

          detect(k)

        });

        

        

        var ltWin;

        

        

        function detect(k) {

          var keyState = ScriptUI.environment.keyboardState;

          // if "shift" click the button, create a new window

          if (keyState.shiftKey){

            ltWin = new Window("palette", "Light options", undefined);

            var groupOne = ltWin.add("group", undefined, "GroupOne");

                   groupOne.orientation = "column";

            var optionBanner = groupOne.add("image", undefined, "/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/LightOptions.jpg", );

            var addParallel = groupOne.add("button", [0, 0, 250, 25], "Parallel light",);

            var addSpot = groupOne.add("button", [0, 0, 250, 25], "Spot light",);

            var addPoint = groupOne.add("button", [0, 0, 250, 25], "Point light",);

            var addAmbient = groupOne.add("button", [0, 0, 250, 25], "Ambient light",);

            ltWin.layout.layout(true);

            ltWin.center();

            ltWin.show();

           

            addParallel.onClick = function(){

            addParallel = proj.layers.addLight("Parallel Light", [960, 540]);

            addParallel.lightType = LightType.PARALLEL;

            addParallel.property("position").setValue([ 1040, 460, -666.6667]);

            return ltWin.close();

            }

        addSpot.onClick = function(){

            addSpot = proj.layers.addLight("Spot Light", [960, 540]);

            addSpot.lightType = LightType.SPOT

            addSpot.property("position").setValue([ 1040, 460, -666.6667]);

            return ltWin.close();

            }  

        addPoint.onClick = function(){

            addPoint = proj.layers.addLight("Point Light", [0, 0]);

            addPoint.lightType = LightType.POINT

            addPoint.property("position").setValue([ 1040, 460, -666.6667]);

            return ltWin.close();

        }

        addAmbient.onClick = function(){

            addAmbient = proj.layers.addLight("Ambient Light", [0, 0]);

            addAmbient.lightType = LightType.AMBIENT

            return ltWin.close();

            }

          }

     

          /* regular click to add a regluar point light*/

          else {

            var pointLight = proj.layers.addLight("Light", [0, 0]);

            pointLight.lightType = LightType.POINT;

            pointLight.property("position").setValue([ 1040, 460, -666.6667]);

          }

        }

                            

       //Add a Camera to active Comp

       addCameraCtrl.onClick = function(){

           var cam = proj.layers.addCamera("Camera", [960, 540]);

           cam.property("position").setValue([ 960, 540, -2666.6667]);

           }

      

       //execute() malty_SimpleCameraRig.jsxbin

       addRigCtrl.onClick = function(){

            //Open script with in another script code

            var file = new File('/c/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/malty_SimpleCameraRig.jsxbin');

            file.open("r");

            eval(file.read());

            file.close();

           }

       //Add a Null to active Comp

       addNullObjectCtrl.addEventListener ('click', function (k) {

        if (k.shiftKey) {

        proj.layers.addNull(); // shift is clicked = 2D Null Object

        }else{

          var nullObject = proj.layers.addNull();  // Normal click = 3D Null Object

          nullObject.threeDLayer = true;

    }

});

      

       //Add a Adjustment Layer to active Comp

       addAdjustmentLayerCtrl.onClick = function(){

           proj.layers.addSolid([1, 1, 1], "Adjustment Layer", 1920, 1080, 1.0,).adjustmentLayer = true;

           }

      

       //preCompose function

       preComposeCtrl.onClick = function(){

          

           var myLayers = proj.selectedLayers;

           if(myLayers.length > 0){

           var newInPoint = myLayers[0].inPoint;

           var newOutPoint = myLayers[0].outPoint;

           var newCompName = "Pre-comp ";

           var layerName = myLayers[0].name;

           if(layerName.length > 26) {

           layerName = layerName.substring(0, 26);

           }

           newCompName += layerName;

          

           var layerIndices = new Array();

           for (var i = 0; i < myLayers.length; i++) {

           layerIndices[layerIndices.length] = myLayers.index;

        if (myLayers.inPoint < newInPoint) newInPoint = myLayers.inPoint;

        if (myLayers.outPoint > newOutPoint) newOutPoint = myLayers.outPoint;

      }

 

  var newComp = proj.layers.precompose(layerIndices, newCompName, true );

      var preCompLayer = proj.selectedLayers[0];

      preCompLayer.inPoint = newInPoint;

      preCompLayer.outPoint = newOutPoint;

     

  }else{

    alert("Make sure you have one or more layers selected");

    }

  app.endUndoGroup();

}

        //Un-PreCompose function, will execute() Un-PreCompose.aex

        unPreComposeCtrl.onClick = function(){

         if(proj instanceof CompItem){//Verify that activeItem is a comp

         var curLayer, layerSel, layerSelLength;

         layerSel = proj.selectedLayers;

         layerSelLength = layerSel.length;

    

         for(var l = 0; l < layerSelLength; l++){

              curLayer = layerSel;

              if(curLayer.source instanceof CompItem){//It's a precomp

                  app.executeCommand (app.findMenuCommandId("Un-PreCompose..."));

              }else{//It's not a precomp

                    alert ("Please select a Pre-Composition in time line, and make sure you have Un-PreCompose from Batchframe Software installed"+"\n\nKeep in mind: This button is not always stable. Please try again!");

              }

         }

    }

            }

         //Settings/Help window

         settingsCtrl.onClick = function(){

                 var hwin = new Window("dialog", "Help and settings", undefined);

                 var hres = "group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

                                bannerImage: Image{text: 'Image', image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Banner.jpg'},\

                                about: StaticText{text:, properties:{multiline:true}},\

                                myImage: Image{text: 'Image', image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Description.png'},\

                                cc: Image{text: 'creative commons', image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/creative_commons.png'},\

                            }";

               

                  hwin.grp = hwin.add(hres);

                 

                  hwin.grp.about.text = "Layer tools"+

                  "\nCreated by: JesB © copyright 2013"+

                  "\n\nThis script was designed as a layer toolbar to create different layers quickly and easy."+

                  "\n\nESC key will exit this window.";

                 

                  hwin.grp.layout.layout(true);

                  hwin.center();

                  hwin.show();

             }

           }

 

                    //Setup panel sizing and make panel resizable

                    myPanel.layout.layout(true);

                    myPanel.grp.minimumSize = myPanel.grp.size;

                    myPanel.layout.resize();

                    myPanel.onResizing = myPanel.onResize = function () {this.layout.resize();}

                    return myPanel;

          }

          var myScriptPal = myScript_buildUI(thisObj);

          if ((myScriptPal != null) && (myScriptPal instanceof Window)) {

                    myScriptPal.center();

                    myScriptPal.show();

                    }

          }

          myScript(this);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 07, 2013 Dec 07, 2013

Hi JesB,

first try to give your main function a more specific name. If all your scripts are enclosed in a function called myScript(), no wonder your are in trouble !

Another major problem in your script is that you define proj (=activeItem ???) before anything else and if project is defined, then you define all the onClick functions. What if no activeItem when you launch the script ??

It just can't work that way.

If there is no activeItem at the moment you launched your script (like when you launch AE), then at best you have plenty of buttons with no events attached to them, or you have an error if no project (true project, not activeItem).

So first you shouldnt call activeItem "proj", it is very confusing.

Then do not define an activeItem object inside your main environment: its validity can be very short.

You must check activeItem EVERY TIME you need it (ie every time you click a button).

This means that you should replace

        var proj = app.project.activeItem;

        if(proj instanceof CompItem) {

        //Add a black Solit to active Comp

        addSolidCtrl.onClick = function(){

            proj.layers.addSolid([0, 0, 0], "Black Solid", proj.width, proj.height, 1.0,);

            }

         + all events inside the if (!!!)

          }

by   all events, with a if inside them (if needed):

        //Add a black Solit to active Comp

        addSolidCtrl.onClick = function(){

              if (app.project && app.project.activeItem instanceof CompItem) app.project.activeItem.layers.addSolid([0, 0, 0], "Black Solid", proj.width, proj.height, 1.0,);

               return;

            }

          // and so on for all events

// note: if you want to avoid name conflicts, instead of

function myScript(thisObj) {

/// some code

}

myScript(this);

you can use:

(function(thisObj){

// same code

})(this);

It both defines the function and executes it with the argument 'this'.

Xavier.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 08, 2013 Dec 08, 2013

Hi Xavier

Thank you very much for your help, I appreciate it.

When I get some free time I'll try out what you wrote.

and again thank you!

JesB

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 08, 2013 Dec 08, 2013

Hi again!

Ok, now i have tried what you said above!

Is this correct and what you meant? (Now I have changed proj to projItem)

{

function myScript(thisObj) {

          function myScript_buildUI(thisObj) {

                    var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Layer tools", undefined, {resizeable:true});

                    myPanel.spacing = 1;

                    myPanel.margins = [0,0,0,0];

                    myPanel.preferredSize = [30,0];

                    res="group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

                        grp1: Group{orientation: 'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

                               addSolid: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Solid.png'},\

                               addLight: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Light.png'},\

                               addCamera: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Camera.png'},\

                               addRig: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/RIG.png'},\

                               addNullObject: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Null_2.png'},\

                               addAdjustmentLayer: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Adjustment_Layer.png'},\

                               preCompose: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Pre-Compose.png'},\

                               unPreCompose: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Un-precompose.png'},\

                               settings: IconButton{text:'IconButton',size:[25, 25],properties: { style : 'toolbutton' },image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Settings.png'},\

                              },\

                         },\

                    }";

                    //Add resource string to panel

                    myPanel.grp = myPanel.add(res);

       //All variables:

        var addSolidCtrl = myPanel.grp.grp1.addSolid;

        var addLightCtrl = myPanel.grp.grp1.addLight;

        var addCameraCtrl = myPanel.grp.grp1.addCamera;

        var addRigCtrl = myPanel.grp.grp1.addRig;

        var addNullObjectCtrl = myPanel.grp.grp1.addNullObject;

        var addAdjustmentLayerCtrl = myPanel.grp.grp1.addAdjustmentLayer;

        var preComposeCtrl = myPanel.grp.grp1.preCompose;

        var unPreComposeCtrl = myPanel.grp.grp1.unPreCompose;

        var settingsCtrl = myPanel.grp.grp1.settings;

        addSolidCtrl.helpTip = " Add solid";

        addLightCtrl.helpTip = "Add point light (Shift-click for more options)";

        addCameraCtrl.helpTip = "Add camera";

        addRigCtrl.helpTip = "Add simple camera rig";

        addNullObjectCtrl.helpTip = "Add null object";

        addAdjustmentLayerCtrl.helpTip = "Add adjustment layer";

        preComposeCtrl.helpTip = "Pre-Compose";

        unPreComposeCtrl.helpTip = "Un-PreCompose";

        settingsCtrl.helpTip = "Help & settings";

        var projItem = app.project.activeItem;

        if(projItem instanceof CompItem) {

        //Add a black Solit to active Comp

        addSolidCtrl.onClick = function(){

            if (app.project && app.project.activeItem instanceof CompItem) projItem.layers.addSolid([0, 0, 0], "Black Solid", projItem.width, projItem.height, 1.0,);

            }

       //Add a Point Light to active Comp and Shift-Click function

      // mouse click event handler for the button

        addLightCtrl.addEventListener("click", function(k) {

          detect(k)

        });

        var ltWin;

        function detect(k) {

          var keyState = ScriptUI.environment.keyboardState;

          // if "shift" click the button, create a new window

          if (keyState.shiftKey){

            ltWin = new Window("palette", "Light options", undefined);

            var groupOne = ltWin.add("group", undefined, "GroupOne");

                   groupOne.orientation = "column";

            var optionBanner = groupOne.add("image", undefined, "/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/LightOptions.jpg", );

            var addParallel = groupOne.add("button", [0, 0, 250, 25], "Parallel light",);

            var addSpot = groupOne.add("button", [0, 0, 250, 25], "Spot light",);

            var addPoint = groupOne.add("button", [0, 0, 250, 25], "Point light",);

            var addAmbient = groupOne.add("button", [0, 0, 250, 25], "Ambient light",);

            ltWin.layout.layout(true);

            ltWin.center();

            ltWin.show();

            addParallel.onClick = function(){

            if (app.project && app.project.activeItem instanceof CompItem);

            addParallel = projItem.layers.addLight("Parallel Light", [960, 540]);

            addParallel.lightType = LightType.PARALLEL;

            addParallel.property("position").setValue([ 1040, 460, -666.6667]);

            return ltWin.close();

            }

        addSpot.onClick = function(){

            if (app.project && app.project.activeItem instanceof CompItem);

            addSpot = projItem.layers.addLight("Spot Light", [960, 540]);

            addSpot.lightType = LightType.SPOT

            addSpot.property("position").setValue([ 1040, 460, -666.6667]);

            return ltWin.close();

            }  

        addPoint.onClick = function(){

            if (app.project && app.project.activeItem instanceof CompItem);

            addPoint = projItem.layers.addLight("Point Light", [0, 0]);

            addPoint.lightType = LightType.POINT

            addPoint.property("position").setValue([ 1040, 460, -666.6667]);

            return ltWin.close();

        }

        addAmbient.onClick = function(){

            if (app.project && app.project.activeItem instanceof CompItem);

            addAmbient = projItem.layers.addLight("Ambient Light", [0, 0]);

            addAmbient.lightType = LightType.AMBIENT

            return ltWin.close();

            }

          }

          /* regular click to add a regluar point light*/

          else {

           if (app.project && app.project.activeItem instanceof CompItem);

            var pointLight = projItem.layers.addLight("Light", [0, 0]);

            pointLight.lightType = LightType.POINT;

            pointLight.property("position").setValue([ 1040, 460, -666.6667]);

          }

        }

       //Add a Camera to active Comp

       addCameraCtrl.onClick = function(){

           if (app.project && app.project.activeItem instanceof CompItem);

           var cam = projItem.layers.addCamera("Camera", [960, 540]);

           cam.property("position").setValue([ 960, 540, -2666.6667]);

           }

       //execute() malty_SimpleCameraRig.jsxbin

       addRigCtrl.onClick = function(){

           if (app.project && app.project.activeItem instanceof CompItem);

            //Open script with in another script code

            var file = new File('/c/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/malty_SimpleCameraRig.jsxbin');

            file.open("r");

            eval(file.read());

            file.close();

           }

       //Add a Null to active Comp

       addNullObjectCtrl.addEventListener ('click', function (k) {

        if (k.shiftKey) {

        if (app.project && app.project.activeItem instanceof CompItem) projItem.layers.addNull(); // shift is clicked = 2D Null Object

        }else{

          if (app.project && app.project.activeItem instanceof CompItem);

          var nullObject = projItem.layers.addNull();  // Normal click = 3D Null Object

          nullObject.threeDLayer = true;

    }

});

       //Add a Adjustment Layer to active Comp

       addAdjustmentLayerCtrl.onClick = function(){

           if (app.project && app.project.activeItem instanceof CompItem) projItem.layers.addSolid([1, 1, 1], "Adjustment Layer", 1920, 1080, 1.0,).adjustmentLayer = true;

           }

       //preCompose function

       preComposeCtrl.onClick = function(){

           if (app.project && app.project.activeItem instanceof CompItem);

           var myLayers = projItem.selectedLayers;

           if(myLayers.length > 0){

           var newInPoint = myLayers[0].inPoint;

           var newOutPoint = myLayers[0].outPoint;

           var newCompName = "Pre-comp ";

           var layerName = myLayers[0].name;

           if(layerName.length > 26) {

           layerName = layerName.substring(0, 26);

           }

           newCompName += layerName;

           var layerIndices = new Array();

           for (var i = 0; i < myLayers.length; i++) {

           layerIndices[layerIndices.length] = myLayers.index;

        if (myLayers.inPoint < newInPoint) newInPoint = myLayers.inPoint;

        if (myLayers.outPoint > newOutPoint) newOutPoint = myLayers.outPoint;

      }

  var newComp = projItem.layers.precompose(layerIndices, newCompName, true );

      var preCompLayer = projItem.selectedLayers[0];

      preCompLayer.inPoint = newInPoint;

      preCompLayer.outPoint = newOutPoint;

  }else{

    alert("Make sure you have one or more layers selected");

    }

  app.endUndoGroup();

}

        //Un-PreCompose function, will execute() Un-PreCompose.aex

        unPreComposeCtrl.onClick = function(){

            if (app.project && app.project.activeItem instanceof CompItem);

         if(projItem instanceof CompItem){//Verify that activeItem is a comp

         var curLayer, layerSel, layerSelLength;

         layerSel = projItem.selectedLayers;

         layerSelLength = layerSel.length;

         for(var l = 0; l < layerSelLength; l++){

              curLayer = layerSel;

              if(curLayer.source instanceof CompItem){//It's a precomp

                  app.executeCommand (app.findMenuCommandId("Un-PreCompose..."));

              }else{//It's not a precomp

                    alert ("Please select a Pre-Composition in time line, and make sure you have Un-PreCompose from Batchframe Software installed"+"\n\nKeep in mind: This button is not always stable. Please try again!");

              }

         }

    }

            }

         //Settings/Help window

         settingsCtrl.onClick = function(){

             if (app.project && app.project.activeItem instanceof CompItem);

                 var hwin = new Window("dialog", "Help and settings", undefined);

                 var hres = "group{orientation:'column', alignment:['fill', 'fill'], alignChildren:['fill', 'fill'],\

                                bannerImage: Image{text: 'Image', image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Banner.jpg'},\

                                about: StaticText{text:, properties:{multiline:true}},\

                                myImage: Image{text: 'Image', image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/Description.png'},\

                                cc: Image{text: 'creative commons', image:'/C/Program Files/Adobe/Adobe After Effects CS6/Support Files/Scripts/ScriptUI Panels/Layer_tools Icons/creative_commons.png'},\

                            }";

                  hwin.grp = hwin.add(hres);

                  hwin.grp.about.text = "Layer tools"+

                  "\nCreated by: JesB © copyright 2013"+

                  "\n\nThis script was designed as a layer toolbar to create different layers quickly and easy."+

                  "\n\nESC key will exit this window.";

                  hwin.grp.layout.layout(true);

                  hwin.center();

                  hwin.show();

             }

           }

                    //Setup panel sizing and make panel resizable

                    myPanel.layout.layout(true);

                    myPanel.grp.minimumSize = myPanel.grp.size;

                    myPanel.layout.resize();

                    myPanel.onResizing = myPanel.onResize = function () {this.layout.resize();}

                    return myPanel;

          }

          var myScriptPal = myScript_buildUI(thisObj);

          if ((myScriptPal != null) && (myScriptPal instanceof Window)) {

                    myScriptPal.center();

                    myScriptPal.show();

                    }

          }

          myScript(this);

}

JesB

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 09, 2013 Dec 09, 2013

Hi JesB,

unfortunately... no ;(

Apparently you are confused with what is called "app.project.activeItem".

If you define a variable projItem = app.project.activeItem, at the moment the code is executed, it might point to, say, comp1.

Ten minutes later, the user has down something, the currently selected item is say, comp2, so app.project.activeItem is equal to comp2, but your projItem variable is STILL pointing to comp1, which has been the activeItem in the past, but no longer is (and even worse, it is may be now invalid - for instance the user has deleted it).

You need to check the activeItem every time you need it.

So you should not define projItem AT ALL in the body of your main function : remove it completely.

Only upon events (onClick etc) you must check whether there is an activeItem and see if the particular action can be done with the current app.project.activeItem.

So, after you have defined all your variables:

//All variables:

        var addSolidCtrl = myPanel.grp.grp1.addSolid;

        var addLightCtrl = myPanel.grp.grp1.addLight;

        var addCameraCtrl = myPanel.grp.grp1.addCamera;

        etc, etc,

define your events straight away, like this:

myBtn.onClick = function()

{

     if (app.project && app.project.activeItem instanceof CompItem)

     {

          var comp = app.project.activeItem;

          // do something with that comp

          }

     else

     {

          // alert, or simply do nothing

          };

     return;

     };

You can also do:

myBtn.onClick = function()

{

     if (!app.project || !(app.project.activeItem instanceof CompItem)) return; // exit, there is nothing to do

     var comp = app.project.activeItem;

     // do something with that comp

     //

     return;

     };

Xavier.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 10, 2013 Dec 10, 2013
LATEST

Hi Xavier

Now I understood what you meant!

Thank you very much for your help, I really appreciate it.

JesB

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines