对于CAD中的实体进行筛选等操作,常常会用到实体的XData属性,下面介绍一下实体的XData的增删改。
//XData的新增,修改跟新增一样,new一个ResultBuffer,赋值即可 SEO靠我 Document doc=Application.DocumentManager.MdiActiveDocument; using (DocumentLock dl = doc.LSEO靠我ockDocument()) {using (Transaction trans = doc.TransactionManager.StartTransaction()){DBObjeSEO靠我ct obj=trans.GetObjectId(id,OpenMode.ForWrite);//id为要设置的实体的ObjectId,也可以对实体直接进行设置也就是obj可以为Polyline、BlSEO靠我ockReference、MText、DBText、Hatch...string regAppName="YourAppName";//你的注册应用程序名RegAppTable rat = (RegASEO靠我ppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForWrite, false);if (!rat.Has(regAppName)){rat.UpSEO靠我gradeOpen();RegAppTableRecord ratr = new RegAppTableRecord();ratr.Name = regAppName;rat.Add(ratr);trSEO靠我ans.AddNewlyCreatedDBObject(ratr, true);}ResultBuffer resBuf = new ResultBuffer();resBuf.Add(new TypSEO靠我edValue(1001, regAppName)); resBuf.Add(new TypedValue(1000, "YourContents")); resBuf.Add(new TypedVaSEO靠我lue(1000, "YourContents")); obj.XData = resBuf;trans.Comit()} } //XData的删除 SEO靠我Document doc=Application.DocumentManager.MdiActiveDocument; using (DocumentLock dl = doc.LocSEO靠我kDocument()) {using (Transaction trans = doc.TransactionManager.StartTransaction()){DBObjectSEO靠我 obj=trans.GetObjectId(id,OpenMode.ForWrite);//id为要设置的实体的ObjectId,也可以对实体直接进行设置也就是obj可以为Polyline、BlocSEO靠我kReference、MText、DBText、Hatch...string regAppName="YourAppName";//你的注册应用程序名RegAppTable rat = (RegAppSEO靠我Table)trans.GetObject(db.RegAppTableId, OpenMode.ForWrite, false);if (!rat.Has(regAppName)){RegAppTaSEO靠我bleRecord ratr = (RegAppTableRecord)rat[regAppName].GetObject(OpenMode.ForWrite);ratr.Erase();}transSEO靠我.Comit()} }网站备案号:浙ICP备17034767号-2