c#怎样在CAD词典内检索数据(已解决)
本帖最后由 xgr 于 2011-9-16 12:33 编辑看了教程还是不太懂,只知道创建词典条目,却不知道如何为词典条目设置和读取数据。
//将比例尺设置到词典对象,词典条目名称为Xggj_Tool
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Transaction trans = acCurDb.TransactionManager.StartTransaction();
DocumentLock dl = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
try
{
//首先,获取NOD……
DBDictionary NOD = (DBDictionary)trans.GetObject(acCurDb.NamedObjectsDictionaryId, OpenMode.ForWrite);
//定义一个自定义级别的字典"Xggj_Tool"
DBDictionary acmeDict;
try
{
//如果Xg_Tool不存在,则转到catch块,这里什么也不做
acmeDict = (DBDictionary)trans.GetObject(NOD.GetAt("Xggj_Tool"), OpenMode.ForRead);
}
catch
{
//如果Xggj_Tool不存在,则创建它并把它加入到NOD中……
acmeDict = new DBDictionary();
NOD.SetAt("Xggj_Tool", acmeDict);
trans.AddNewlyCreatedDBObject(acmeDict, true);
//定义子阶别的字典条目"Xggj_Scales"(比例尺)
DBDictionary divDict;
try
{
divDict = (DBDictionary)trans.GetObject(acmeDict.GetAt("Xggj_Scales"), OpenMode.ForWrite);
}
catch
{
divDict = new DBDictionary();
acmeDict.SetAt("Xggj_Scales", divDict);
trans.AddNewlyCreatedDBObject(divDict, true);
}
}
trans.Commit();
}
finally
{
dl.Dispose();
}
运行后可以查看到词典条目,请问怎样设置值何取值
LISP有
(vlax-ldata-get dict key )
(vlax-ldata-put dict key data )
c#怎么做??谢谢!
问题已解决
首先建立词典条目Xggj_Tool
并设置Xggj_Tool的值为1000,
//将比例尺设置到词典对象,词典条目名称为Xggj_Tool
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Transaction trans = acCurDb.TransactionManager.StartTransaction();
DocumentLock dl = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
try
{
//首先,获取NOD……
DBDictionary NOD = (DBDictionary)trans.GetObject(acCurDb.NamedObjectsDictionaryId, OpenMode.ForWrite);
//定义一个自定义级别的字典"Xggj_Tool"
DBDictionary acmeDict;
try
{
//如果Xg_Tool不存在,则转到catch块,这里什么也不做
acmeDict = (DBDictionary)trans.GetObject(NOD.GetAt("Xggj_Tool"), OpenMode.ForRead);
}
catch
{
//如果Xggj_Tool不存在,则创建它并把它加入到NOD中……
acmeDict = new DBDictionary();
NOD.SetAt("Xggj_Tool", acmeDict);
trans.AddNewlyCreatedDBObject(acmeDict, true);
Xrecord mgrXRec;
try
{
mgrXRec = (Xrecord)trans.GetObject(acmeDict.GetAt("Xggj_Scales"), OpenMode.ForWrite);
}
catch
{
mgrXRec = new Xrecord();
mgrXRec.Data = new ResultBuffer(new TypedValue((int)DxfCode.Text, "1000"));
acmeDict.SetAt("Xggj_Scales", mgrXRec);
trans.AddNewlyCreatedDBObject(mgrXRec, true);
}
}
trans.Commit();
}
finally
{
dl.Dispose();
}读取Xggj_Tool的值
//读取词典对象的值
Transaction trans1 = acCurDb.TransactionManager.StartTransaction();
DBDictionary NOD1 = (DBDictionary)trans1.GetObject(acCurDb.NamedObjectsDictionaryId, OpenMode.ForRead);
DBDictionary Dict1 = (DBDictionary)trans1.GetObject(NOD1.GetAt("Xggj_Tool"), OpenMode.ForRead);
Xrecord salesXRec = (Xrecord)trans1.GetObject(Dict1.GetAt("Xggj_Scales"), OpenMode.ForRead);
TypedValue resBuf = salesXRec.Data.AsArray();
acDoc.Editor.WriteMessage("当前词典对象的值为:" + Convert.ToString(resBuf.Value));
trans1.Commit();运行命令行显示:“当前词典对象的值为:1000“
页:
[1]