CAD 开发小技巧
1. C#计算两点之间的距离.(09.10.7)
1 Point2d p0,p1;
double d1 = p1.GetDistanceTo(p0);
2 (p1-p0).Length 两点相减得到一个向量.再得到距离.
2. Vector2d 和 Vector3d 类
可以获得该向量的长度.是否垂直/平行另个向量.
3.用矩形框选择两个点
PromptCornerOptions pco = new PromptCornerOptions("\nSelect second corner of plot area: ", first);
ppr = ed.GetCorner(pco);
if (ppr.Status != PromptStatus.OK)
return;
Point3d second = ppr.Value;
4. 选择 块中的对象.Gets the name of an entity selected by the user using the supplied prompt selection options.
ObjectId i= ed.GetNestedEntity("PromptString").ObjectId;
5. PromptForSelectionEnding 事件.可以获得选择的对象
privatevoidcallback_PromptForSelectionEnding(objectsender, PromptForSelectionEndingEventArgse)
{
try
{
WriteLine(String.Format("PromptForSelectionEnding - ssCount:{0}", e.Selection.Count));
}
catch (System.Exceptionex)
{
Helper.Message(ex);
}
}
6.获得坐标点.
Tools.WriteMessage("computedPoint:"+e.Context.ComputedPoint.ToString()+e.Context.PointComputed.ToString()+"\n");//包括跟踪点
Tools.WriteMessage("lastPoint:"+ e.Context.LastPoint.ToString()+"\n");//最后一点.
Tools.WriteMessage("RawPoint:" + e.Context.RawPoint.ToString() + "\n");//光标所在的坐标点
7.
#region LINQ资料
每类产品,价格之和
varq =
frompindb.Products
grouppbyp.CategoryIDintog
selectnew {
g.Key,
TotalPrice = g.Sum(p => p.UnitPrice)
};
8.只有当实体加入到图形空间.才可以用ent.GeometricExtents属性
9. ent.IsNewObject 判断Ent是一个新对对象.也就是是否已经加入数据库