EaBIM
标题:
[用户交互] 使用AutoCAD标准对话框修改实体颜色、线型和线宽
[打印本页]
作者:
萧闫子
时间:
2014-1-8 15:11
标题:
[用户交互] 使用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
{
[CommandMethod("SPE")]
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();
}
}
}
}
复制代码
欢迎光临 EaBIM (https://eabim.net/)
Powered by Discuz! X3.2