Skip to main content
dublove
Legend
July 27, 2026
Question

How to set the positioning object in the following figure using a script?

  • July 27, 2026
  • 1 reply
  • 26 views

Hi everyone.

I want to use a script to set the object style for the following image.

I searched for some information and tried several times without success.

The annotation section seems incorrect, while the rest is correct.

reference material:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#AnchoredObjectSetting.html

Thank you very much.

 

imgObjStySet();
function imgObjStySet() {
var imgObjSty= app.documents[0].objectStyles.itemByName('img')
imgObjSty.setDimensionAttributeState(DimensionAttributes.WIDTH_ATTRIBUTE, true);
imgObjSty.transformAttributeOptions.transformAttrWidth = '52mm';
imgObjSty.textWrapPreferences.textWrapOffset = ["2mm", "2mm", "5mm", "5mm"];

//imgObjSty.anchoredObjectSettings = {
// anchorPoint: AnchorPoint.TOP_CENTER_ANCHOR,
// horizontalReferencePoint: AnchoredRelativeTo.TEXT_FRAME,
// verticalReferencePoint: VerticallyRelativeTo.LINE_BASELINE,
// horizontalAlignment: HorizontalAlignment.CENTER_ALIGN,
// verticalAlignment: VerticalAlignment.TOP_ALIGN,
// anchoredPosition: AnchorPosition.ANCHORED,
// anchorYoffset: 3,
//}

imgObjISty.properties = {
//Text wrapping
enableTextWrapAndOthers: true,
//Position and size
enableTransformAttributes: true,
//Positioning object
enableAnchoredObjectOptions: true,
}

}

 

    1 reply

    rob day
    Community Expert
    Community Expert
    July 27, 2026

    Something like this:

     

    var d = app.documents[0];
    var gf = d.objectStyles.add({name:"graphic frame"})
    var imgSty = d.objectStyles.add({name:"img", basedOn:gf})

    //set base image style
    gf.properties = d.objectStyles[1].properties
    imgSty.properties =
    {
    //objects and settings with their own properties are enclosed in brackets
    anchoredObjectSettings:{anchoredPosition:AnchorPosition.ANCHORED,
    anchorPoint:AnchorPoint.TOP_CENTER_ANCHOR,
    horizontalReferencePoint:AnchoredRelativeTo.TEXT_FRAME,
    verticalReferencePoint: VerticallyRelativeTo.LINE_BASELINE,
    pinPosition:true, spineRelative:true},
    //note brackets
    transformAttributeOptions:{transformAttrWidth: "52mm"},
    textWrapPreferences:{textWrapMode:TextWrapModes.BOUNDING_BOX_TEXT_WRAP, textWrapSide:TextWrapSideOptions.BOTH_SIDES, textWrapOffset:["2mm", "2mm", "5mm", "5mm"]}
    }

     

     

    dublove
    dubloveAuthor
    Legend
    July 28, 2026

    @rob day 

    Thank you rob day.
     

    imgSty.properties = 
    {
    textWrapPreferences:{
    }
    }

     

    imgSty = d.objectStyles.itemByName('img');
    imgSty.textWrapPreferences = {
    textWrapMode: TextWrapModes.BOUNDING_BOX_TEXT_WRAP,
    textWrapSide: TextWrapSideOptions.BOTH_SIDES,
    textWrapOffset: ["2mm", "2mm", "5mm", "5mm"],
    }


    Both of the above are invalid.
    I don't know why, but you must write it outside of the properties and write it separately. Like this:

    imgSty = d.objectStyles.itemByName('img');
    imgSty.textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP;
    imgSty.textWrapPreferences.textWrapSide = TextWrapSideOptions.BOTH_SIDES;
    imgSty.textWrapPreferences.textWrapOffset = ["2mm", "2mm", "5mm", "5mm"];