3 Replies Latest reply on Aug 28, 2012 2:56 AM by bruno@CD

# How to shrinkwrap an equation using ExtendScript?

Hi all,

Is there any function to shrinkwrap an equation frame? I want to write a script which shrinkwraps all equations in an active document.

Regards,

Bruno

• ###### 1. Re: How to shrinkwrap an equation using ExtendScript?

There is an FCode to shrinkwrap. Otherwise, you can use code to get the parent anchored frame and size it to the size of the equation, while setting the LocY and LocX of the equation to 0.

Rick

• ###### 2. Re: How to shrinkwrap an equation using ExtendScript?

Thanks for the suggestion. Actually, the equation LocY and Loc X should be 1 pt, and the frame width and height 2 pt greater than the equation's.

```function ApplyFormatOnEqn(frame, eqn)
{
frame.Width = eqn.Width + 2*65536;
frame.Height = eqn.Height + 2*65536;
eqn.LocX = 1*65536;
eqn.LocY = 1*65536;
}
```

Do you know how to select frames with extenscript, so that I can use the following Fcode?

```function ApplyFormatOnEqnFcode()
{
codes = new Array();
codes[0] = FCodes.KBD_PUTINLINE;
Fcodes(codes);
}
```
• ###### 3. Re: How to shrinkwrap an equation using ExtendScript?

Got it:

```function ApplyFormatOnEqn(frame, eqn)
{
frame.Width = eqn.Width + 2*65536;
frame.Height = eqn.Height + 2*65536;
eqn.LocX = 1*65536;
eqn.LocY = 1*65536;
}

function ApplyFormatOnEqnFcode()
{
codes = new Array();
codes[0] = FCodes.KBD_PUTINLINE;
Fcodes(codes);
}

function ApplyEqnFormatBatch()
{
var doc = app.ActiveDoc; // current doc

if(!doc.ObjectValid() )
{
return;
} // if

var frame = doc.FirstGraphicInDoc;

// Look for next anchored frame, 40 attempts
var i = 0;
while (frame.type != Constants.FO_AFrame && i < 40)
{
frame = frame.NextGraphicInDoc;
i++;
}  // while

// Check whether eqn is selected
if(!frame.ObjectValid()  || i == 40)
{
return;
} // if

var eqn = frame.FirstGraphicInFrame;

// Apply correct format to selected eqn
if (eqn.type == Constants.FO_Math) // if equation
{
ApplyFormatOnEqn(frame, eqn);
}

// Loop if there are more eqns
while(frame.NextGraphicInDoc.ObjectValid())
{
frame = frame.NextGraphicInDoc;
if (frame.type == Constants.FO_AFrame)
{
eqn = frame.FirstGraphicInFrame;
if (eqn.type == Constants.FO_Math) // if eqn
{
ApplyFormatOnEqn(frame, eqn);
}
}
} // while

} // function```