一、3D坐标转2D坐标指在零件层面获得的点坐标,在进入草图编辑状态时,该点转换为在草图中的坐标值,只有XY轴;
注:如需将装配体层面的坐标转换为零件草图的坐标,需先将绝对坐标转换为零件的相对坐标,然后再进行3D坐标转2D坐标;
代码如下:
public double[] ModelToSketchCoordinate(double[] point)//传入需要3D坐标值
{
MathUtility swMathUtil = (MathUtility)SwApp.GetMathUtility();
MathPoint swMathPoint;
swMathPoint = swMathUtil.CreatePoint((object)point);
Sketch sketch = ActiveDoc.SketchManager.ActiveSketch;//获取当前活跃的草图
IMathTransform swMathTrans = sketch.ModelToSketchTransform;
//swMathTrans = swMathTrans .Inverse();//反转,由2D坐标转为3D坐标
swMathPoint = swMathPoint.MultiplyTransform(swMathTrans);
double[] sketchCoordinate = swMathPoint.ArrayData;
return sketchCoordinate;//返回转换后的2D坐标,只有XY值
}
模型空间的点是绝对的,但是相对于不同的坐标系具有不同的坐标值。