Dockable Script Question

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
mnarlock
Posts: 3
Joined: August 2nd, 2010, 9:31 am

I've been toying with a script that supposedly works, but I'm having a devil of a time getting it to. The idea is simple, I have four scripts that I'd like to dock into a panel and run them using buttons. The script I've been toying with creates the dockable panel, but places all of the buttons on top of each other when run from scriptUI. The buttons also, on clicking, don't actually run the required jsx files. I've put these "other" scripts in a directory inside the scriptUI folder. Here's the script below. I'd be grateful for any assistance.

{
function onScriptButtonClick()
{
var scriptFile = new File(this.currentDirectory+this.scriptFileName);
scriptFile.open();
eval(scriptFile.read());
scriptFile.close();
}

function addScriptButton(palette, buttonRect, buttonLabel, buttonCurrentDirectory, buttonScriptName)
{
var newButton = palette.add("button", buttonRect, buttonLabel);

newButton.scriptFileName = buttonScriptName;
newButton.currentDirectory = buttonCurrentDirectory;

newButton.onClick = onScriptButtonClick;
return newButton;
}

function createUI(thisObj)
{

var topEdge = 4;
var leftEdge = 4;
var btnSize = 36;

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

var BT4096 = addScriptButton(myPanel,[leftEdge, topEdge, leftEdge+btnSize, topEdge+btnSize], "4096", "/Dome3D/", "domemaster_overlay_4096.jsx");
var BT2560 = addScriptButton(myPanel,[leftEdge, topEdge, leftEdge+btnSize, topEdge+btnSize], "2560", "/Dome3D/", "domemaster_overlay_2560.jsx");
var BT1920 = addScriptButton(myPanel,[leftEdge, topEdge, leftEdge+btnSize, topEdge+btnSize], "1920", "/Dome3D/", "domemaster_overlay_1920.jsx");
var BT1536 = addScriptButton(myPanel,[leftEdge, topEdge, leftEdge+btnSize, topEdge+btnSize], "1536", "/Dome3D/", "domemaster_overlay_1536.jsx");
var BT1408 = addScriptButton(myPanel,[leftEdge, topEdge, leftEdge+btnSize, topEdge+btnSize], "1408", "/Dome3D/", "domemaster_overlay_1408.jsx");

return myPanel;
}

var YourPanel = createUI(this);

if (YourPanel instanceof Window) YourPanel.show();


}
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

Try rewrite your onScriptButtonClick this way:

Code: Select all

function onScriptButtonClick()
{
	var currDir = File($.fileName).path;
	var scriptFile = new File(currDir+this.currentDirectory+this.scriptFileName);
	alert(scriptFile.fsName);
	if (scriptFile.exists && scriptFile.open('r'))
	{
		eval(scriptFile.read());
		scriptFile.close();
		}
	else $.writeln(scriptFile.fsName);// or whatever
   };
and for the layout, replace the last line by

Code: Select all

if (YourPanel instanceof Window) YourPanel.show() else YourPanel.layout.layout(true);
Xavier
Post Reply