- UID
- 14
- 积分
- 8264
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-4
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Using Transient graphics By Balaji Ramamoorthy
In this post we looked at using graphics functions provided by AutoCAD API to show temporary graphics. In this post we will look at using the transient graphics API to draw temporary graphics. This API provides us much better control over the display of the graphics as compared to the graphics functions.
Here is a sample code that uses transient graphics to mark the intersection points of rectangle and a ray. To try this, draw a rectangle and select an internal point and the ray direction when prompted.
 - using Autodesk.AutoCAD.GraphicsInterface;
- DBObjectCollection _markers = null;
- [CommandMethod("Test")]
- public void TestMethod()
- {
- Document activeDoc
- = Application.DocumentManager.MdiActiveDocument;
- Database db = activeDoc.Database;
- Editor ed = activeDoc.Editor;
- PromptEntityOptions peo
- = new PromptEntityOptions("Select a polyline : ");
- peo.SetRejectMessage("Not a polyline");
- peo.AddAllowedClass
- (
- typeof(Autodesk.AutoCAD.DatabaseServices.Polyline),
- true
- );
- PromptEntityResult per = ed.GetEntity(peo);
- if (per.Status != PromptStatus.OK)
- return;
- ObjectId plOid = per.ObjectId;
- PromptPointResult ppr =
- ed.GetPoint
- (
- new PromptPointOptions("Select an internal point : ")
- );
- if (ppr.Status != PromptStatus.OK)
- return;
- Point3d testPoint = ppr.Value;
- PromptAngleOptions pao
- = new PromptAngleOptions("Specify ray direction");
- pao.BasePoint = testPoint;
- pao.UseBasePoint = true;
- PromptDoubleResult rayAngle = ed.GetAngle(pao);
- if (rayAngle.Status != PromptStatus.OK)
- return;
- Point3d tempPoint = testPoint.Add(Vector3d.XAxis);
- tempPoint
- = tempPoint.RotateBy(
- rayAngle.Value,
- Vector3d.ZAxis,
- testPoint
- );
- Vector3d rayDir = tempPoint - testPoint;
- ClearTransientGraphics();
- _markers = new DBObjectCollection();
- using (Transaction tr
- = db.TransactionManager.StartTransaction())
- {
- Curve plcurve = tr.GetObject(
- plOid,
- OpenMode.ForRead
- ) as Curve;
- for (int cnt = 0; cnt < 2; cnt++)
- {
- if (cnt == 1)
- rayDir = rayDir.Negate();
- using (Ray ray = new Ray())
- {
- ray.BasePoint = testPoint;
- ray.UnitDir = rayDir;
- Point3dCollection intersectionPts
- = new Point3dCollection();
- plcurve.IntersectWith(
- ray,
- Intersect.OnBothOperands,
- intersectionPts,
- IntPtr.Zero,
- IntPtr.Zero
- );
- foreach (Point3d pt in intersectionPts)
- {
- Circle marker
- = new Circle(pt, Vector3d.ZAxis, 0.2);
- marker.Color = Color.FromRgb(0, 255, 0);
- _markers.Add(marker);
- IntegerCollection intCol
- = new IntegerCollection();
- TransientManager tm
- = TransientManager.CurrentTransientManager;
- tm.AddTransient
- (
- marker,
- TransientDrawingMode.Highlight,
- 128,
- intCol
- );
- ed.WriteMessage("\n" + pt.ToString());
- }
- }
- }
- tr.Commit();
- }
- }
- void ClearTransientGraphics()
- {
- TransientManager tm
- = TransientManager.CurrentTransientManager;
- IntegerCollection intCol = new IntegerCollection();
- if (_markers != null)
- {
- foreach (DBObject marker in _markers)
- {
- tm.EraseTransient(
- marker,
- intCol
- );
- marker.Dispose();
- }
- }
- }
|
评分
-
查看全部评分
|