请教:为什么新建的表格(table)没有在图上显示出来
<p>void createAndSetDataLink()<br/>{<br/> Acad::ErrorStatus es;<br/> AcDbTable *pTbl; <br/> pTbl = new AcDbTable();</p><p> const TCHAR *pTblStyle = ACRX_T("MY_Style");<br/> <br/> // Set the Table Style<br/> AcDbDictionary *pDict = NULL;<br/> AcDbObjectId idTblStyle;<br/> acdbHostApplicationServices()->workingDatabase()->getTableStyleDictionary(pDict,AcDb::kForWrite);<br/> es = pDict->getAt(pTblStyle,idTblStyle);<br/> pDict->close();<br/> <br/> <br/> if(Acad::eOk == es) pTbl->setTableStyle(idTblStyle);<br/> setTableColAndRows(pTbl, 5, 5);</p><p> pTbl->setTextString(3,3,L"my love");</p><p> pTbl->generateLayout(); // Very very important, else expect crashes later on</p><p> if(NULL == pTbl) <br/> {<br/> acutPrintf(ACRX_T("\nSelected entity was not a table!"));<br/> return;<br/> }</p><p> // Get an Excel file<br/> //<br/> struct resbuf *result; <br/> int rc; </p><p> if ( (result = acutNewRb(RTSTR)) == NULL)<br/> {<br/> pTbl->close();<br/> acutPrintf(ACRX_T("\nUnable to allocate buffer!")); <br/> return;<br/> }</p><p> result->resval.rstring=NULL; </p><p> rc = acedGetFileD( ACRX_T("Excel File"), // Title<br/> ACRX_T("c:\\"), // Default pathname <br/> ACRX_T("xls"), // Default extension<br/> 16, // Control flags<br/> result); // The path selected by the user.<br/> if (rc != RTNORM) <br/> {<br/> pTbl->close();<br/> acutPrintf(ACRX_T("\nError in selecting an EXCEL file!")); <br/> return;<br/> }</p><p> // Retrieve the file name from the ResBuf.<br/> ACHAR fileName;<br/> _tcscpy(fileName, result->resval.rstring);<br/> rc = acutRelRb(result);</p><p> static ACHAR sMyDataLink = ACRX_T("TLLink");<br/> // Get the Data Link Manager.<br/> AcDbDataLinkManager* pDlMan = acdbHostApplicationServices()->workingDatabase()->getDataLinkManager();<br/> assert(pDlMan);</p><p> AcDbObjectId idDL;<br/> AcDbDataLink *pDL = NULL; <br/> // Check if a Data Link with the name already exists. If so, remove it.<br/> if( pDlMan->getDataLink(sMyDataLink, pDL, AcDb::kForRead) == Acad::eOk && pDL)<br/> {<br/> pDL->close();<br/> es = pDlMan->removeDataLink(sMyDataLink, idDL);<br/> if( es != Acad::eOk )<br/> {<br/> pTbl->close();<br/> acutPrintf(ACRX_T("\nError in removing the Data Link!"));<br/> return;<br/> }<br/> }<br/> </p><p> // Create a Data Link with the name.<br/> es = pDlMan->createDataLink(ACRX_T("AcExcel"), sMyDataLink, ACRX_T("This is a test for Excel type data link."), fileName, idDL);<br/> if( es != Acad::eOk )<br/> {<br/> pTbl->close();<br/> acutPrintf(ACRX_T("\nError in creating Data Link!\nPlease check if there is a sheet named 'Sheet1' in the XLS file."));<br/> return;<br/> }</p><p> // Open the Data Link.<br/> es = acdbOpenObject<AcDbDataLink>(pDL, idDL, AcDb::kForWrite);<br/> if ( es != Acad::eOk || !pDL )<br/> {<br/> pTbl->close();<br/> acutPrintf(ACRX_T("\nError in opening the Data Link object!")); <br/> return;<br/> }</p><p> // Set options of the Data Link<br/> es = pDL->setOption(AcDb::kDataLinkOptionPersistCache);<br/> es = pDL->setUpdateOption(pDL->updateOption() | AcDb::kUpdateOptionAllowSourceUpdate);</p><p> // Close the Data Link.<br/> pDL->close();</p><p> // Set data link to the table object at cell(2,2).<br/> es = pTbl->setDataLink(0,0, idDL, true);<br/> if( es != Acad::eOk )<br/> {<br/> pTbl->close();<br/> 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."));<br/> return;<br/> }<br/> pTbl->setPosition(AcGePoint3d(0, 0, 0));<br/> // Don't forget to close the table object.<br/> pTbl->close();<br/>}</p>忘记了一条语句
<p>不好意思,原因找到了, 在pTbl->close();语句前面加上addEntToDwg(acdbHostApplicationServices()->workingDatabase(),pTbl);</p><p>加上后一切就OK了.</p>
页:
[1]