How to create TextFrame in document with Height and width alone using indesign javascript?

Contributor ,
Sep 10, 2022 Sep 10, 2022

Copy link to clipboard

Copied

I know to create textFrame with geometric bounds but I only have width and height as input for textFrame. Is there anyway to create it with only width and height or please suggest the possible way!

TOPICS
How to , Scripting

Views

65

Likes

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 , Sep 10, 2022 Sep 10, 2022

Assuming four variables:

y: the frame's vertical position

x: the frame's horizontal position

width and height speak for themselves.

app.documents[0].textFrames.add ({
  geometricBounds: [y, x, y+height, x+width];
});/

 

Likes

Translate

Translate
Community Expert , Sep 10, 2022 Sep 10, 2022

Hi @Karthik SG , you could also wrap Peter‘s code in a function—here the parameters are x,y, width, height, destination page

 

 

 

 

var tframe = makeTextFrame(1,1,5,3,app.activeWindow.activePage)


/**
* Makes a new text frame on the active page 
* @ param x position 
* @ param y position
* @ param width
* @ param height
* @ param target page
* @ return the text frame 
*/
function makeTextFrame(x,y,w,h,p){
    return p.textFrames.add ({ geometricBounds: [y,x,y+h,x+w]});
}

 

 

 

Likes

Translate

Translate
Community Expert ,
Sep 10, 2022 Sep 10, 2022

Copy link to clipboard

Copied

Assuming four variables:

y: the frame's vertical position

x: the frame's horizontal position

width and height speak for themselves.

app.documents[0].textFrames.add ({
  geometricBounds: [y, x, y+height, x+width];
});/

 

Likes

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 ,
Sep 11, 2022 Sep 11, 2022

Copy link to clipboard

Copied

Thanks Manan!

Likes

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 ,
Sep 10, 2022 Sep 10, 2022

Copy link to clipboard

Copied

Hi @Karthik SG , you could also wrap Peter‘s code in a function—here the parameters are x,y, width, height, destination page

 

 

 

 

var tframe = makeTextFrame(1,1,5,3,app.activeWindow.activePage)


/**
* Makes a new text frame on the active page 
* @ param x position 
* @ param y position
* @ param width
* @ param height
* @ param target page
* @ return the text frame 
*/
function makeTextFrame(x,y,w,h,p){
    return p.textFrames.add ({ geometricBounds: [y,x,y+h,x+w]});
}

 

 

 

Likes

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 ,
Sep 12, 2022 Sep 12, 2022

Copy link to clipboard

Copied

LATEST

Hi @Karthik SG ,

you could add more property : value pairs to the object that is the only argument of method add().

Also note, that the frame is added to the first spread in your document, because no spread or page is specified.

And you could use strings for the measurement values and also mix them.

 

Sample code:

 

var propValueObject =
{
	geometricBounds :
		[
		"10 mm" , // y
		"10 mm" , // x
		"200 pt" , // y + height
		"100 pt" // x + width
		]
};

app.documents[0].textFrames.add( propValueObject );

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Likes

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