// AutoCAD 2009
// Based on the http://through-the-interface.typepad.com/through_the_interface/2007/12/creating-an-aut.html
using cad = Autodesk.AutoCAD.ApplicationServices.Application;
using App = Autodesk.AutoCAD.ApplicationServices;
using Db = Autodesk.AutoCAD.DatabaseServices;
using Ed = Autodesk.AutoCAD.EditorInput;
using Rtm = Autodesk.AutoCAD.Runtime;
using Gem = Autodesk.AutoCAD.Geometry;
namespace WipeoutApplication {
public class Commands : Rtm.IExtensionApplication {
static Db.ObjectId id = Db.ObjectId.Null;
[Rtm.CommandMethod("wshow")]
public void wshow() {
set_visibility(true);
}
[Rtm.CommandMethod("whide")]
public void whide() {
set_visibility(false);
}
void set_visibility(System.Boolean value) {
if (id != Db.ObjectId.Null && !id.IsErased && id.IsValid) {
App.Document doc = cad.DocumentManager.MdiActiveDocument;
Db.Database db = doc.Database;
using (Db.Transaction tr = db.TransactionManager.StartTransaction()) {
Db.Wipeout wo = tr.GetObject(id, Db.OpenMode.ForWrite) as Db.Wipeout;
wo.Visible = value;
tr.Commit();
}
}
}
public void Initialize() {
App.Document doc = cad.DocumentManager.MdiActiveDocument;
Db.Database db = doc.Database;
Ed.Editor ed = doc.Editor;
ed.WriteMessage("The library is loaded.\n");
using (Db.Transaction tr = db.TransactionManager.StartTransaction()) {
Db.BlockTable bt = (Db.BlockTable)tr.GetObject(
db.BlockTableId, Db.OpenMode.ForRead, false);
Db.BlockTableRecord btr = (Db.BlockTableRecord)tr.GetObject(
bt[Db.BlockTableRecord.ModelSpace], Db.OpenMode.ForWrite, false);
Gem.Point2dCollection pts = new Gem.Point2dCollection(5);
pts.Add(new Gem.Point2d(0.0, 0.0));
pts.Add(new Gem.Point2d(100.0, 0.0));
pts.Add(new Gem.Point2d(100.0, 100.0));
pts.Add(new Gem.Point2d(0.0, 100.0));
pts.Add(new Gem.Point2d(0.0, 0.0));
Db.Wipeout wo = new Db.Wipeout();
wo.SetDatabaseDefaults(db);
wo.SetFrom(pts, new Gem.Vector3d(0.0, 0.0, 0.1));
wo.Visible = false; // Look at this.
btr.AppendEntity(wo);
tr.AddNewlyCreatedDBObject(wo, true);
id = wo.ObjectId;
tr.Commit();
}
}
public void Terminate() {
// throw new System.NotImplementedException();
}
}
}