|
组件没办法,零件可以实体边界投影
//获取Solid的轮廓尺寸,投影实体曲面
function EvalSolidOutline(solid){
var item = Selector.SelOneModelItem("sldface,datum,csys");//选择一个实体曲面,平面或者坐标系的几何项目
var transform;
try {
transform = item.CoordSys;//获取几何项目的转换矩阵
} catch (error) {
transform = solid.ListItems(ModelItemType.ITEM_COORD_SYS).Item(0).CoordSys;//未选择或者曲面不具有转换矩阵时则获取默认坐标系的转换矩阵
}
session.CurrentWindow.Repaint();
//获取相应的坐标轴
var vx = transform.GetXAxis();
var vy = transform.GetYAxis();
var vz = transform.GetZAxis();
transform.Invert();//将矩阵转置
//获取模型质心的转换坐标
var xMax = transform.TransformPoint( solid. GetMassProperty(null).GravityCenter).Item(0);
var xMin = transform.TransformPoint( solid. GetMassProperty(null).GravityCenter).Item(0);
var yMax = transform.TransformPoint( solid. GetMassProperty(null).GravityCenter).Item(1);
var yMin = transform.TransformPoint( solid. GetMassProperty(null).GravityCenter).Item(1);
var zMax = transform.TransformPoint( solid. GetMassProperty(null).GravityCenter).Item(2);
var zMin = transform.TransformPoint( solid. GetMassProperty(null).GravityCenter).Item(2);
var surfaces = solid.ListItems(ModelItemType.ITEM_SURFACE);//列举模型中的所有实体曲面
for (var i = 0; i < surfaces.Count; i++) {
var surf = surfaces.Item(i);
//曲面在x方向的投影极限点
var max = transform.TransformPoint(surf.EvalMaximum(vx)).Item(0);
var min = transform.TransformPoint(surf.EvalMinimum(vx)).Item(0);
if (max > xMax) xMax = max;
if (min < xMin) xMin = min;
//曲面在y方向的投影极限点
max = transform.TransformPoint(surf.EvalMaximum(vy)).Item(1);
min = transform.TransformPoint(surf.EvalMinimum(vy)).Item(1);
if (max > yMax) yMax = max;
if (min < yMin) yMin = min;
//曲面在y方向的投影极限点
max = transform.TransformPoint(surf.EvalMaximum(vz)).Item(2);
min = transform.TransformPoint(surf.EvalMinimum(vz)).Item(2);
if (max > zMax) zMax = max;
if (min < zMin) zMin = min;
}
//计算最大极限点并用arry数组排序
var arry = new Array();
arry.push(Math.abs((xMax - xMin).toFixed(2)));
arry.push(Math.abs((yMax - yMin).toFixed(2)));
arry.push(Math.abs((zMax - zMin).toFixed(2)));
arry.sort();
return arry[2] + "x" + arry[1] + "x" + arry[0];
} |
评分
-
查看全部评分
|