EaBIM

标题: [用户交互] 使用AutoCAD标准对话框修改实体颜色、线型和线宽 [打印本页]

作者: 萧闫子    时间: 2014-1-8 15:11
标题: [用户交互] 使用AutoCAD标准对话框修改实体颜色、线型和线宽
  1. using Autodesk.AutoCAD.Runtime;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Windows;

  6. namespace EntityProperties
  7. {
  8. public class Commands
  9. {
  10. [CommandMethod("SPE")]
  11. public void SetPropertiesOnEntity()
  12. {
  13.    Document doc =
  14.       Application.DocumentManager.MdiActiveDocument;
  15.    Database db = doc.Database;
  16.    Editor ed = doc.Editor;

  17.    PromptEntityResult per =
  18.       ed.GetEntity(
  19.       "\n选择要修改的实体: "
  20.       );

  21.    if (per.Status != PromptStatus.OK)
  22.       return;

  23.    Transaction tr =
  24.       db.TransactionManager.StartTransaction();
  25.    using (tr)
  26.    {
  27.       Entity ent =
  28.       (Entity)
  29.          tr.GetObject(
  30.             per.ObjectId,
  31.             OpenMode.ForRead
  32.          );

  33.       ColorDialog cd = new ColorDialog();
  34.       cd.Color = ent.Color;

  35.       System.Windows.Forms.DialogResult dr;

  36.       dr = cd.ShowDialog();
  37.       if (dr != System.Windows.Forms.DialogResult.OK)
  38.       return;

  39.       LinetypeDialog ltd = new LinetypeDialog();
  40.       ltd.Linetype = ent.LinetypeId;

  41.       dr = ltd.ShowDialog();
  42.       if (dr != System.Windows.Forms.DialogResult.OK)
  43.       return;

  44.       LineWeightDialog lwd = new LineWeightDialog();
  45.       lwd.LineWeight = ent.LineWeight;

  46.       dr = lwd.ShowDialog();
  47.       if (dr != System.Windows.Forms.DialogResult.OK)
  48.       return;

  49.       ent.UpgradeOpen();
  50.       if (ent.Color != cd.Color)
  51.       ent.Color = cd.Color;
  52.       if (ent.LinetypeId != ltd.Linetype)
  53.       ent.LinetypeId = ltd.Linetype;
  54.       if (ent.LineWeight != lwd.LineWeight)
  55.       ent.LineWeight = lwd.LineWeight;

  56.       tr.Commit();
  57.    }
  58. }
  59. }
  60. }
复制代码





欢迎光临 EaBIM (https://eabim.net/) Powered by Discuz! X3.2