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

Script UI question tough one.

Advocate ,
Aug 06, 2020 Aug 06, 2020

Copy link to clipboard

Copied

This may be outside the realm of what Script UI can do. Is there a way to have a text box set the radius for a text frame around the Page? I illustrated my current Script UI and added white boxes to illustrate what i'm hoping could be done. When i click on the "Add Dieline to Document" checkbox have it set the radius to the text frame around the box. for instance if you want .125" radius type that in if you want a .0313" type that in. I have a script attached now that makes a dieline around the page but it only has one size of radius i'd like the ability (if possible) to be able to change that when needed.

 

Screen Shot 2020-08-06 at 3.57.05 PM.jpg

TOPICS
Scripting

Views

440

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

correct answers 2 Correct answers

Community Expert , Aug 06, 2020 Aug 06, 2020

Sure. Set up your UI as a separate function, then return from that function an object with the values that are set in the UI edittext boxes, ie: 

var radiusObj = {
   topLeft: edittext1.text;
   bottomLeft: edittext2.text;
   topRight: edittext3.text;
   bottomRight: edittext4.text; 
}

 Then in your main code: 

var radiusInfo = RadiusUI(); //RadiusUI is the function you created, and returns the object
textFrame.topLeftCornerRadius = radiusInfo.topLeft;
//etc

 

Votes

Translate

Translate
Community Expert , Aug 11, 2020 Aug 11, 2020

Use functional programming to separate your codebase within the same script file. This is much cleaner then having a bunch of separate scripts to maintain. 

 

There also are a few problems with your code. Your addRow function called for a "maingroup" variable but did not use that variable in the rest. You also were trying to set .edit and buttons.group objects which are inaccessible. Your snippet would have failed several times over. I believe I shared Peter Kahrel's ScriptUI book with you previ

...

Votes

Translate

Translate
Community Expert ,
Aug 06, 2020 Aug 06, 2020

Copy link to clipboard

Copied

Sure. Set up your UI as a separate function, then return from that function an object with the values that are set in the UI edittext boxes, ie: 

var radiusObj = {
   topLeft: edittext1.text;
   bottomLeft: edittext2.text;
   topRight: edittext3.text;
   bottomRight: edittext4.text; 
}

 Then in your main code: 

var radiusInfo = RadiusUI(); //RadiusUI is the function you created, and returns the object
textFrame.topLeftCornerRadius = radiusInfo.topLeft;
//etc

 

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
Advocate ,
Aug 07, 2020 Aug 07, 2020

Copy link to clipboard

Copied

wow thanks i didnt think this was actually going to be possilbe. I'll start tinkering today thanks again. There was a SCRIPT UI document floating around somewhere would you happen to know where that is?

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 ,
Aug 07, 2020 Aug 07, 2020

Copy link to clipboard

Copied

https://creativepro.com/files/kahrel/indesign/scriptui.html

 

Peter Kahrel's ScriptUI book is great.

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
Advocate ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

Can the above be put into this script i just did? I dabble in scripting so i am by no means anywhere near good at it. I changed my origional thinking about embedding this into the other script. i dont want to make that 1 script to complex for people to us. so what i'm going to do is make a separate script that open up with a check box. it to me seems less cluttered.

 

var w = new Window ("dialog");
var wN = w.add ("group")
w.add ("statictext", undefined, "Die line Radius")
var mG1 = w.add ("panel {orientation: 'row'}");
var mG2 = w.add ("panel {orientation: 'column'}");
add_row (mG1);

w.show ();
function add_row (maingroup) {

var b1g, b2g, b3g, b4g;

    b1g = mG1.add ("group")
    b2g = mG1.add ("group")
    b3g = mG1.add ("group")
    b4g = mG1.add ("group")
var b1 = mG1.add ("group")
var b2 = mG1.add ("group")
var b3 = mG1.add ("group")
var b4 = mG1.add ("group")
var group = mG2.add ("group");
var buttons = w.add("group")

b1g.edit = b1.add ("statictext", undefined, "Top Left", "")
b1.edit = b1.add ("edittext", ["", "", 75, 20], mG1.children.length);
b2g.edit = b2.add ("statictext", undefined, "Bottom Left")
b2.edit = b2.add ("edittext", ["", "", 75, 20], mG1.children.length);
b3g.edit = b3.add ("statictext", undefined, "Top Right")
b3.edit = b3.add ("edittext", ["", "", 75, 20], mG1.children.length);
b4g.edit = b4.add ("statictext", undefined, "Bottom Right")
b4.edit = b4.add ("edittext", ["", "", 75, 20], mG1.children.length);

buttons.group = group.add("button",undefined,"OK")
buttons.group = group.add("button",undefined,"Cancel")

}

 

 

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 ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

Use functional programming to separate your codebase within the same script file. This is much cleaner then having a bunch of separate scripts to maintain. 

 

There also are a few problems with your code. Your addRow function called for a "maingroup" variable but did not use that variable in the rest. You also were trying to set .edit and buttons.group objects which are inaccessible. Your snippet would have failed several times over. I believe I shared Peter Kahrel's ScriptUI book with you previously; here it is again.

 

Here's the whole thing put together (untested, that's for you).

 

var RadiusUI = function() {
    var w = new Window ("dialog");
    var wN = w.add ("group"); //we're adding nothing to this group; is it needed?
    w.add ("statictext", undefined, "Die line Radius")
    var mG1 = w.add ("panel {orientation: 'row'}");
    var mG2 = w.add ("panel {orientation: 'column'}");

    var b1g, b2g, b3g, b4g;

    b1g = mG1.add ("group");
    b2g = mG1.add ("group");
    b3g = mG1.add ("group");
    b4g = mG1.add ("group");
    var b1 = mG1.add ("group");
    var b2 = mG1.add ("group");
    var b3 = mG1.add ("group");
    var b4 = mG1.add ("group");
    var group = mG2.add ("group"); //this variable also is not used, and it is not descriptive
    var buttons = w.add("group");

    var b1gEdit = b1.add ("statictext", undefined, "Top Left", "");
    var b1Edit = b1.add ("edittext", ["", "", 75, 20], mG1.children.length);
    var b2gEdit = b2.add ("statictext", undefined, "Bottom Left");
    var b2Edit = b2.add ("edittext", ["", "", 75, 20], mG1.children.length);
    var b3gEdit = b3.add ("statictext", undefined, "Top Right");
    var b3Edit = b3.add ("edittext", ["", "", 75, 20], mG1.children.length);
    var b4gEdit = b4.add ("statictext", undefined, "Bottom Right");
    var b4Edit = b4.add ("edittext", ["", "", 75, 20], mG1.children.length);

    buttons.add("button",undefined,"OK");
    buttons.add("button",undefined,"Cancel");

    var obj = {};
    var result = w.show();
    if (result == 1) {
        obj.topLeft = b1Edit.text;
        obj.bottomLeft = b2Edit.text;
        obj.topRight = b3Edit.text;
        obj.bottomRight = b4Edit.text;
        return obj;
    } else {
        //user canceled dialog
        return null;
    }

}

var processTextFrame = function(textFrame) {
     var radiusInfo = RadiusUI(); 
     if (radiusInfo) { //if it was !radiusInfo, that means the user canceled the dialog
        textFrame.topLeftCornerRadius = radiusInfo.topLeft;
        textFrame.bottomLeftCornerRadius = radiusInfo.bottomLeft;
        textFrame.topRightCornerRadius = radiusInfo.topRight;
        textFrame.bottomRightCornerRadius = radiusInfo.bottomRight;
    }
}

var unitTest = function() {
    var textFrame = app.activeDocument.textFrames[0];
    processTextFrame(textFrame);
}

unitTest();

 

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
Advocate ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

Ahhhh so i was supposed to put all of that in the RadiusUI function. no wonder i was getting errors. that and i didnt now have the last function you have on here when i was tring to get it to work. Thank you so much i'm slowly learning.

 

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
Advocate ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

Can you see a reason for my text boxes defaulting with the number 8 in them? I've had this issue since the beginning and have yet to figure out why they are like that?

 

I figured this one out "kinda" i can change it to whatever text i want by adding "whatever" after the size but i still dont know why it put 8

var b4Edit = b4.add ("edittext", ["", "", 75, 20], "-", mG1.children.length);

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 ,
Aug 11, 2020 Aug 11, 2020

Copy link to clipboard

Copied

LATEST

I think it's mG1.children.length

 

What happens if you delete that.

 

Also, while you should read Peter's book, this is a handy GUI tool for building and exporting InDesign UIs: https://scriptui.joonas.me/

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