You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CEP/JavaScript如何获取使用geometricBounds创建的圆形的中心点坐标

解答

你使用的是Adobe InDesign的ExtendScript脚本环境,不存在myCircle.center这类直接获取圆心的内置属性,需要通过图形的几何边界手动计算,计算逻辑非常简单:

  1. InDesign中所有页面对象的geometricBounds属性返回固定格式的数组:[yMin, xMin, yMax, xMax],分别对应图形的上边界、左边界、下边界、右边界坐标
  2. 圆心x坐标为左右边界的平均值,y坐标为上下边界的平均值

代码实现

// 方式1:直接计算
var bounds = myCircle.geometricBounds;
var centerX = (bounds[1] + bounds[3]) / 2;
var centerY = (bounds[0] + bounds[2]) / 2;

// 方式2:封装为通用方法,适合多次调用,支持所有带几何边界的页面对象
function getShapeCenter(targetShape) {
    var bounds = targetShape.geometricBounds;
    return {
        x: (bounds[1] + bounds[3]) / 2,
        y: (bounds[0] + bounds[2]) / 2
    };
}
// 调用方法
var centerOfMyCircle = getShapeCenter(myCircle);

内容的提问来源于stack exchange,提问作者Fitspade

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 22:39:06