Message 1 of 16
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, everyone. Now I am making a small project .NET. There I should embed a JSON data into DWG file.
I thought it maybe possible to use Xrecord. Followings are my portion of code.
public class roomrule
{
public Polyline pl;
public double width;
public double height;
public ObjectId objid;
public Handle hnd;
}
public void WriteToNOD()
{
List<JsonItems> jsonlists = new List<JsonItems>();
public static List<roomrule> aroomrule = new List<roomrule>();
IEnumerable<roomrule> rmrulelst = aroomrule.Distinct();
//I added some data to aroomrule already.
foreach (roomrule wrule in rmrulelst)
{
jsonlists.Add(new JsonItems
{
layer = "_Room",
OId = wrule.objid.ToString(),
width = wrule.width,
height = wrule.height,
hndle = wrule.hnd.ToString(),
projtype = (int)Plugin.projtypestate,
});
}
try
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
DBDictionary nod = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
Xrecord myXrecord = new Xrecord();
ResultBuffer resbuf = new ResultBuffer(new TypedValue((int)DxfCode.Text, jsonlists[0].layer), new TypedValue((int)DxfCode.Int64, jsonlists[0].OId),
new TypedValue((int)DxfCode.Int64, jsonlists[0].OId), new TypedValue((int)DxfCode.Int32,jsonlists[0].height),
new TypedValue((int)DxfCode.Int64,jsonlists[0].hndle),new TypedValue((int)DxfCode.Int32,jsonlists[0].projtype));
foreach(TypedValue tv in resbuf)
{
Application.ShowAlertDialog(
"===== Now write: " + tv.TypeCode.ToString()
+ ". " + tv.Value.ToString());
}
myXrecord.Data = resbuf;
nod.SetAt("PrevalData", myXrecord);
trans.AddNewlyCreatedDBObject(myXrecord, true);
trans.Commit();
}
}
catch (Exception e)
{
System.Diagnostics.Debug.Print(e.ToString());
}
}
Solved! Go to Solution.