![]() |
【转帖】[求助]求助一个关于扩展数据的问题
[求助]求助一个关于扩展数据的问题
www.dimcax.com [求助]求助一个关于扩展数据的问题 怎么样把以前添加的autocad扩展数据更新成新的或删除 下面是网上找到的清除扩展数据的代码,我看不懂 void delxdata() { ads_name enam; ads_point pt; int ret = acedentsel ("\nselect an object:", enam, pt); if ( ret!= rtnorm) { return; } acdbobjectid objid; acdbgetobjectid(objid, enam); acdbentity *pent; acdbopenacdbentity(pent, objid, acdb::kforwrite); resbuf *xdata = pent->xdata(null); if (xdata) { xdata->rbnext = null; pent->setxdata(xdata); acutrelrb(xdata); } pent->close(); } public void delxdata() { ads_name enam; ads_point pt; int ret = acedentsel ("\nselect an object:", enam, pt); //点选获得一个实体 if ( ret!= rtnorm) { return; } acdbobjectid objid; acdbgetobjectid(objid, enam); //获得实体的id acdbentity *pent; acdbopenacdbentity(pent, objid, acdb::kforwrite); //通过objectid打开实体来编辑 resbuf *xdata = pent->xdata(null); //获取实体的扩展数据结果缓冲区链表 if (xdata) //如果该扩展数据结果缓冲区链表不为空 { xdata->rbnext = null; //将该结果缓冲区链表的后续指针置为空 pent->setxdata(xdata); //将该实体的扩展数据设为置为空了的结果缓冲区 acutrelrb(xdata); //释放链表 } pent->close(); } 本想发贴咨询一下在autocad , resstring[; appname[0] = resstring[0] = '\0'; acedgetstring(null, "enter application name: ", appname); acedgetstring(null, "enter string to be added: ", resstring); struct resbuf *prb, *ptemp; prb = pobj->xdata(appname); if (prb != null) { // if xdata is present, then walk to the // end of the list. // for (ptemp = prb; ptemp->rbnext != null; ptemp = ptemp->rbnext) { ; } } else { // if xdata is not present, register the application // and add appname to the first resbuf in the list. // notice that there is no -3 group as there is in // autolisp. this is only the xdata so // the -3 xdata-start marker isn't needed. // acdbregapp(appname); prb = acutnewrb(acdb::kdxfregappname); ptemp = prb; ptemp->resval.rstring = (char*) malloc(strlen(appname) + 1); strcpy(ptemp->resval.rstring, appname); } // add user-specified string to the xdata. // ptemp->rbnext = acutnewrb(acdb::kdxfxdasciistring); ptemp = ptemp->rbnext; ptemp->resval.rstring = (char*) malloc(strlen(resstring) + 1); strcpy(ptemp->resval.rstring, resstring); // the following code shows the use of upgradeopen() // to change the entity from read to write. // pobj->upgradeopen(); pobj->setxdata(prb); pobj->close(); acutrelrb(prb); } 问题是在autocad , openmode.forwrite, false); //create the custom per-employee data xrecord xrec = new xrecord(); //we want to add //name//, //salary// and //division// information. here is how: xrec.data = new resultbuffer( new typedvalue((int)dxfcode.text, name), new typedvalue((int)dxfcode.real, salary), new typedvalue((int)dxfcode.text, division)); //next, we need to add this data to the //extension dictionary// of the employee. br.createextensiondictionary(); dbdictionary brextdict = (dbdictionary)trans.getobject(br.extensiondictionary, openmode.forwrite, false); brextdict.setat("employeedata", xrec); //set our xrecord in the dictionary at //employeedata//. trans.addnewlycreateddbobject(xrec, true); return xrec.objectid; } catch { return objectid.null; } } 但为何添加xdata扩展数据就会报错ebaddxfsequence呢? public void addxdata(entity ent,string name,string salary,string division) { database db = hostapplicationservices.workingdatabase; transaction myt = db.transactionmanager.starttransaction(); try { blocktable bt = (blocktable)myt.getobject(db.blocktableid, openmode.forwrite, false); blocktablerecord btr = (blocktablerecord)myt.getobject(bt[blocktablerecord.modelspace], openmode.forwrite, false); ent.xdata = new resultbuffer(); ent.xdata = new resultbuffer( new typedvalue((int)dxfcode.text, name), new typedvalue((int)dxfcode.real, salary), new typedvalue((int)dxfcode.text, division)); btr.appendentity(ent); myt.addnewlycreateddbobject(ent, true); } catch { } } 后来又试过如下方法: autodesk.autocad.databaseservices.symbolutilityservices.isregappacadname("name"); pent.xdata = new resultbuffer(new typedvalue((int)dxfcode.extendeddataregappname,"name")); pent.xdata.add(new typedvalue((int)dxfcode.extendeddatacontrolstring, "this is a test!")); 也报错……为eregappidnotfound,应该是因为未注册应用程序名的原因, 求教全局函数acdbregapp(appname)在c#中的对应方法!! public void addxdata() { editor ed = application.documentmanager.mdiactivedocument.editor; ed.writemessage("添加扩充数据xdata\n"); promptentityoptions entops = new promptentityoptions("选择要打开的对象\n"); promptentityresult entres; entres = ed.getentity(entops); if (entres.status != promptstatus.ok) { ed.writemessage("选择对象失败,退出"); return; } objectid objid = entres.objectid; database db = hostapplicationservices.workingdatabase; using (transaction trans = db.transactionmanager.starttransaction()) { entity ent = trans.getobject(objid, openmode.forwrite) as entity ; ent.colorindex = 1; regapptable apptbl = trans.getobject(db.regapptableid, openmode.forwrite) as regapptable ; if (!apptbl.has("myappname")) { regapptablerecord apptblrcd = new regapptablerecord(); apptblrcd.name = "myappname"; apptbl.add(apptblrcd); trans.addnewlycreateddbobject(apptblrcd, true); } resultbuffer resbuf = new resultbuffer();//new typedvalue(1001, "myappname"), new typedvalue(1000, "开发部门")); resbuf.add(new typedvalue(1001, "myappname"));//注册程序名称 resbuf.add(new typedvalue(1000 , " hongxian qin"));//姓名 resbuf.add(new typedvalue(1000 , " 工程部"));//部门 resbuf.add(new typedvalue(1040, [commandmethod("getxdata")] public void getxdata() { editor ed = application.documentmanager.mdiactivedocument.editor; ed.writemessage("获取扩充数据xdata\n"); promptentityoptions entops = new promptentityoptions("选择要打开的对象"); promptentityresult entres = ed.getentity(pr); if (entres.status != promptstatus.ok) { ed.writemessage("选择对象失败,退出"); return; } database db = autodesk.autocad.applicationservices.application.documentmanager.mdiactivedocument.database; using (transaction tr = db.transactionmanager.starttransaction()) { entity ent = (entity)tr.getobject(res.objectid, openmode.forread); resultbuffer resbuf = ent.xdata; if (rb != null) { // ienumerator iter = resbuf.getenumerator(); while (iter.movenext()) { typedvalue tmpval = (typedvalue)iter.current; ed.writemessage(tmpval.typecode.tostring() + ":"); ed.writemessage(tmpval.value.tostring() + "\n"); } } } } 简单的活着 |
所有的时间均为北京时间。 现在的时间是 02:02 AM. |