Hi All,
I am very new to .NET C# and I am try to rewrite a application I wrote in AutoLisp to .NET C#. I am looking for a working xdata tool to Add, Edit and Remove xdata to an object. I have been trying to get this to work but the compiler tell me to go find ResultList, List, and Cast missing assembly references.
Can someone... anyone help?
Here is the code:
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
namespace Xdata
{
public class MyXdata
{
[CommandMethod("PUTXDATA")]
public void test2()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
var resEnt = ed.GetEntity("Select a Entity");
if (resEnt.Status == PromptStatus.OK)
{
using (var tr = db.TransactionManager.StartTransaction())
{
Entity ent = tr.GetObject(resEnt.ObjectId, OpenMode.ForWrite) as Entity;
var rb = ent.GetXDataForApplication("MyTestApp");
if (rb == null)
{
var rat = tr.GetObject(db.RegAppTableId, OpenMode.ForWrite) as RegAppTable;
if (!rat.Has("MyTestApp"))
{
var ratr = new RegAppTableRecord();
ratr.Name = "MyTestApp";
rat.Add(ratr);
tr.AddNewlyCreatedDBObject(ratr, true);
}
ent.XData = new ResultList { { 1001, "MyTestApp" }, { 1000, "value1" } };
}
else
{
List<TypedValue> values = rb.Cast<TypedValue>().ToList();
values.Add(new TypedValue(1000, "value" + values.Count.ToString()));
ent.XData = new ResultBuffer(values.ToArray());
}
tr.Commit();
}
}
}
}
}