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

How to use "fit" method to only RECTANGLES containing any type of graphics?

Community Beginner ,
Feb 15, 2016 Feb 15, 2016

Copy link to clipboard

Copied

Hi,

I want use : fit(FitOptions.FRAME_TO_CONTENT) to only rectangles having placed an image of any type, not to touching other rectangles

I' don't know how to do it.

Many thanks for suggestions 🙂

Marcin

TOPICS
Scripting

Views

396

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 ,
Feb 15, 2016 Feb 15, 2016

Copy link to clipboard

Copied

Hi,

try this snippet.

var doc   = app.documents[0];

var rects = doc.rectangles;

for (var i=0, len=rects.length; i < len ; i++) {

  var rect = rects;

  var include_img = rect.graphics.length > 0 ||

                    rect.images.length > 0;

  if (include_img) {

    $.writeln(rect.id);

    rect.fit(FitOptions.FRAME_TO_CONTENT);

  }

};

if you want to specify graphic type, use rect.epss.length instead of rect.graphics.length for example.

thankyou

mg

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 ,
Feb 15, 2016 Feb 15, 2016

Copy link to clipboard

Copied

Hi Marcin,

if you also want to catch graphics, that are nested (in groups, anchored graphics, graphics in cells, pasted inside graphics) we could also use the allGraphics array of the document. Then the question is: would you like to dismiss graphics on locked layers, graphics that are locked, graphics that are placed on the pasteboard * ?

// Fit graphics, if parent is Rectangle object

// Dismiss locked rectangles and locked layers

var doc = app.documents[0];

var allGraphicsArray = doc.allGraphics;

for(var n=0;n<allGraphicsArray.length;n++)

{

    var container = allGraphicsArray.parent;

  

    if(

        // 1. Container is a Rectangle object:

        container.constructor.name == "Rectangle"

        // 2. It's layer is not locked:

        && container.itemLayer.locked === false

        // 3. Container is not locked:

        && container.locked === false

        )

    {

      allGraphicsArray.parent.fit(FitOptions.FRAME_TO_CONTENT);

    };

};

* If only placed graphics of the pages should be affected, we could loop through the pages.

What could go wrong?
The container of the graphic is inside overset text or is part of a table cell's overset.

Uwe

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 Beginner ,
Feb 16, 2016 Feb 16, 2016

Copy link to clipboard

Copied

many thanks milligrame

it looks like needed !!

I will try tommorow in practice

thank you Laubender

tommorow I will try it

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 Beginner ,
Feb 18, 2016 Feb 18, 2016

Copy link to clipboard

Copied

LATEST

many, many many thanks Launder 🙂

your snippet looks and work brilliant !!!!

it gave me also a "new" look of "what" I should search first 🙂

thanks again

regards Marcin

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