工作单位问题:(from Yongan.Fu )
MS中的方法单位都是UOR(Unit Of Resolution,这是一个非常大的一个数,基本上会是米的1万倍),而ORD中的方法默认单位则是米。
①C# MSCE .NET封装的对象模型,UOR单位;②C# MSCE COM封装的对象模型,主单位(基本上也可以认为是米单位);
③ORDCE 编程对象模型,米单位。
写一个功能最好只在一个对象模型里面写,实在需要用到两个以上的对象模型时,得特别注意单位的转换问题
public static void GetClosestPoint(string unparsed)
{
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
Element myElem = dgnModel.FindElementById((ElementId)1259083L);
CurvePrimitive cp = CurvePathQuery.ElementToCurveVector(myElem).GetPrimitive(0);
DPoint3d[] spacePoint = {new DPoint3d(4873336313.0,35949337874.0, 294702.0),
new DPoint3d(4873333904.0, 35950189744.0, 213879.0)};
double fraction;
DPoint3d curvePoint;
for (int i = 0; i < 2; i++)
{
cp.ClosestPointBounded(spacePoint[i], out fraction, out curvePoint);
LineElement line = new LineElement(dgnModel, null, new DSegment3d(spacePoint[i], curvePoint));
line.AddToModel();
}
}
第一个参数spacePoint为输入参数(从参数说明前缀[in]可知),即线外的一点
第二个参数fraction为输出参数(从前缀[out]可知)。它表示返回的曲线上的点在整条曲线上的比例(一个介于0.0~1.0之间的实数)。比如起点,fraction=0,中点,fraction=0.5,终点,fraction=1.0。顺便说一下函数名中的这个Bounded就是限定返回点一定要在曲线上的意思,保证fraction不会超出0.0~1.0之间的范围。
第三个参数curvePoint当然就是返回的线上的点了。