[求助]获得CAD当前活动图形的基本信息的大体思路?
本帖最后由 作者 于 2008-7-7 9:08:04 编辑 <br /><br /> <p>如题。新手求助。。</p><p> 我的问题是假如我在CAD中画了一条线,那么我如何通过ARX程序获得</p><p>它的图层,线性,颜色,线宽等基本信息呢?即如何从当前的块表记录获得</p><p>相关对象的ObjectID呢?</p><p> 再扩展一下,假如是读取一个块对象的信息的话,如果用Iterator来实现的话,那么</p><p>相关对象的类型判断如何解决呢?</p><p> 只求一个思路(如解决办法,相关函数,变量等),谢谢! :-)</p> <p>首先是你想怎样使用这条线的信息,如果仅仅是想显示出来,就看看这个</p><p>ObjectARX 2004\samples\entity\MultilineTooltipSamp\MultilineTooltipSamp.vcproj</p><p>代码贴上来,让你看的眼花:</p><p>CSampleIPM::CSampleIPM(const bool storeInDocVars, AcApDocument* pDoc)<br/>{<br/> if (storeInDocVars) {</p><p> assert(gDocVars.docData(pDoc).m_pIPM == NULL);</p><p> m_pDoc = pDoc;<br/> m_pDoc->inputPointManager()->addPointMonitor(this);<br/> gDocVars.docData().m_pIPM = this;</p><p> } else<br/> m_pDoc = NULL;<br/>}</p><p>CSampleIPM::~CSampleIPM()<br/>{<br/> if (m_pDoc)<br/> if (gDocVars.docData(m_pDoc).m_pIPM) {<br/> m_pDoc->inputPointManager()->removePointMonitor(this);<br/> gDocVars.docData(m_pDoc).m_pIPM = NULL;<br/> }<br/>}</p><p>bool<br/>CSampleIPM::excludeFromOsnapCalculation(const AcArray<AcDbObjectId>& nestedEntity,<br/> int gsSelectionMark)<br/>{<br/> 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/> bool& bAppendToTooltipStr,<br/> char*& pAdditionalTooltipString,<br/> AcGiViewportDraw* pDrawContext,<br/> AcApDocument* pDocument,<br/> bool pointComputed,<br/> int history,<br/> const AcGePoint3d& lastPoint,<br/> const AcGePoint3d& rawPoint,<br/> const AcGePoint3d& grippedPoint,<br/> const AcGePoint3d& cartesianSnappedPoint,<br/> const AcGePoint3d& osnappedPoint,<br/> AcDb::OsnapMask osnapMask,<br/> const AcArray<AcDbCustomOsnapMode*>& customOsnapModes,<br/> AcDb::OsnapMask osnapOverrides,<br/> const AcArray<AcDbCustomOsnapMode*>& customOsnapOverrides,<br/> const AcArray<AcDbObjectId>& apertureEntities,<br/> const AcArray< AcDbObjectIdArray,<br/> AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedApertureEntities,<br/> const AcArray<int>& gsSelectionMark,<br/> const AcArray<AcDbObjectId>& keyPointEntities,<br/> const AcArray< AcDbObjectIdArray,<br/> AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedKeyPointEntities,<br/> const AcArray<int>& keyPointGsSelectionMark,<br/> const AcArray<AcGeCurve3d*>& alignmentPaths,<br/> const AcGePoint3d& computedPoint,<br/> const char* pTooltipString)<br/>{<br/> char mtooltipStr,<br/> tempStr;<br/> mtooltipStr = '\0';</p><p> Acad::ErrorStatus es;<br/> AcDbEntity* pEnt;<br/> AcDbObjectId highlightId = AcDbObjectId::kNull;</p><p> if (pointComputed)<br/> {<br/> //<br/> // Analyze the aperture entities.<br/> //<br/> if (apertureEntities.length() > 0)<br/> {<br/> if(strlen(mtooltipStr) > 0)<br/> strcpy(mtooltipStr, "\nEntities under the cursor aperture:");<br/> else<br/> strcpy(mtooltipStr, "Entities under the cursor aperture:");</p><p> for (int i = 0; i < apertureEntities.length(); ++i)<br/> {<br/> if (Acad::eOk != (es = acdbOpenAcDbEntity(pEnt, apertureEntities, AcDb::kForRead)))<br/> continue;</p><p> sprintf(tempStr, "\n %s%s%d%s", pEnt->isA()->name(), " <Object ID: ", pEnt->objectId(), ">");<br/> strcat(mtooltipStr, tempStr);<br/> pEnt->close();</p><p> // Analyze the nested aperture entities.<br/> AcDbObjectIdArray nestedIds = nestedApertureEntities;<br/> int length = nestedIds.length();<br/> if (length > 1)<br/> {<br/> // There is a nested entitiy: get it.<br/> AcDbEntity* pEnt2;<br/> if (Acad::eOk == (es = acdbOpenAcDbEntity(pEnt2, nestedIds, AcDb::kForRead))) {<br/> sprintf(tempStr, "\n nested: %s", pEnt2->isA()->name());<br/> strcat(mtooltipStr, tempStr);<br/> pEnt2->close();<br/> }<br/> }<br/> }<br/> highlightId = apertureEntities;<br/> }</p><p> //<br/> // Analyze OSNAP.<br/> //</p><p> if (history && Acad::eOsnapped)<br/> {<br/> char osnapInfo;<br/> osnapInfo = '\0';</p><p> switch (osnapMask)<br/> {<br/> case AcDb::kOsMaskEnd:<br/> strcpy(osnapInfo, "\nOsnap:\n end");<br/> break;<br/> case AcDb::kOsMaskMid:<br/> strcpy(osnapInfo, "\nOsnap:\n mid");<br/> break;<br/> case AcDb::kOsMaskCen:<br/> strcpy(osnapInfo, "\nOsnap:\n center");<br/> break;<br/> case AcDb::kOsMaskNode:<br/> strcpy(osnapInfo, "\nOsnap:\n node");<br/> break;<br/> case AcDb::kOsMaskQuad:<br/> strcpy(osnapInfo, "\nOsnap:\n quadrant");<br/> break;<br/> case AcDb::kOsMaskInt:<br/> strcpy(osnapInfo, "\nOsnap:\n intersection");<br/> break;<br/> case AcDb::kOsMaskIns:<br/> strcpy(osnapInfo, "\nOsnap:\n insert");<br/> break;<br/> case AcDb::kOsMaskPerp:<br/> strcpy(osnapInfo, "\nOsnap:\n perpendicular");<br/> break;<br/> case AcDb::kOsMaskTan:<br/> strcpy(osnapInfo, "\nOsnap:\n tangent");<br/> break;<br/> case AcDb::kOsMaskNear:<br/> strcpy(osnapInfo, "\nOsnap:\n near");<br/> break;<br/> case AcDb::kOsMaskQuick:<br/> strcpy(osnapInfo, "\nOsnap:\n quick");<br/> break;<br/> case AcDb::kOsMaskApint:<br/> strcpy(osnapInfo, "\nOsnap:\n apint");<br/> break;<br/> case AcDb::kOsMaskImmediate:<br/> strcpy(osnapInfo, "\nOsnap:\n immediate");<br/> break;</p><p> case AcDb::kOsMaskAllowTan:<br/> strcpy(osnapInfo, "\nOsnap:\n allowTan");<br/> break;<br/> case AcDb::kOsMaskDisablePerp:<br/> strcpy(osnapInfo, "\nOsnap:\n DisablePerp");<br/> break;<br/> case AcDb::kOsMaskRelCartesian:<br/> strcpy(osnapInfo, "\nOsnap:\n RelCartesian");<br/> break;<br/> case AcDb::kOsMaskRelPolar:<br/> strcpy(osnapInfo, "\nOsnap:\n RelPolar");<br/> break;<br/> }<br/> if (strlen(osnapInfo))<br/> {<br/> if (keyPointEntities.length())<br/> {<br/> strcat(osnapInfo, "\nKey entities:");<br/> for (int i=0; i<keyPointEntities.length(); ++i)<br/> {<br/> if (Acad::eOk != (es = acdbOpenAcDbEntity(pEnt, keyPointEntities, AcDb::kForRead)))<br/> continue;</p><p> sprintf(tempStr, "\n %s", pEnt->isA()->name());<br/> strcat(osnapInfo, tempStr);<br/> pEnt->close();<br/> }<br/> }<br/> }<br/> strcat(mtooltipStr, osnapInfo);<br/> }<br/> }</p><p> //<br/> // Do highlighting, only the top level entity is highlighted.<br/> //<br/> static AcDbObjectId oldHighlightId = AcDbObjectId::kNull;<br/> if(highlightId != oldHighlightId)<br/> {<br/> if (AcDbObjectId::kNull != oldHighlightId)<br/> {<br/> es = acdbOpenAcDbEntity(pEnt, oldHighlightId, AcDb::kForRead);<br/> if (es == Acad::eOk)<br/> {<br/> es = pEnt->unhighlight();<br/> pEnt->close();<br/> oldHighlightId = AcDbObjectId::kNull;<br/> }<br/> }<br/> es = acdbOpenAcDbEntity(pEnt, highlightId, AcDb::kForRead);<br/> if (es == Acad::eOk)<br/> {<br/> es = pEnt->highlight();<br/> pEnt->close();<br/> oldHighlightId = highlightId;<br/> }<br/> }</p><p> // Turn on additional tooltip.<br/> bAppendToTooltipStr = true;<br/> pAdditionalTooltipString = mtooltipStr;<br/> return Acad::eOk;<br/>}</p><p>void MTooltipOn()<br/>{<br/> if (!gDocVars.docData().m_pIPM)<br/> new CSampleIPM;<br/>}</p><p>void MTooltipOff()<br/>{<br/> if (gDocVars.docData().m_pIPM)<br/> delete gDocVars.docData().m_pIPM;<br/>}</p><p>// Init this application. Register your<br/>// commands, reactors...<br/>void InitApplication()<br/>{<br/> acedRegCmds->addCommand("ASDK", "MTOOPTIPON", "MTON", ACRX_CMD_MODAL, MTooltipOn);<br/> acedRegCmds->addCommand("ASDK", "MTOOPTIPOFF", "MTOFF", ACRX_CMD_MODAL, MTooltipOff);</p><p> acutPrintf("\nCommands are: MTOOPTIPON (MTON) and MTOOPTIPOFF (MTOFF).");<br/> MTooltipOn();<br/> acutPrintf("\nSample multiline tooltip is on.");<br/>}</p> <p>该程序不是很稳定</p><p>如果用鼠标在窗口中快速移动</p><p>经常会莫名奇妙自动退出!</p><p>而且没有任何提示!</p>
页:
[1]