zidane_mt 发表于 2008-7-7 09:06:00

[求助]获得CAD当前活动图形的基本信息的大体思路?

本帖最后由 作者 于 2008-7-7 9:08:04 编辑 <br /><br /> <p>如题。新手求助。。</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 我的问题是假如我在CAD中画了一条线,那么我如何通过ARX程序获得</p><p>它的图层,线性,颜色,线宽等基本信息呢?即如何从当前的块表记录获得</p><p>相关对象的ObjectID呢?</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 再扩展一下,假如是读取一个块对象的信息的话,如果用Iterator来实现的话,那么</p><p>相关对象的类型判断如何解决呢?</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 只求一个思路(如解决办法,相关函数,变量等),谢谢!&nbsp;&nbsp;&nbsp; :-)</p>

zhang007 发表于 2008-7-9 09:32:00

<p>首先是你想怎样使用这条线的信息,如果仅仅是想显示出来,就看看这个</p><p>ObjectARX 2004\samples\entity\MultilineTooltipSamp\MultilineTooltipSamp.vcproj</p><p>代码贴上来,让你看的眼花:</p><p>CSampleIPM::CSampleIPM(const bool storeInDocVars, AcApDocument* pDoc)<br/>{<br/>&nbsp;if (storeInDocVars) {</p><p>&nbsp;&nbsp;assert(gDocVars.docData(pDoc).m_pIPM == NULL);</p><p>&nbsp;&nbsp;m_pDoc = pDoc;<br/>&nbsp;&nbsp;m_pDoc-&gt;inputPointManager()-&gt;addPointMonitor(this);<br/>&nbsp;&nbsp;gDocVars.docData().m_pIPM = this;</p><p>&nbsp;} else<br/>&nbsp;&nbsp;m_pDoc = NULL;<br/>}</p><p>CSampleIPM::~CSampleIPM()<br/>{<br/>&nbsp;if (m_pDoc)<br/>&nbsp;&nbsp;if (gDocVars.docData(m_pDoc).m_pIPM) {<br/>&nbsp;&nbsp;&nbsp;m_pDoc-&gt;inputPointManager()-&gt;removePointMonitor(this);<br/>&nbsp;&nbsp;&nbsp;gDocVars.docData(m_pDoc).m_pIPM = NULL;<br/>&nbsp;&nbsp;}<br/>}</p><p>bool<br/>CSampleIPM::excludeFromOsnapCalculation(const AcArray&lt;AcDbObjectId&gt;&amp; nestedEntity,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int gsSelectionMark)<br/>{<br/>&nbsp; return false;<br/>}<br/>//<br/>// This is where we take advantage of quite a bit of information<br/>// provide by this big function to display multiline tooltip<br/>// (new feature in Acad 2002) under the cursor aperture.<br/>//<br/>// It gets even more interesting when you mix it with OSNAP info.<br/>//<br/>// Have fun!<br/>//<br/>Acad::ErrorStatus <br/>CSampleIPM::monitorInputPoint(<br/>&nbsp; bool&amp; bAppendToTooltipStr,<br/>&nbsp;&nbsp;&nbsp;&nbsp; char*&amp; pAdditionalTooltipString,<br/>&nbsp;&nbsp;&nbsp;&nbsp; AcGiViewportDraw* pDrawContext,<br/>&nbsp;&nbsp;&nbsp;&nbsp; AcApDocument* pDocument,<br/>&nbsp;&nbsp;&nbsp;&nbsp; bool pointComputed,<br/>&nbsp;&nbsp;&nbsp;&nbsp; int history,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcGePoint3d&amp; lastPoint,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcGePoint3d&amp; rawPoint,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcGePoint3d&amp; grippedPoint,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcGePoint3d&amp; cartesianSnappedPoint,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcGePoint3d&amp; osnappedPoint,<br/>&nbsp;&nbsp;&nbsp;&nbsp; AcDb::OsnapMask osnapMask,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcArray&lt;AcDbCustomOsnapMode*&gt;&amp; customOsnapModes,<br/>&nbsp;&nbsp;&nbsp;&nbsp; AcDb::OsnapMask osnapOverrides,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcArray&lt;AcDbCustomOsnapMode*&gt;&amp; customOsnapOverrides,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcArray&lt;AcDbObjectId&gt;&amp; apertureEntities,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcArray&lt; AcDbObjectIdArray,<br/>&nbsp;&nbsp;&nbsp;&nbsp; AcArrayObjectCopyReallocator&lt; AcDbObjectIdArray &gt; &gt;&amp; nestedApertureEntities,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcArray&lt;int&gt;&amp; gsSelectionMark,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcArray&lt;AcDbObjectId&gt;&amp; keyPointEntities,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcArray&lt; AcDbObjectIdArray,<br/>&nbsp;&nbsp;&nbsp;&nbsp; AcArrayObjectCopyReallocator&lt; AcDbObjectIdArray &gt; &gt;&amp; nestedKeyPointEntities,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcArray&lt;int&gt;&amp; keyPointGsSelectionMark,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcArray&lt;AcGeCurve3d*&gt;&amp; alignmentPaths,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const AcGePoint3d&amp; computedPoint,<br/>&nbsp;&nbsp;&nbsp;&nbsp; const char* pTooltipString)<br/>{<br/>&nbsp;char mtooltipStr,<br/>&nbsp;&nbsp; tempStr;<br/>&nbsp;mtooltipStr = '\0';</p><p>&nbsp;Acad::ErrorStatus es;<br/>&nbsp;AcDbEntity* pEnt;<br/>&nbsp;AcDbObjectId highlightId = AcDbObjectId::kNull;</p><p>&nbsp;if (pointComputed)<br/>&nbsp;{<br/>&nbsp;&nbsp;//<br/>&nbsp;&nbsp;// Analyze the aperture entities.<br/>&nbsp;&nbsp;//<br/>&nbsp;&nbsp;if (apertureEntities.length() &gt; 0)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;if(strlen(mtooltipStr) &gt; 0)<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(mtooltipStr, "\nEntities under the cursor aperture:");<br/>&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(mtooltipStr, "Entities under the cursor aperture:");</p><p>&nbsp;&nbsp;&nbsp;for (int i = 0; i &lt; apertureEntities.length(); ++i)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (Acad::eOk != (es = acdbOpenAcDbEntity(pEnt, apertureEntities, AcDb::kForRead)))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(tempStr, "\n&nbsp; %s%s%d%s", pEnt-&gt;isA()-&gt;name(), " &lt;Object ID: ", pEnt-&gt;objectId(), "&gt;");<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(mtooltipStr, tempStr);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pEnt-&gt;close();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Analyze the nested aperture entities.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AcDbObjectIdArray nestedIds = nestedApertureEntities;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int length = nestedIds.length();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (length &gt; 1)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// There is a nested entitiy: get it.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AcDbEntity* pEnt2;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Acad::eOk == (es = acdbOpenAcDbEntity(pEnt2, nestedIds, AcDb::kForRead))) {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(tempStr, "\n&nbsp; nested: %s", pEnt2-&gt;isA()-&gt;name());<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(mtooltipStr, tempStr);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pEnt2-&gt;close();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;highlightId = apertureEntities;<br/>&nbsp;&nbsp;}</p><p>&nbsp;&nbsp;//<br/>&nbsp;&nbsp;// Analyze OSNAP.<br/>&nbsp;&nbsp;//</p><p>&nbsp;&nbsp;if (history &amp;&amp; Acad::eOsnapped)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;char osnapInfo;<br/>&nbsp;&nbsp;&nbsp;osnapInfo = '\0';</p><p>&nbsp;&nbsp;&nbsp;switch (osnapMask)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskEnd:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; end");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskMid:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; mid");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskCen:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; center");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskNode:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; node");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskQuad:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; quadrant");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskInt:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; intersection");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskIns:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; insert");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskPerp:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; perpendicular");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskTan:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; tangent");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskNear:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; near");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskQuick:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; quick");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskApint:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; apint");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskImmediate:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; immediate");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;</p><p>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskAllowTan:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; allowTan");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskDisablePerp:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; DisablePerp");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskRelCartesian:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; RelCartesian");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;case AcDb::kOsMaskRelPolar:<br/>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(osnapInfo, "\nOsnap:\n&nbsp; RelPolar");<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;if (strlen(osnapInfo))<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;if (keyPointEntities.length())<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(osnapInfo, "\nKey entities:");<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i=0; i&lt;keyPointEntities.length(); ++i)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (Acad::eOk != (es = acdbOpenAcDbEntity(pEnt, keyPointEntities, AcDb::kForRead)))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(tempStr, "\n&nbsp;&nbsp;&nbsp; %s", pEnt-&gt;isA()-&gt;name());<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(osnapInfo, tempStr);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;strcat(mtooltipStr, osnapInfo);<br/>&nbsp;&nbsp;}<br/>&nbsp;}</p><p>&nbsp;//<br/>&nbsp;// Do highlighting, only the top level entity is highlighted.<br/>&nbsp;//<br/>&nbsp;static AcDbObjectId oldHighlightId = AcDbObjectId::kNull;<br/>&nbsp;if(highlightId != oldHighlightId)<br/>&nbsp;{<br/>&nbsp;&nbsp;if (AcDbObjectId::kNull != oldHighlightId)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;es = acdbOpenAcDbEntity(pEnt, oldHighlightId, AcDb::kForRead);<br/>&nbsp;&nbsp;&nbsp;if (es == Acad::eOk)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;es = pEnt-&gt;unhighlight();<br/>&nbsp;&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<br/>&nbsp;&nbsp;&nbsp;&nbsp;oldHighlightId = AcDbObjectId::kNull;<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;es = acdbOpenAcDbEntity(pEnt, highlightId, AcDb::kForRead);<br/>&nbsp;&nbsp;if (es == Acad::eOk)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;es = pEnt-&gt;highlight();<br/>&nbsp;&nbsp;&nbsp;pEnt-&gt;close();<br/>&nbsp;&nbsp;&nbsp;oldHighlightId = highlightId;<br/>&nbsp;&nbsp;}<br/>&nbsp;}</p><p>&nbsp;// Turn on additional tooltip.<br/>&nbsp;bAppendToTooltipStr = true;<br/>&nbsp;pAdditionalTooltipString = mtooltipStr;<br/>&nbsp;return Acad::eOk;<br/>}</p><p>void MTooltipOn()<br/>{<br/>&nbsp; if (!gDocVars.docData().m_pIPM)<br/>&nbsp;&nbsp;&nbsp; new CSampleIPM;<br/>}</p><p>void MTooltipOff()<br/>{<br/>&nbsp; if (gDocVars.docData().m_pIPM)<br/>&nbsp;&nbsp;&nbsp; delete gDocVars.docData().m_pIPM;<br/>}</p><p>// Init this application. Register your<br/>// commands, reactors...<br/>void InitApplication()<br/>{<br/>&nbsp;acedRegCmds-&gt;addCommand("ASDK", "MTOOPTIPON", "MTON", ACRX_CMD_MODAL, MTooltipOn);<br/>&nbsp;acedRegCmds-&gt;addCommand("ASDK", "MTOOPTIPOFF", "MTOFF", ACRX_CMD_MODAL, MTooltipOff);</p><p>&nbsp;acutPrintf("\nCommands are: MTOOPTIPON (MTON) and MTOOPTIPOFF (MTOFF).");<br/>&nbsp;MTooltipOn();<br/>&nbsp;acutPrintf("\nSample multiline tooltip is on.");<br/>}</p>

liub1979 发表于 2009-5-24 12:42:00

<p>该程序不是很稳定</p><p>如果用鼠标在窗口中快速移动</p><p>经常会莫名奇妙自动退出!</p><p>而且没有任何提示!</p>
页: [1]
查看完整版本: [求助]获得CAD当前活动图形的基本信息的大体思路?