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

How add text to frames in script: MakeGrid.jsx

Participant ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

I use standard script MakeGrid.jsx (InDesign), make Grid boxes.

Hoe can I change fontsize, fonttype, textcolor etc. for text in those boxes?

I tried several ways (blue text eg.), but nothing changes the text... Text comes in boxes, thats OK, but I can't change its font etc.

 

default code (at line 131 ...):

if(myRetainFormatting == true){
myNewObject = myObject.duplicate();
myNewObject.geometricBounds = [myY1, myX1, myY2, myX2];
}

 

replaced code (at line131 ...):

if(myRetainFormatting == true){
myNewObject = myObject.duplicate();
myNewObject.geometricBounds = [myY1, myX1, myY2, myX2];

tmp = myNewObject.textFrames.add(
{
geometricBounds :[myY1, myX1, myY2, myX2],
strokeWidth : 0,
size:30,
fillColor : "None",
contents : "some text"
});
}

 

TOPICS
Scripting

Views

1.7K

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 , May 23, 2020 May 23, 2020

You need to check if myNewObject is a textFrame before trying to access parentStory. MakeGrid can work on several different objects.

if (

if(myRetainFormatting == true){
 myNewObject = myObject.duplicate();
 myNewObject.geometricBounds = [myY1, myX1, myY2, myX2];
 if (myNewObject instanceof TextFrame) {
    myNewObject.parentStory.pointSize = 20
 }
}

Votes

Translate

Translate
Community Expert , May 23, 2020 May 23, 2020

That explains it, i was always trying it with a single textframe selection. Good catch Brian

 

-Manan

Votes

Translate

Translate
Community Expert ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

Hi,

 

The code myObject.duplicate() creates the new textframe. You can alter its properties by using the myNewObject var. For ex changing the font size of the new frames the code would be something like

if(myRetainFormatting == true){
 myNewObject = myObject.duplicate();
 myNewObject.geometricBounds = [myY1, myX1, myY2, myX2];
 myNewObject.parentStory.pointSize = 20
}

 

You can change other properties as well by looking at what properties are available for story object

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Story.html

 

-Manan

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
Participant ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

@Manan,

Thanks for answer... however it does not work for me, see error message below.

Is it about an other version of InDesign ? (I have CS6).

 

code replaced= your suggestion above

Message:

Z-Text-Sample.jpg

 

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 ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

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 ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

I don't have access to CS6 but we can target the older script version and i did that, all seems to be working fine for me. CS6 does have the parentStory property. See the following

http://jongware.mit.edu/idcs6js/pc_TextFrame.html

Run the following code and see what you get

alert(app.scriptPreferences.version)

For CS6 it should be 8, i set it to 8 on my end and it worked fine. See the code running on my end and check if you notice something different in what you have edited

https://www.dropbox.com/s/2xofaqrbjjndi0g/screen%20recording%202020-05-23%20at%203.10.23%20pm.mov?dl...

 

-Manan

 

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
Participant ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

@Manan,

 

Version = 8.0

by the way ... is there a possibility to record a serie key strokes so that makes/records a script... That will help me to learn and see the things work?

ActionRecorderExtension.zxp (from Rorohiko does not work).

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
Contributor ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

LATEST

Note that ActionRecorder is very old. It was using the old CSXS technology (Air/Flash based) which is not supported any more, and the signing certificates on it have long gone stale. 

At the time we were very hopeful and sank a lot of time, effort and resources into ActionRecorder, but we never found any takers, and when the move to CEP was made, we could not afford rebuilding it from scratch, so we had to abandon the project...

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 ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

Do you really need the changes in the script?


Or is it possible to create an new Object Style with an Paragraph Style.

Then run your MakeGrid.jsx. The text boxes are still selected --> now simply apply your new created Object Style.

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
Participant ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

@pixxxel_schubser

Thanks... first: I'am a beginner in InDesign.

Although I can program, scripting in InDesign is different.

In addition, I would more like to make a one-touch-button because the end result is for non-experienced people who do not have to do difficult things.
Furthermore: font, color, size etc. should still be a basic occurrence in a script?! I was looking for scripts that change fonts etc. But finding a good example is difficult. Maybe someone has a simple script that changes the font, size and color and makes it available? And I can make progress.

 

Error message (above): if I read correctly ... there is something with the object and not with "parentStory" .. isn't it?
So, how can I check if my InDesign CS6-V8 has a "parentStory".
or ... should I use a different type of object in the script? As said ... I'm too inexperienced with InDesign.

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 ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

I am not aware of any action recorder for InDesign. However i looked into my archives and was able to locate an installation of CS6, and the code works flawlessly for me. See the screengrab

https://www.dropbox.com/s/j1u359nyl3aw9p5/screen%20recording%202020-05-23%20at%208.31.48%20pm.mov?dl...

 

Are you doing something different from what i am doing? There has to be something different

 

-Manan

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 ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

You need to check if myNewObject is a textFrame before trying to access parentStory. MakeGrid can work on several different objects.

if (

if(myRetainFormatting == true){
 myNewObject = myObject.duplicate();
 myNewObject.geometricBounds = [myY1, myX1, myY2, myX2];
 if (myNewObject instanceof TextFrame) {
    myNewObject.parentStory.pointSize = 20
 }
}

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 ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

That explains it, i was always trying it with a single textframe selection. Good catch Brian

 

-Manan

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
Participant ,
May 23, 2020 May 23, 2020

Copy link to clipboard

Copied

@Manan Joshi + @Brianp311

 

YES, I was focused on the script commands. I used an empty frame, no text in it. After I type some text in it "parentStory" works well!.

Both thanks.

 

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 ,
May 25, 2020 May 25, 2020

Copy link to clipboard

Copied

Hi Jan,

additionally to what Brian and Manan said, visit the DOM documentation for InDesign CS6 :

Compiled by Jongware for online and offline use. Also for various versions of InDesign, Illustrator and PhotoShop, also FrameMaker:

http://www.jongware.com/idjshelp.html

 

Or the one compiled by Gregor Fellenz for online use:

https://www.indesignjs.de/extendscriptAPI/indesign8/#about.html

 

And yes, here we have it, property parentStory with text frames:

http://jongware.mit.edu/idcs6js/pc_TextFrame.html#parentStory

 

Regards,
Uwe Laubender

( ACP )

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
Participant ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

@Laubender....

Thanks.

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