在Python中通过MassProp命令处理返回结果

问题描述 投票:0回答:1

我正在尝试通过Python代码中的MassProp命令处理返回结果:


acad.doc.SendCommand("MassProp")
res1 = acad.doc.GetVariable("AREA");
res2 = acad.doc.GetVariable("USERR2");
res3 = acad.doc.GetVariable("USERR3");
res4 = acad.doc.GetVariable("USERR4")
res5 = acad.doc.GetVariable("USERR5")

我试图通过读取 USERR1-USERR5 环境变量来做到这一点。但它们的值都是 0.0。 但 Autocad env 在屏幕上返回某些区域的结果:

---------------- 地区 ---------------- 面积:373.3232 周长:79.9499 边界框:X:9.9847 -- 35.0884 是:5.0765——19.9477 质心:X:22.5366 是:12.5121 转动惯量:X:65324.9322 是:209215.5765 惯性积:XY:-105269.7286 回转半径:X:13.2281 是:23.6731 主力矩和关于质心的 X-Y 方向: I:6880.1556 沿 [1.0000 0.0000] J:19605.5483 沿 [0.0000 1.0000]

请问如何在Python代码中获取这些参数?

python lisp autocad autocad-scripts
1个回答
0
投票

你有文档,可以直接查询实体, 忽略上面的 axDoc 部分,那是我的实用工具

import traceback
from pyrx_impx import Rx, Ge, Gi, Db, Ap, Ed, Ax

def PyRxCmd_xdoit() -> None:
    try:
        axApp = Ax.getApp()
        axDoc = axApp.ActiveDocument
        reslt = axDoc.Utility.GetEntity("\nSelect a solid")
        solid = Ax.IAcad3DSolid(reslt[0])
        mp = {}
        mp['BoundingBox'] = solid.GetBoundingBox()
        mp['Centroid'] = solid.Centroid
        mp['MomentOfInertia'] = solid.MomentOfInertia
        mp['ProductOfInertia'] = solid.ProductOfInertia
        print(mp)
    except Exception as err:
        traceback.print_exception(err)
© www.soinside.com 2019 - 2024. All rights reserved.