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

HELP ME RE-DOING THIS SCRIPT AS A DOCKABLE PANEL?

Explorer ,
Oct 20, 2023 Oct 20, 2023

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();

TOPICS
Expressions , FAQ , Scripting , User interface or workspaces

Views

953

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
Community Expert ,
Oct 21, 2023 Oct 21, 2023

Copy link to clipboard

Copied

We discussed this 5 days ago with you here, right?

https://community.adobe.com/t5/after-effects-discussions/how-do-i-make-my-script-dockable/m-p/141626...

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

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 ,
Oct 24, 2023 Oct 24, 2023

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?

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
Community Expert ,
Oct 24, 2023 Oct 24, 2023

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. 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

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 ,
Oct 24, 2023 Oct 24, 2023

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

LeoBledo_0-1698180965122.pngexpand image

otherwise, opening two windows

LeoBledo_2-1698181129799.pngexpand image

 



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
Community Expert ,
Oct 25, 2023 Oct 25, 2023

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();
}
Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

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 ,
Oct 25, 2023 Oct 25, 2023

Copy link to clipboard

Copied

Alright the two windows opening is fixed. 
But now it looks like this....

LeoBledo_0-1698272987068.pngexpand image

It is empty, why?

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
Community Expert ,
Oct 26, 2023 Oct 26, 2023

Copy link to clipboard

Copied

Does it help if you add this before the show()?

win.layout.layout(true);
win.layout.resize();
Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

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 ,
Oct 26, 2023 Oct 26, 2023

Copy link to clipboard

Copied

LATEST

Thank you, but it is not working. it is srtill empty

LeoBledo_0-1698343108366.pngexpand image

 

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