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

Resize Anchored Frames with Script

Community Beginner ,
Jul 07, 2023 Jul 07, 2023

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

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) {
       
...
Translate
Community Expert ,
Jul 07, 2023 Jul 07, 2023

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

        AFrame.Height = graphic.Height + (2 * 65535);
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 ,
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) {
        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;
    }
}
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 Beginner ,
Jul 07, 2023 Jul 07, 2023
LATEST

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

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