EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

萧闫子 发表于 2014-1-8 15:11:25

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

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;

namespace EntityProperties
{
public class Commands
{

public void SetPropertiesOnEntity()
{
   Document doc =
      Application.DocumentManager.MdiActiveDocument;
   Database db = doc.Database;
   Editor ed = doc.Editor;

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

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

   Transaction tr =
      db.TransactionManager.StartTransaction();
   using (tr)
   {
      Entity ent =
      (Entity)
         tr.GetObject(
            per.ObjectId,
            OpenMode.ForRead
         );

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

      System.Windows.Forms.DialogResult dr;

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

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

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

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

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

      ent.UpgradeOpen();
      if (ent.Color != cd.Color)
      ent.Color = cd.Color;
      if (ent.LinetypeId != ltd.Linetype)
      ent.LinetypeId = ltd.Linetype;
      if (ent.LineWeight != lwd.LineWeight)
      ent.LineWeight = lwd.LineWeight;

      tr.Commit();
   }
}
}
}
页: [1]
查看完整版本: [用户交互] 使用AutoCAD标准对话框修改实体颜色、线型和线宽