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

Resize a Rectangle horizontaly ONLY or verticaly ONLY by script

Explorer ,
Sep 21, 2019 Sep 21, 2019

Good morning, 

I'm wondering, how to resize an rectangle in only one direction by script, to acheive identical result, as mouse double clikin on the middle handle ?

 

the fit() method doesn't allow to do such operation, I think ?

 

thanks in advance for suggestions or solution 🙂

 

many regards a.

TOPICS
Scripting
854
Translate
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 ,
Sep 22, 2019 Sep 22, 2019

Hi platm72,

Auto sizing options is available for text frames not for rectangles like:

 

var myTextFrame = app.activeDocument.pages[0].textFrames[0];
/// These are four types ======
myTextFrame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.OFF;
myTextFrame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH;
myTextFrame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH_PROPORTIONALLY;
myTextFrame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
myTextFrame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.WIDTH_ONLY;
/// ==========================

 

Unforutnately there's no such thing for rectangles

Here are some list how you can fit rectangle frames : 

 

var myRectangle = app.activeDocument.pages[0].rectangles[0];
//// These are types how you can fit you rectangle frames ======
myRectangle.fit(FitOptions.APPLY_FRAME_FITTING_OPTIONS);
myRectangle.fit(FitOptions.CENTER_CONTENT);
myRectangle.fit(FitOptions.CONTENT_AWARE_FIT);
myRectangle.fit(FitOptions.CONTENT_TO_FRAME);
myRectangle.fit(FitOptions.FILL_PROPORTIONALLY);
myRectangle.fit(FitOptions.FRAME_TO_CONTENT);
myRectangle.fit(FitOptions.PROPORTIONALLY);
/// ==========================================================

 

 

You can have more information here on rectangles : Rectangle && Rectangles

 

Best

Sunil

Translate
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 ,
Sep 22, 2019 Sep 22, 2019
FitOptions.CONTENT_AWARE_FIT

===This is not supported===

 

Best

Sunil

Translate
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 23, 2019 Sep 23, 2019

Hi,

 

A method you can use is Resize - https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Rectangle.html#d1e217105

 

Which is a little complicated when you first look at it.

undefined resize (in:Varies BoundingBoxLimits CoordinateSpaces BoundsKind:BoundingBoxLimits OrderedarraycontainingcoordinateSpace:CoordinateSpaces, from:Array of Varies AnchorPoint AnchorPoints 2 Reals BoundingBoxLimitss CoordinateSpacess Arrays of 2 Reals LongIntegers, by:ResizeMethods, values:Array of Varies Reals ResizeConstraintss CoordinateSpacess, [resizeIndividually:Boolean=Boolean], [consideringRulerUnits:Boolean=Boolean])

 

but with a little trial and error you should be able to work out what works for you. I would try something like

 

myRectangle.resize (BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS,

AnchorPoint.CENTER_ANCHOR,

ResizeMethods.ADDING_CURRENT_DIMENSIONS_TO, [100, 100], false, false);

 

Note: I am not in a position to test this so it may not run out of the box, and it will resize your rectangle in both directions, to alter that just change the value of the 100.

 

Hope this helps.

 

Malcolm

Translate
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 ,
Sep 23, 2019 Sep 23, 2019
Thank you Malcolm for pointing me on RESIZE method .... it is obvious, but I never used it unfortunately 🙂
Translate
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 ,
Sep 23, 2019 Sep 23, 2019
In my first post I miss describing of some conditions I plan to use the script. My main target is to adjust the height of the picture frame to the content, not changing the width. The picture box has its own object style and the graphic fills the box starting from left bottom corner. I've prepared beneatch function
Translate
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 ,
Sep 23, 2019 Sep 23, 2019
function fitTheBox () { var ag = app.activeDocument.allGraphics, i = ag.length; while ( i-- ) { if ( ag[i].parent.constructor.name == 'Rectangle' && ag[i].parent.locked == false /* maybe some other conditions */ ) { var g, r, hg, wg, hr, wr; g = ag[i].geometricBounds, r = ag[i].parent.geometricBounds; hg = g[2]-g[0], wg = g[3]-g[1], hr = r[2]-r[0], wr = r[3]-r[1]; if ( hg > hr ) { ag[i].parent.geometricBounds = [ g[0], r[1], r[2], r[3] ]; } else { ag[i].fit( FitOptions.PROPORTIONALLY ); g = ag[i].geometricBounds; ag[i].parent.geometricBounds = [ g[0], r[1], r[2], r[3] ]; } } } }
Translate
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 ,
Sep 23, 2019 Sep 23, 2019
LATEST
this function do the job :-), but I'll experiment with resize()
Translate
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