1、保证有ARX
2、新建C#的类库dll;
3、添加引用(ARX目录下的inc文件夹中的所有dll)
添加类:
public class Class1
{
[CommandMethod("HelloWorld")]
public void HelloWorld()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("Hello World");
}
//测试写入
[CommandMethod("AddXRecordToEntity")]
public void AddXRecordToEntity()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
PromptEntityResult per = doc.Editor.GetEntity("\nSelect an entity: ");
if (per.Status != PromptStatus.OK)
{
return;
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Entity entity = tr.GetObject(per.ObjectId, OpenMode.ForWrite) as Entity;
if (entity.ExtensionDictionary == ObjectId.Null)
{
entity.CreateExtensionDictionary();
}
DBDictionary xDict = tr.GetObject(entity.ExtensionDictionary, OpenMode.ForRead) as DBDictionary;
if (!xDict.Contains("CAXDEV"))
{
xDict.UpgradeOpen();
Xrecord xRec = new Xrecord();
ResultBuffer rb = new ResultBuffer();
rb.Add(new TypedValue((int)DxfCode.Text, "Hello www.caxdev.com"));
rb.Add(new TypedValue((int)DxfCode.Int32, 123));
rb.Add(new TypedValue((int)DxfCode.Real, 1.2345));
xRec.Data = rb;
xDict.SetAt("CAXDEV", xRec);
tr.AddNewlyCreatedDBObject(xRec, true);
}
tr.Commit();
}
}
}