![]() |
【转帖】请教:为什么新建的表格(table)没有在图上显示出来
请教:为什么新建的表格(table)没有在图上显示出来
请教:为什么新建的表格(table)没有在图上显示出来 void createandsetdatalink() { acad::errorstatus es; acdbtable *ptbl; ptbl = new acdbtable(); const tchar *ptblstyle = acrx_t("my_style"); // set the table style acdbdictionary *pdict = null; acdbobjectid idtblstyle; acdbhostapplicationservices()->workingdatabase()->gettablestyledictionary(pdict,acdb::kforwrite); es = pdict->getat(ptblstyle,idtblstyle); pdict->close(); if(acad::eok == es) ptbl->settablestyle(idtblstyle); settablecolandrows(ptbl, 5, 5); ptbl->settextstring(3,3,l"my love"); ptbl->generatelayout(); // very very important, else expect crashes later on if(null == ptbl) { acutprintf(acrx_t("\nselected entity was not a table!")); return; } // get an excel file // struct resbuf *result; int rc; if ( (result = acutnewrb(rtstr)) == null) { ptbl->close(); acutprintf(acrx_t("\nunable to allocate buffer!")); return; } result->resval.rstring=null; rc = acedgetfiled( acrx_t("excel file"), // title acrx_t("c:\\"), // default pathname acrx_t("xls"), // default extension 16, // control flags result); // the path selected by the user. if (rc != rtnorm) { ptbl->close(); acutprintf(acrx_t("\nerror in selecting an excel file!")); return; } // retrieve the file name from the resbuf. achar filename[max_path]; _tcscpy(filename, result->resval.rstring); rc = acutrelrb(result); static achar smydatalink[max_path] = acrx_t("tllink"); // get the data link manager. acdbdatalinkmanager* pdlman = acdbhostapplicationservices()->workingdatabase()->getdatalinkmanager(); assert(pdlman); acdbobjectid iddl; acdbdatalink *pdl = null; // check if a data link with the name already exists. if so, remove it. if( pdlman->getdatalink(smydatalink, pdl, acdb::kforread) == acad::eok && pdl) { pdl->close(); es = pdlman->removedatalink(smydatalink, iddl); if( es != acad::eok ) { ptbl->close(); acutprintf(acrx_t("\nerror in removing the data link!")); return; } } // create a data link with the name. es = pdlman->createdatalink(acrx_t("acexcel"), smydatalink, acrx_t("this is a test for excel type data link."), filename, iddl); if( es != acad::eok ) { ptbl->close(); acutprintf(acrx_t("\nerror in creating data link!\nplease check if there is a sheet named 'sheet1' in the xls file.")); return; } // open the data link. es = acdbopenobject<acdbdatalink>(pdl, iddl, acdb::kforwrite); if ( es != acad::eok || !pdl ) { ptbl->close(); acutprintf(acrx_t("\nerror in opening the data link object!")); return; } // set options of the data link es = pdl->setoption(acdb::kdatalinkoptionpersistcache); es = pdl->setupdateoption(pdl->updateoption() | acdb::kupdateoptionallowsourceupdate); // close the data link. pdl->close(); // set data link to the table object at cell(2,2). es = ptbl->setdatalink(0,0, iddl, true); if( es != acad::eok ) { ptbl->close(); acutprintf(acrx_t("\nerror in setting data link to the selected table!\nplease check if there is a sheet named 'sheet1' in the xls file.")); return; } ptbl->setposition(acgepoint3d(0, 0, 0)); // don't forget to close the table object. ptbl->close(); } 忘记了一条语句 不好意思,原因找到了, 在ptbl->close();语句前面加上addenttodwg(acdbhostapplicationservices()->workingdatabase(),ptbl); 加上后一切就ok了. |
| 所有的时间均为北京时间。 现在的时间是 07:05 AM. |