|
- 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();
- }
- }
- }
- }
复制代码 |
|