Copy link to clipboard
Copied
Hi There,
I'm having some issues with a TreeView control in my UI that I cannot seem to resolve, and thought I would ask if anybody here has done this type of thing. My TreeView is made up of a collection of nodes, each with some child items. When the window containing the TreeView displays, I populate it with the nodes. I want to be able to script the selection within the TreeView, but I want the script to select a child items, not just their parent nodes. Is this possible? I know it is possible to selecting the parent nodes in a TreeView, but I cannot seem to get the code for selecting, via scripting, a child item of a node in a TreeView. Any thoughts on how to acheive this?
Thanks for your time and help!
Best,
Arie
Here is some of the code I am using for auto-selecting child items of nodes in the TreeView:
//Code to populate the TreeView (picker) goes here
...
//Highlight the last selection
for (var i=0; i < picker.items.length; i++)
{
if (picker.items.title == SAVED_TITLE){
picker.selection = picker.items;
picker.selection.expanded = true;
for (var x=0; x < picker.selection.items.length; x++) {
if (picker.selection.items
picker.selection = picker.selection.items
break;
}
}
break;
}
}
Copy link to clipboard
Copied
I ran a simple setup like this:
var win = new Window("palette", "Yo", undefined);
var t = win.add("treeview", [0, 0, 200, 75]);
var n = t.add("node", "Look inside");
var i = n.add("item", "hi");
var b = win.add("button", undefined, "Select");
b.onClick = function(){
try{
n.expanded = true; //Expand node
alert(i.reflect.properties); //Reveals the property options for the child item
i.selected = true; //selected is a valid property, but does not work
n.selected = true; //selected does work on a treeview node though
}catch(err){alert(err)};
};
win.center();
win.show();
The alert shows that "selected" is a property of the child item, yet it will not select the item. It will however select the node. It does not cause an error either. This might be a bug. https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
Copy link to clipboard
Copied
I figured as much. It would be nice to be able to highlite child items of a node via scripting. Not sure if it's a bug or by design. Either way, I'll file it at the link you provided. T
Thanks!
Arie
Copy link to clipboard
Copied
Hi, great posts and very helpful. I am trying to run scripts on my hard drive via clicking or double clicking an item in a treeview, does anyone know how to do this? I usually use Python, but need to create this ability. I have the treeview UI done with items and icons etc and is running in AFX CS6, I just need to understand how to get the items to run scripts.
Thanks
Copy link to clipboard
Copied
I am trying to run scripts on my hard drive via clicking or double clicking an item in a treeview, does anyone know how to do this?
A Treeview ListItem has an onDoubleClick event-handling callback.
treeViewControl.onDoubleClick = function(){alert(this.selection)}; //Alerts the item that was doubleclicked
Copy link to clipboard
Copied
Hi David, thanks for the reply and also thank you for the videos, they have been invaluable while i have been getting to grips with extendScript. Prior to your reply, I did manage to get it working with an onClick event handler, much the same as your post above, but need to change it to encompass a try catch, just in case there is an issue running the script from the treeview.
I am currently looking into a rclick context menu for the treeview to add extra functionality. Still very new to ExtendScript, but enjoying it so far.
So far.
Thanks again
Copy link to clipboard
Copied
Hi David or anyone that can help with this issue, I have my treeview working, but scripts being used/called from the dock palette version I have made that has the treeview of the scripts are stored on a drive (Z:) different to the install folder of After Effects (C:). The issue I have is that one or more scripts require resource folders and an error dialog (see attached image) is produced even though I have the resource folder for the script(s) in the folder on the Z drive. If I copy the script and its resource folder to the install folder....
C:\Program Files\Adobe\Adobe After Effects CS6\Support Files\Scripts\
...then the script runs with no issue when called from the File-Scripts menu in AFX.
I am wondering then, if there is a way to point towards the resource folder on the Z drive so that I can get the scripts to run correctly, or could you inform me of the correct process to resolve t his issue.
Thanks
Copy link to clipboard
Copied
I am wondering then, if there is a way to point towards the resource folder on the Z drive so that I can get the scripts to run correctly, or could you inform me of the correct process to resolve t his issue.
Depends on how you are finding your script when you launch it. Are you creating a relative association where you find the parent folder of the primary launching script first, then look for resources there? Or is everything hard coded with specific paths?
Copy link to clipboard
Copied
Pg. 56-57 in the JavaScript Tools Guide PDF shows a bunch of folder properties that can get common folder locations. There is also on Pg. 40 a section about absolute and relative paths for folders and files too that might be helpful.
Copy link to clipboard
Copied
Hi David, thanks for the reply. I am using CS6 and I have noticed that there are some differences between that and CC documentation so I hope I am not too far from what is required. I have looked at the docs and I think I am going the right direction with this but would appreciate a second look from someone with more experience.
Below is a sample of the code I have written (I have omitted all but one of the entries) and below that is the list of scripts and folders that contain other assets for the scripts. What I need to understand is why the three scripts that have resource folders in the same folder do not run and crash the UI when I click on their entry in the application.
{
function filterJSXFiles(file)
{
return ((file.name.match(/.jsx(bin)?$/) != null) && (file.name != (new File($.fileName)).name));
}
// COLLECT FILES IN FOLDERS THAT HOUSES SCRIPTS--------------------------------------------------------------------------------------------------------------------------------//
var ScriptFolder = "Z:\\apps\\after_effects\\myAFX_Scripts\\";
if (ScriptFolder != null)
{
var fileList = Folder(ScriptFolder).getFiles(filterJSXFiles);
}
function myScript(thisObj)
{
myScript_BuildUI(thisObj)
{
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "AFX SCripts", undefined, {resizeable:true});
res = "group{orientation:'row', alignment:['fill', 'fill'] , alignChildren:['fill', 'fill'], \
groupOne: Group{orientation:'column', alignment:['fill', 'fill'] , alignChildren:['fill', 'fill'], myMultiTreeView: TreeView{} } } }";
myPanel.grp = myPanel.add(res);
var ScripIconsDir = "Z:\\apps\\after_effects\\AFX_Script_Icons\\IconForAFX\\";
var jsxExt = ".jsx";
//ADD TREEVIEW----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
var AsciiGenerator_1_2 = brws_TopNode.add("item", "AsciiGenerator_1_2"); // CURRENTLY THROWS RESOURCE ERROR WHEN CLICKED IN AFX DOCKABLE UI
AsciiGenerator_1_2.image = File( ScripIconsDir + "AsciiGenerator_1_2.png");
// EVENTS--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
myPanel.grp.groupOne.myMultiTreeView.addEventListener('change', function (event)
{
if (myPanel.grp.groupOne.myMultiTreeView.selection.text === 'AsciiGenerator_1_2') { fn_AsciiGenerator_1_2(); }
}
// FUNCTIONS--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function fn_AsciiGenerator_1_2()
{
var asciiGenLoc = (ScriptFolder + "AsciiGenerator_1_2" + jsxExt);
var scr_asciiGenLoc = new File(asciiGenLoc);
if (scr_asciiGenLoc.exists) { scr_asciiGenLoc.open("r"); var scriptContent = scr_asciiGenLoc.read(); scr_asciiGenLoc.close(); eval(scriptContent); }
myPanel.grp.groupOne.myMultiTreeView.selection = brws_TopNode;
}
//SETUP PANEL SIZING--------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
myPanel.layout.layout(true);
myPanel.grp.minimumSize = myPanel.grp.size;
//MAKE PANEL RESIZABLE----------------------------------------------------------------------------------------------------------------------------------------------------------------------//
myPanel.layout.resize();
myPanel.onResizing = myPanel.onResize = function(){this.layout.resize()}
return myPanel;
} // END OF myScript_BuildUI FUNCTION
} // END OF myScript FUNCTION
}// END
Many thanks
Copy link to clipboard
Copied
I had some of the above code wrong:
{
// function to filter jsx files-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function filterJSXFiles(file)
{
return ((file.name.match(/.jsx(bin)?$/) != null) && (file.name != (new File($.fileName)).name));
}
// Collect files in folder that holds Burrow AFX scripts---------------------------------------------------------------------------------------------------------------------------------------------------------------//
var brws_ScriptFolder = "Z:\\apps\\after_effects\\AFX_Scripts\\";
//print(brws_ScriptFolder)
if (brws_ScriptFolder != null)
{
var fileList = Folder(brws_ScriptFolder).getFiles(filterJSXFiles);
//print( fileList)
}
function myScript(thisObj){
function myScript_BuildUI(thisObj){
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "AFX SCripts", undefined, {resizeable:true});
res = "group{orientation:'row', alignment:['fill', 'fill'] , alignChildren:['fill', 'fill'], \
groupOne: Group{orientation:'column', alignment:['fill', 'fill'] , alignChildren:['fill', 'fill'], myMultiTreeView: TreeView{} } } }"; // creating a resource string, controls go here
myPanel.grp = myPanel.add(res);
var brws_ScripIconsDir = "Z:\\apps\\after_effects\\burrowsAFX_Script_Icons\\burrowsIconForAFX\\";
var jsxExt = ".jsx";
//Add Treeview items and icons-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
var brws_TopNode = myPanel.grp.groupOne.myMultiTreeView.add("node", "Burrows AFX Scripts");
brws_TopNode.image = File( brws_ScripIconsDir + "BurrowsIcon20x20.png" );
//brws_TopNode.helpTip = "This is the help. Is it not THE greatest thing you have seen?"
var brws_AsciiGenerator_1_2 = brws_TopNode.add("item", "AsciiGenerator_1_2"); // CURRENTLY THROWS RESOURCE ERROR
brws_AsciiGenerator_1_2.image = File( brws_ScripIconsDir + "AsciiGenerator_1_2.png");
// EVENTS--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
myPanel.grp.groupOne.myMultiTreeView.addEventListener('change', function (event)
{
if (myPanel.grp.groupOne.myMultiTreeView.selection.text === 'AsciiGenerator_1_2') { fn_AsciiGenerator_1_2(); }
}, false);// End of Event Listener
function fn_AsciiGenerator_1_2()
{
var asciiGenLoc = (brws_ScriptFolder + "AsciiGenerator_1_2" + jsxExt);
var scr_asciiGenLoc = new File(asciiGenLoc);
if (scr_asciiGenLoc.exists) { scr_asciiGenLoc.open("r"); var scriptContent = scr_asciiGenLoc.read(); scr_asciiGenLoc.close(); eval(scriptContent); }
myPanel.grp.groupOne.myMultiTreeView.selection = brws_TopNode;
}
//Setup panel sizing-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
myPanel.layout.layout(true);
myPanel.grp.minimumSize = myPanel.grp.size;
//Make panel resizeable-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
myPanel.layout.resize();
myPanel.onResizing = myPanel.onResize = function(){this.layout.resize()}
return myPanel;
}// End of myScript_BuildUI--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
// Create the UI-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
var myScriptPal = myScript_BuildUI (thisObj)
if( (myScriptPal != null) && (myScriptPal instanceof Window) )
{
myScriptPal.center();
myScriptPal.show();
}// End of if Statement-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
}// End of myScript function
myScript(this);
}// End of script
Copy link to clipboard
Copied
I'm running on a Mac (Mavericks). Modified your script to run on my mac, and it runs fine.
I suggest you ensure that the names and paths for your icons are correct. Once you have that settled, you shouldn't run into a resource error.
I suggest you use event.target.selection.text instead of myPanel.grp.groupOne.myMultiTreeView.selection.text as in the example below:
myPanel.grp.groupOne.myMultiTreeView.addEventListener('change', function (event)
{
if (event.target.selection.text === 'AsciiGenerator_1_2') {
fn_AsciiGenerator_1_2();
}
You might find this link useful...http://www.kahrel.plus.com/indesign/scriptui-2-2.pdf
Copy link to clipboard
Copied
Hi S___H, thanks for the reply. I will use the event.target.selection.text as you suggest, thanks very much for the pointer.
Prior to your mail, I did have it working, I just hit a block with the resource file(s) for one or more of the scripts. It says I need the resource folder next to the script, but I do have that as the first image shows. Other scripts I have also have the resource folder in the same location and they run fine. I am still getting to grips with ExtendScript so am learning better ways to achieve things at the moment.
I even downloaded another version of the script and put that in the same location as well as the resource folder that came with it and adjusted my script, but it still happens. If I open and run the script from the File-Scripts-Run script file... then the UI shows correctly. There is obviously a search error when clicking the treeview item, but as mentioned, othere scripts from the same supplier run fine. Any ideas would be welcome.
I need the scripts and resources on our server as I will be making a deployment to the studio that artists can acces. This makes updates and changes easier.
I do have the pdf that you linked to, it has been very helpful in the learning curve.
Many thanks
Find more inspiration, events, and resources on the new Adobe Community
Explore Now