明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1867|回复: 1

[PHP] 代码着色试试

[复制链接]
发表于 2011-2-14 09:55 | 显示全部楼层 |阅读模式
  1. #
  2. using System;
  3. #
  4. using Autodesk.AutoCAD.Runtime;
  5. #
  6. using Autodesk.AutoCAD.Geometry;
  7. #
  8. using Autodesk.AutoCAD.ApplicationServices;
  9. #
  10. using Autodesk.AutoCAD.DatabaseServices;
  11. #
  12. using Autodesk.AutoCAD.EditorInput;
  13. #
  14. namespace CADTest
  15. #
  16. {
  17. #
  18.     public class Class1
  19. #
  20.     {
  21. #
  22.         [CommandMethod("c2p")]
  23. #
  24.         public void CircleToPloyline()
  25. #
  26.         {
  27. #
  28.             Document doc = Application.DocumentManager.MdiActiveDocument;
  29. #
  30.             Database db = doc.Database;
  31. #
  32.             Editor ed = doc.Editor;
  33. #
  34.             Transaction trans = db.TransactionManager.StartTransaction();
  35. #
  36.             BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
  37. #
  38.             BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  39. #
  40.             PromptSelectionResult psr = ed.GetSelection();
  41. #
  42.             //获取选择集,这里就不过滤了
  43. #
  44.             SelectionSet ss = null;
  45. #
  46.             if (psr.Status == PromptStatus.OK)
  47. #
  48.             {
  49. #
  50.                 ss = psr.Value;
  51. #
  52.                 foreach (SelectedObject so in ss)
  53. #
  54.                 {
  55. #
  56.                     Circle c = trans.GetObject(so.ObjectId, OpenMode.ForWrite) as Circle;
  57. #
  58.                     double r = c.Radius;
  59. #
  60.                     Point3d cc = c.Center;
  61. #
  62.                     Point2d p1 = new Point2d(cc.X + r, cc.Y);
  63. #
  64.                     Point2d p2 = new Point2d(cc.X - r, cc.Y);
  65. #
  66.                     Polyline poly = new Polyline();
  67. #
  68.                     poly.AddVertexAt(0, p1, 1, 0, 0);
  69. #
  70.                     poly.AddVertexAt(1, p2, 1, 0, 0);
  71. #
  72.                     poly.AddVertexAt(2, p1, 1, 0, 0);
  73. #
  74.                     btr.AppendEntity(poly);
  75. #
  76.                     trans.AddNewlyCreatedDBObject(poly, true);
  77. #
  78.                     c.Erase(true);
  79. #
  80.                 }
  81. #
  82.             }
  83. #
  84.             trans.Commit();
  85. #
  86.             trans.Dispose();
  87. #
  88.         }
  89. #
  90. #
  91.         [CommandMethod("GET")]
  92. #
  93.         public void GetEntityType()
  94. #
  95.         {
  96. #
  97.             Document doc = Application.DocumentManager.MdiActiveDocument;
  98. #
  99.             Database db = doc.Database;
  100. #
  101.             Editor ed = doc.Editor;
  102. #
  103.             PromptEntityOptions peo = new PromptEntityOptions("请选择一个实体");
  104. #
  105.             PromptEntityResult per = null;
  106. #
  107.             try
  108. #
  109.             {
  110. #
  111.                 per = ed.GetEntity(peo);
  112. #
  113.                 if (per.Status == PromptStatus.OK)
  114. #
  115.                 {
  116. #
  117.                     ObjectId id = per.ObjectId;
  118. #
  119.                     Transaction trans = db.TransactionManager.StartTransaction();
  120. #
  121.                     Entity ent = (Entity)trans.GetObject(id, OpenMode.ForRead, true);
  122. #
  123. #
  124.                     ed.WriteMessage("\n实体ObjectId 为:" + ent.ObjectId + "\n实体类型为:" + ent.GetType().FullName);
  125. #
  126.                     trans.Commit();
  127. #
  128.                     trans.Dispose();
  129. #
  130.                 }
  131. #
  132.             }
  133. #
  134.             catch (Autodesk.AutoCAD.Runtime.Exception exc)
  135. #
  136.             {
  137. #
  138.                 ed.WriteMessage("发生异常,原因为:" + exc.Message);
  139. #
  140.             }
  141. #
  142.         }
  143. #
  144.     }
  145. #
  146. }


发表于 2017-10-30 11:11 | 显示全部楼层
回帖是一种美德!感谢楼主的无私分享 谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-19 12:39 , Processed in 0.338239 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表