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

Treeview selection

Explorer ,
Jul 26, 2017 Jul 26, 2017

Copy link to clipboard

Copied

Having a small issue that I'm hoping easily solvable.

myBtn.onClick = function(){

var Text = myTree.selection.text;

var myComp = app.project.activeItem;

myComp.layer("Text1").property("ADBE Text Properties").property("ADBE Text Document").setValue(Text);

}

This works great, but what I want it to do.

In myTree I have 2 Nodes (male, female), in those I have 3 Nodes I have (tops, bottoms and shoes).

I want to be able to select a Top so that it changes Text1, if I change Bottoms it will change Text2, if I change Shoes, it will change Text3.

I've tried changing this var Text = myTree.selection.text; I thought it would be as simple as changing it to var Text = myTree.male.tops.selection.text; but it appears that it's not as simple as that.

Does anyone know how you can specifically tell it that if A selected Item in Node is true, use selected Item. If not that don't do anything.

TOPICS
Scripting

Views

584

Translate

Translate

Report

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 ,
Jul 29, 2017 Jul 29, 2017

Copy link to clipboard

Copied

You could check for selected Items parent and see if it validates. Simple example:

if (parent.type === "node" && parent === femaleNode) {

    alert("It's a womens world!")

} else {

    alert("You picked the wrong stuff pal!")

}

And here's a more finished script for you to test. Hope it helps.

(function (thisObj) {

    scriptBuildUI(thisObj)

    function scriptBuildUI(thisObj) {

        var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script", undefined, {

            resizeable: true

        });

        var myTree = win.add("treeview", [0, 0, 150, 150]);

        var maleNode = myTree.add("node", "Male stuff");

        var maleItems = ["Beer", "Muscules", "Hangover"];

        addItems(maleNode, maleItems);

        var femaleNode = myTree.add("node", "Female stuff");

        var femaleItems = ["Bra", "Panties", "Bikini"]

        addItems(femaleNode, femaleItems);

        maleNode.expanded = true;

        femaleNode.expanded = true;

        var myBtn = win.add("button", undefined, "Do it")

        myBtn.onClick = function () {

            if (myTree.selection) {

                var selection = myTree.selection;

                var parent = selection.parent;

                if (parent.type === "node" && parent === femaleNode) {

                    alert("It's a womens world!")

                } else {

                    alert("You picked the wrong stuff pal!")

                }

            }

        }

        win.onResizing = win.onResize = function () {

            this.layout.resize();

        };

        win instanceof Window

            ? (win.center(), win.show()) : (win.layout.layout(true), win.layout.resize());

    }

    function addItems(treeNode, items) {

        for (var i = 0, il = items.length; i < il; i++) {

            treeNode.add("item", items);

        }

    }

})(this);

Votes

Translate

Translate

Report

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 ,
Jul 30, 2017 Jul 30, 2017

Copy link to clipboard

Copied

LATEST

Cheers for this, I'll test this out tomorrow.

I forget like Java and Javascript expression in after effects, it pretty much the same thing in your script. I'm an idiot for not thinking of that. I've just gotten used to listbox and dropbox and I was trying to treat it as a children item instead and thought you have to reference the children.

Votes

Translate

Translate

Report

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