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

Resize Anchored Frames with Script

Community Beginner ,
Jul 07, 2023 Jul 07, 2023

Copy link to clipboard

Copied

Hi, I have a number of anchored frames throughout a book that are oddly sized. I would like to create an automatic script that resizes them to the graphic, but I'm having some trouble. After piecing together other posts I am currently working with:

 

var doc = app.ActiveDoc;

var graphic = doc.FirstGraphicInDoc;

while( graphic.ObjectValid( ) )

{

     if( graphic.constructor.name == "AFrame" )

     {

        AFrame.Height = graphic.Height + (2 * 65535);

     }

     graphic = graphic.NextGraphicInDoc;

}

 But when I run the script nothing happens. I've checked the console and there are no errors, so I assume I have something incorrect here. The FM scripting guides I've found don't seem to cover anything graphic related. Any assistance is appreciated!

TOPICS
Scripting

Views

111

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 1 Correct answer

Community Expert , Jul 07, 2023 Jul 07, 2023

I haven't tested this, but this should work to resize your anchored frames to the containing graphic.

#target framemaker

main ();

function main () {
    
    var doc;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        processDoc (doc);
    }
}

function processDoc (doc) {

    var aframe, graphic;
    
    // Loop through the graphics in the document,
    // looking for anchored frames.
    aframe = doc.FirstGraphicInDoc;
    while (aframe.ObjectValid () === 1) {
       
...

Votes

Translate

Translate
Community Expert ,
Jul 07, 2023 Jul 07, 2023

Copy link to clipboard

Copied

This line doesn't refer to your anchored frame object:

        AFrame.Height = graphic.Height + (2 * 65535);

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 ,
Jul 07, 2023 Jul 07, 2023

Copy link to clipboard

Copied

I haven't tested this, but this should work to resize your anchored frames to the containing graphic.

#target framemaker

main ();

function main () {
    
    var doc;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        processDoc (doc);
    }
}

function processDoc (doc) {

    var aframe, graphic;
    
    // Loop through the graphics in the document,
    // looking for anchored frames.
    aframe = doc.FirstGraphicInDoc;
    while (aframe.ObjectValid () === 1) {
        if (aframe.constructor.name === "AFrame") {
            // Assume that there is a single graphic in 
            // the anchored frame.
            graphic = aframe.FirstGraphicInFrame;
            if (graphic.ObjectValid () === 1) {
                // Resize the anchored frame to the graphic.
                aframe.Height = graphic.Height;
                aframe.Width = graphic.Width;
                // Position the graphic at the upper-left of
                // the anchored frame.
                graphic.LocY = 0;
                graphic.LocX = 0;
            }
        }
        aframe = aframe.NextGraphicInDoc;
    }
}

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 ,
Jul 07, 2023 Jul 07, 2023

Copy link to clipboard

Copied

LATEST

Wow that worked great, thank you so much for the quick reply!

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