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!
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) {
...
Copy link to clipboard
Copied
This line doesn't refer to your anchored frame object:
AFrame.Height = graphic.Height + (2 * 65535);
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;
}
}
Copy link to clipboard
Copied
Wow that worked great, thank you so much for the quick reply!