Skip to main content
jan99x
Inspiring
May 23, 2020
Answered

How add text to frames in script: MakeGrid.jsx

  • May 23, 2020
  • 7 replies
  • 2892 views

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"
});
}

 

This topic has been closed for replies.
Correct answer Manan Joshi

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

 

-Manan

7 replies

Community Expert
May 25, 2020

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 )

jan99x
jan99xAuthor
Inspiring
May 26, 2020

@Laubender....

Thanks.

brian_p_dts
Community Expert
Community Expert
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
 }
}
Manan JoshiCommunity ExpertCorrect answer
Community Expert
May 23, 2020

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

 

-Manan

-Manan
jan99x
jan99xAuthor
Inspiring
May 24, 2020

@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.

 

Community Expert
May 23, 2020

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=0

 

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

 

-Manan

-Manan
pixxxelschubser
Community Expert
Community Expert
May 23, 2020

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.

jan99x
jan99xAuthor
Inspiring
May 23, 2020

@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.

Community Expert
May 23, 2020

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=0

 

-Manan

 

-Manan
jan99x
jan99xAuthor
Inspiring
May 23, 2020

@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).

Inspiring
May 27, 2020

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...

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

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

-Manan
jan99x
jan99xAuthor
Inspiring
May 23, 2020

@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: