给字典中添加键值时出现问题,求教!!
DBDictionary nod4 = (DBDictionary)trans.GetObject(nodSw3, OpenMode.ForWrite);Xrecord xrec = new Xrecord();
xrec.Data = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataWorldXCoordinate, new Point3d(10, 10, 0)));
ObjectId nodSw4 = nod4.SetAt("PM_qyPoint1", xrec);
trans.AddNewlyCreatedDBObject(xrec, true);
xrec.Data = new ResultBuffer(new TypedValue((int)DxfCode.XCoordinate, new Point3d(20,20,0)));
ObjectId nodSw5 = nod4.SetAt("PM_qyPoint2",xrec);
trans.AddNewlyCreatedDBObject(xrec, true);
这段代码的最后一句调试时报错 说无法创建。
求教是怎么个情况啊!
nod4是nod3的引用吧,nod3不是已经在database里了吗? 我试验了一下 发现给字典添加键值 一个commit只能添加一个键值。 程序改成下面这个样子就能执行了不知道我理解的对不对。还请大家指教。
public class testNod1
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ObjectId objTemp = new ObjectId();
public void Test()
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
DBDictionary nod = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
DBDictionary sw_database = new DBDictionary();
ObjectId nodSw = nod.SetAt("sky_sw9527_database", sw_database);
trans.AddNewlyCreatedDBObject(sw_database, true);
DBDictionary nod1 = (DBDictionary)trans.GetObject(nodSw, OpenMode.ForWrite);
DBDictionary swGC_database = new DBDictionary();
ObjectId nodSw1 = nod1.SetAt("GC1", swGC_database);
trans.AddNewlyCreatedDBObject(swGC_database, true);
DBDictionary nod2 = (DBDictionary)trans.GetObject(nodSw1, OpenMode.ForWrite);
DBDictionary swPM_database = new DBDictionary();
ObjectId nodSw2 = nod2.SetAt("PMCD", swPM_database);
trans.AddNewlyCreatedDBObject(swPM_database, true);
DBDictionary nod3 = (DBDictionary)trans.GetObject(nodSw2, OpenMode.ForWrite);
DBDictionary swPM1_database = new DBDictionary();
ObjectId nodSw3 = nod3.SetAt("PM1", swPM1_database);
trans.AddNewlyCreatedDBObject(swPM1_database, true);
DBDictionary nod4 = (DBDictionary)trans.GetObject(nodSw3, OpenMode.ForWrite);
Xrecord xrec = new Xrecord();
xrec.Data = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataWorldXCoordinate, new Point3d(10, 10, 0)));
ObjectId nodSw4 = nod4.SetAt("PM_qyPoint1", xrec);
trans.AddNewlyCreatedDBObject(xrec, true);
objTemp = nodSw3;
trans.Commit();
}
using (Transaction trans = db.TransactionManager.StartTransaction())
{
DBDictionary nod4 = (DBDictionary)trans.GetObject(objTemp, OpenMode.ForWrite);
Xrecord xrec = new Xrecord();
xrec.Data = new ResultBuffer(new TypedValue((int)DxfCode.Bool, true));
ObjectId nodSw5 = nod4.SetAt("PM_qykObjectId", xrec);
trans.AddNewlyCreatedDBObject(xrec, true);
trans.Commit();
}
using (Transaction trans = db.TransactionManager.StartTransaction())
{
DBDictionary nod4 = (DBDictionary)trans.GetObject(objTemp, OpenMode.ForWrite);
Xrecord xrec = new Xrecord();
xrec.Data = new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataWorldXCoordinate, new Point3d(10, 10, 0)));
ObjectId nodSw6 = nod4.SetAt("PM_qyPoint2", xrec);
trans.AddNewlyCreatedDBObject(xrec, true);
trans.Commit();
}
}
}
页:
[1]