HELP ME RE-DOING THIS SCRIPT AS A DOCKABLE PANEL?
Copy link to clipboard
Copied
It is not working as a dockable panel, and it is launching two windows. I NEEED HELP!
// Function to add or update text in the composition
function updateTextInComp(text) {
var comp = app.project.activeItem;
if (comp && comp instanceof CompItem) {
// Check if a text layer already exists
var textLayer = null;
for (var i = 1; i <= comp.layers.length; i++) {
if (comp.layers[i] instanceof TextLayer) {
textLayer = comp.layers[i];
break;
}
}
if (textLayer) {
textLayer.property("Source Text").setValue(text);
} else {
textLayer = comp.layers.addText(text);
textLayer.property("Position").setValue([comp.width / 2, comp.height / 2]);
textLayer.startTime = comp.time;
}
} else {
alert("Please select or create a composition first.");
}
}
// Create UI panel
var win = new Window("palette", "Text Editor");
win.size = [400, 300];
win.alignChildren = ["fill", "fill"];
// Title
var title = win.add("statictext", undefined, "Text Editor");
title.alignment = "center";
title.graphics.font = ScriptUI.newFont("Verdana", "BOLD", 16);
// Text Input
var textInput = win.add("edittext", undefined, "", {
multiline: true,
scrolling: true,
enterKeySignalsOnChange: true
});
textInput.size = [undefined, 200];
textInput.graphics.backgroundColor = textInput.graphics.newBrush(
textInput.graphics.BrushType.SOLID_COLOR, [0.2, 0.5, 0.1]
);
textInput.graphics.foregroundColor = textInput.graphics.newPen(
textInput.graphics.PenType.SOLID_COLOR, [0.9, 0.9, 0.9], 1
);
// Update Button
var updateButton = win.add("button", undefined, "Update Text");
updateButton.alignment = "center";
updateButton.onClick = function () {
var text = textInput.text;
updateTextInComp(text);
};
win.show();
Copy link to clipboard
Copied
We discussed this 5 days ago with you here, right?
Copy link to clipboard
Copied
Yeah but it didn't work, or I couldn't figure it out. It is not displaying a dockable panel, besides that it is opening two windows, one as a dockable one but empty and the main one but is not dockable. What I can do?
Copy link to clipboard
Copied
Best post the code you tried in as a reply in the other discussion. Then we can take a look at the code and maybe spot what needs to be fixed.
Copy link to clipboard
Copied
This is the code I corrected using the method you told me, but I don't know why it is not working out
// Function to add or update text in the composition
function updateTextInComp(text) {
var comp = app.project.activeItem;
if (comp && comp instanceof CompItem) {
// Check if a text layer already exists
var textLayer = null;
for (var i = 1; i <= comp.layers.length; i++) {
if (comp.layers[i] instanceof TextLayer) {
textLayer = comp.layers[i];
break;
}
}
if (textLayer) {
textLayer.property("Source Text").setValue(text);
} else {
textLayer = comp.layers.addText(text);
textLayer.property("Position").setValue([comp.width / 2, comp.height / 2]);
textLayer.startTime = comp.time;
}
} else {
alert("Please select or create a composition first.");
}
}
// Create UI panel
var win = (this instanceof Panel) ? this : new Window("palette", "Text Editor");
win.size = [400, 300];
win.alignChildren = ["fill", "fill"];
// Title
var title = win.add("statictext", undefined, "Text Editor");
title.alignment = "center";
title.graphics.font = ScriptUI.newFont("Verdana", "BOLD", 16);
// Text Input
var textInput = win.add("edittext", undefined, "", {
multiline: true,
scrolling: true,
enterKeySignalsOnChange: true
});
textInput.size = [undefined, 200];
textInput.graphics.backgroundColor = textInput.graphics.newBrush(
textInput.graphics.BrushType.SOLID_COLOR, [0.2, 0.5, 0.1]
);
textInput.graphics.foregroundColor = textInput.graphics.newPen(
textInput.graphics.PenType.SOLID_COLOR, [0.9, 0.9, 0.9], 1
);
// Update Button
var updateButton = win.add("button", undefined, "Update Text");
updateButton.alignment = "center";
updateButton.onClick = function () {
var text = textInput.text;
updateTextInComp(text);
};
win.show();
_____________________________________________
it is displaying this error
otherwise, opening two windows
Copy link to clipboard
Copied
The show() is only needed if it is a window, not if it is a dockable panel.
Hence, you need to update it like this:
if (win instanceof Window) {
win.show();
}
Copy link to clipboard
Copied
Alright the two windows opening is fixed.
But now it looks like this....
It is empty, why?
Copy link to clipboard
Copied
Does it help if you add this before the show()?
win.layout.layout(true);
win.layout.resize();
Copy link to clipboard
Copied
Thank you, but it is not working. it is srtill empty

