netthree 发表于 2008-3-4 20:31:00

请教:为什么新建的表格(table)没有在图上显示出来

<p>void createAndSetDataLink()<br/>{<br/>&nbsp;&nbsp;&nbsp; Acad::ErrorStatus es;<br/>&nbsp;AcDbTable *pTbl;&nbsp;<br/>&nbsp;pTbl = new AcDbTable();</p><p>&nbsp;const TCHAR *pTblStyle = ACRX_T("MY_Style");<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; // Set the Table Style<br/>&nbsp;&nbsp;&nbsp; AcDbDictionary *pDict = NULL;<br/>&nbsp;&nbsp;&nbsp; AcDbObjectId idTblStyle;<br/>&nbsp;&nbsp;&nbsp; acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getTableStyleDictionary(pDict,AcDb::kForWrite);<br/>&nbsp;&nbsp;&nbsp; es = pDict-&gt;getAt(pTblStyle,idTblStyle);<br/>&nbsp;&nbsp;&nbsp; pDict-&gt;close();<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;<br/>&nbsp;if(Acad::eOk == es)&nbsp;pTbl-&gt;setTableStyle(idTblStyle);<br/>&nbsp;&nbsp;&nbsp; setTableColAndRows(pTbl, 5, 5);</p><p>&nbsp;&nbsp;&nbsp; pTbl-&gt;setTextString(3,3,L"my love");</p><p>&nbsp;&nbsp;&nbsp; pTbl-&gt;generateLayout(); // Very very important, else expect crashes later on</p><p>&nbsp;&nbsp;if(NULL == pTbl) <br/>&nbsp;{<br/>&nbsp;&nbsp;acutPrintf(ACRX_T("\nSelected entity was not a table!"));<br/>&nbsp;&nbsp;return;<br/>&nbsp;}</p><p>&nbsp;// Get an Excel file<br/>&nbsp;//<br/>&nbsp;struct resbuf *result; <br/>&nbsp;int rc; </p><p>&nbsp;if ( (result = acutNewRb(RTSTR)) == NULL)<br/>&nbsp;{<br/>&nbsp;&nbsp;pTbl-&gt;close();<br/>&nbsp;&nbsp;acutPrintf(ACRX_T("\nUnable to allocate buffer!")); <br/>&nbsp;&nbsp;return;<br/>&nbsp;}</p><p>&nbsp;result-&gt;resval.rstring=NULL; </p><p>&nbsp;rc = acedGetFileD(&nbsp;ACRX_T("Excel File"),&nbsp;// Title<br/>&nbsp;&nbsp;ACRX_T("c:\\"),&nbsp;&nbsp;// Default pathname&nbsp; <br/>&nbsp;&nbsp;ACRX_T("xls"),&nbsp;&nbsp;&nbsp;// Default extension<br/>&nbsp;&nbsp;16,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Control flags<br/>&nbsp;&nbsp;result);&nbsp;&nbsp;&nbsp;&nbsp;// The path selected by the user.<br/>&nbsp;if (rc != RTNORM) <br/>&nbsp;{<br/>&nbsp;&nbsp;pTbl-&gt;close();<br/>&nbsp;&nbsp;acutPrintf(ACRX_T("\nError in selecting an EXCEL file!")); <br/>&nbsp;&nbsp;return;<br/>&nbsp;}</p><p>&nbsp;// Retrieve the file name from the ResBuf.<br/>&nbsp;ACHAR fileName;<br/>&nbsp;_tcscpy(fileName, result-&gt;resval.rstring);<br/>&nbsp;rc = acutRelRb(result);</p><p>&nbsp;static ACHAR sMyDataLink = ACRX_T("TLLink");<br/>&nbsp;// Get the Data Link Manager.<br/>&nbsp;AcDbDataLinkManager* pDlMan = acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getDataLinkManager();<br/>&nbsp;assert(pDlMan);</p><p>&nbsp;AcDbObjectId idDL;<br/>&nbsp;AcDbDataLink *pDL = NULL;&nbsp;<br/>&nbsp;// Check if a Data Link with the name already exists. If so, remove it.<br/>&nbsp;if( pDlMan-&gt;getDataLink(sMyDataLink, pDL, AcDb::kForRead) == Acad::eOk &amp;&amp; pDL)<br/>&nbsp;{<br/>&nbsp;&nbsp;pDL-&gt;close();<br/>&nbsp;&nbsp;es = pDlMan-&gt;removeDataLink(sMyDataLink, idDL);<br/>&nbsp;&nbsp;if( es != Acad::eOk )<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;pTbl-&gt;close();<br/>&nbsp;&nbsp;&nbsp;acutPrintf(ACRX_T("\nError in removing the Data Link!"));<br/>&nbsp;&nbsp;&nbsp;return;<br/>&nbsp;&nbsp;}<br/>&nbsp;}<br/>&nbsp;</p><p>&nbsp;// Create a Data Link with the name.<br/>&nbsp;es = pDlMan-&gt;createDataLink(ACRX_T("AcExcel"), sMyDataLink, ACRX_T("This is a test for Excel type data link."), fileName, idDL);<br/>&nbsp;if( es != Acad::eOk )<br/>&nbsp;{<br/>&nbsp;&nbsp;pTbl-&gt;close();<br/>&nbsp;&nbsp;acutPrintf(ACRX_T("\nError in creating Data Link!\nPlease check if there is a sheet named 'Sheet1' in the XLS file."));<br/>&nbsp;&nbsp;return;<br/>&nbsp;}</p><p>&nbsp;// Open the Data Link.<br/>&nbsp;es = acdbOpenObject&lt;AcDbDataLink&gt;(pDL, idDL, AcDb::kForWrite);<br/>&nbsp;if ( es != Acad::eOk || !pDL )<br/>&nbsp;{<br/>&nbsp;&nbsp;pTbl-&gt;close();<br/>&nbsp;&nbsp;acutPrintf(ACRX_T("\nError in opening the Data Link object!")); <br/>&nbsp;&nbsp;return;<br/>&nbsp;}</p><p>&nbsp;//&nbsp; Set options of the Data Link<br/>&nbsp;es = pDL-&gt;setOption(AcDb::kDataLinkOptionPersistCache);<br/>&nbsp;es = pDL-&gt;setUpdateOption(pDL-&gt;updateOption() | AcDb::kUpdateOptionAllowSourceUpdate);</p><p>&nbsp;// Close the Data Link.<br/>&nbsp;pDL-&gt;close();</p><p>&nbsp;// Set data link to the table object at cell(2,2).<br/>&nbsp;es = pTbl-&gt;setDataLink(0,0, idDL, true);<br/>&nbsp;if( es != Acad::eOk )<br/>&nbsp;{<br/>&nbsp;&nbsp;pTbl-&gt;close();<br/>&nbsp;&nbsp;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/>&nbsp;&nbsp;return;<br/>&nbsp;}<br/>&nbsp;pTbl-&gt;setPosition(AcGePoint3d(0, 0, 0));<br/>&nbsp;// Don't forget to close the table object.<br/>&nbsp;&nbsp;&nbsp; pTbl-&gt;close();<br/>}</p>

netthree 发表于 2008-3-6 22:07:00

忘记了一条语句

<p>不好意思,原因找到了,&nbsp; 在pTbl-&gt;close();语句前面加上addEntToDwg(acdbHostApplicationServices()-&gt;workingDatabase(),pTbl);</p><p>加上后一切就OK了.</p>
页: [1]
查看完整版本: 请教:为什么新建的表格(table)没有在图上显示出来