How can I set width or height of an object?

Hi guys,.

y at - it a simple method to define a width/height of an object in absolute terms without messing with .geometricBounds?

Something like this:

app.activeDocument.selection [0] .width = "150 mm;

or

app.activeDocument.selection [0] .width ("150 mm", ConstrainProportion.Yes, AnchorPoint.bottomLeftAnchor);

The object is in my case, usually a vector image copied from Illustrator.

PanDulka

> Don't have you by any chance version of CS3?

In this case to use the PageItem.transform () method in an same special way.

Try this:

function setWidthHeightCS3(/*PageItem*/o, /*str*/w, /*str*/h, /*bool=false*/useVisibleBounds)
{
    if( !o.transform) return;

    var CS_INNER = CoordinateSpaces.INNER_COORDINATES,
        BB = BoundingBoxLimits[(useVisibleBounds?'OUTER_STROKE':'GEOMETRIC_PATH') + '_BOUNDS'];

    var wPt = UnitValue(w).as('pt'),
        hPt = UnitValue(h).as('pt');

    if( 0 >= wPt || 0 >= hPt ) return;

    var wsBkp = app.transformPreferences.whenScaling,
        a = o.resolve([[1,1], BB], CS_INNER)[0].
            concat(o.resolve([[0,0], BB], CS_INNER)[0]),
        sx = wPt / (a[2]-a[0]),
        sy = hPt / (a[3]-a[1]);

    app.transformPreferences.whenScaling = WhenScalingOptions.APPLY_TO_CONTENT;

    o.transform(
        CS_INNER,
        AnchorPoint.CENTER_ANCHOR,
        [sx,0,0,sy,0,0],
        MatrixContent.SCALE_VALUES
        );

    app.transformPreferences.whenScaling = wsBkp;
}

// Sample code
// ---
setWidthHeightCS3(app.selection[0], "5cm", "100pt");

@+

Marc

Tags: InDesign

Similar Questions

Maybe you are looking for