明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3390|回复: 2

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

[复制链接]
发表于 2008-7-7 09:06:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2008-7-7 9:08:04 编辑

如题。新手求助。。

       我的问题是假如我在CAD中画了一条线,那么我如何通过ARX程序获得

它的图层,线性,颜色,线宽等基本信息呢?即如何从当前的块表记录获得

相关对象的ObjectID呢?

        再扩展一下,假如是读取一个块对象的信息的话,如果用Iterator来实现的话,那么

相关对象的类型判断如何解决呢?

       只求一个思路(如解决办法,相关函数,变量等),谢谢!    :-)

发表于 2008-7-9 09:32:00 | 显示全部楼层

首先是你想怎样使用这条线的信息,如果仅仅是想显示出来,就看看这个

ObjectARX 2004\samples\entity\MultilineTooltipSamp\MultilineTooltipSamp.vcproj

代码贴上来,让你看的眼花:

CSampleIPM::CSampleIPM(const bool storeInDocVars, AcApDocument* pDoc)
{
 if (storeInDocVars) {

  assert(gDocVars.docData(pDoc).m_pIPM == NULL);

  m_pDoc = pDoc;
  m_pDoc->inputPointManager()->addPointMonitor(this);
  gDocVars.docData().m_pIPM = this;

 } else
  m_pDoc = NULL;
}

CSampleIPM::~CSampleIPM()
{
 if (m_pDoc)
  if (gDocVars.docData(m_pDoc).m_pIPM) {
   m_pDoc->inputPointManager()->removePointMonitor(this);
   gDocVars.docData(m_pDoc).m_pIPM = NULL;
  }
}

bool
CSampleIPM::excludeFromOsnapCalculation(const AcArray<AcDbObjectId>& nestedEntity,
                                    int gsSelectionMark)
{
  return false;
}
//
// This is where we take advantage of quite a bit of information
// provide by this big function to display multiline tooltip
// (new feature in Acad 2002) under the cursor aperture.
//
// It gets even more interesting when you mix it with OSNAP info.
//
// Have fun!
//
Acad::ErrorStatus
CSampleIPM::monitorInputPoint(
  bool& bAppendToTooltipStr,
     char*& pAdditionalTooltipString,
     AcGiViewportDraw* pDrawContext,
     AcApDocument* pDocument,
     bool pointComputed,
     int history,
     const AcGePoint3d& lastPoint,
     const AcGePoint3d& rawPoint,
     const AcGePoint3d& grippedPoint,
     const AcGePoint3d& cartesianSnappedPoint,
     const AcGePoint3d& osnappedPoint,
     AcDb::OsnapMask osnapMask,
     const AcArray<AcDbCustomOsnapMode*>& customOsnapModes,
     AcDb::OsnapMask osnapOverrides,
     const AcArray<AcDbCustomOsnapMode*>& customOsnapOverrides,
     const AcArray<AcDbObjectId>& apertureEntities,
     const AcArray< AcDbObjectIdArray,
     AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedApertureEntities,
     const AcArray<int>& gsSelectionMark,
     const AcArray<AcDbObjectId>& keyPointEntities,
     const AcArray< AcDbObjectIdArray,
     AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedKeyPointEntities,
     const AcArray<int>& keyPointGsSelectionMark,
     const AcArray<AcGeCurve3d*>& alignmentPaths,
     const AcGePoint3d& computedPoint,
     const char* pTooltipString)
{
 char mtooltipStr[1024],
   tempStr[100];
 mtooltipStr[0] = '\0';

 Acad::ErrorStatus es;
 AcDbEntity* pEnt;
 AcDbObjectId highlightId = AcDbObjectId::kNull;

 if (pointComputed)
 {
  //
  // Analyze the aperture entities.
  //
  if (apertureEntities.length() > 0)
  {
   if(strlen(mtooltipStr) > 0)
    strcpy(mtooltipStr, "\nEntities under the cursor aperture:");
   else
    strcpy(mtooltipStr, "Entities under the cursor aperture:");

   for (int i = 0; i < apertureEntities.length(); ++i)
   {
    if (Acad::eOk != (es = acdbOpenAcDbEntity(pEnt, apertureEntities, AcDb::kForRead)))
     continue;

     sprintf(tempStr, "\n  %s%s%d%s", pEnt->isA()->name(), " <Object ID: ", pEnt->objectId(), ">");
     strcat(mtooltipStr, tempStr);
     pEnt->close();

     // Analyze the nested aperture entities.
     AcDbObjectIdArray nestedIds = nestedApertureEntities;
     int length = nestedIds.length();
     if (length > 1)
     {
      // There is a nested entitiy: get it.
      AcDbEntity* pEnt2;
      if (Acad::eOk == (es = acdbOpenAcDbEntity(pEnt2, nestedIds[length - 1], AcDb::kForRead))) {
       sprintf(tempStr, "\n  nested: %s", pEnt2->isA()->name());
       strcat(mtooltipStr, tempStr);
       pEnt2->close();
      }
     }
   }
   highlightId = apertureEntities[0];
  }

  //
  // Analyze OSNAP.
  //

  if (history && Acad::eOsnapped)
  {
   char osnapInfo[500];
   osnapInfo[0] = '\0';

   switch (osnapMask)
   {
   case AcDb::kOsMaskEnd:
    strcpy(osnapInfo, "\nOsnap:\n  end");
    break;
   case AcDb::kOsMaskMid:
    strcpy(osnapInfo, "\nOsnap:\n  mid");
    break;
   case AcDb::kOsMaskCen:
    strcpy(osnapInfo, "\nOsnap:\n  center");
    break;
   case AcDb::kOsMaskNode:
    strcpy(osnapInfo, "\nOsnap:\n  node");
    break;
   case AcDb::kOsMaskQuad:
    strcpy(osnapInfo, "\nOsnap:\n  quadrant");
    break;
   case AcDb::kOsMaskInt:
    strcpy(osnapInfo, "\nOsnap:\n  intersection");
    break;
   case AcDb::kOsMaskIns:
    strcpy(osnapInfo, "\nOsnap:\n  insert");
    break;
   case AcDb::kOsMaskPerp:
    strcpy(osnapInfo, "\nOsnap:\n  perpendicular");
    break;
   case AcDb::kOsMaskTan:
    strcpy(osnapInfo, "\nOsnap:\n  tangent");
    break;
   case AcDb::kOsMaskNear:
    strcpy(osnapInfo, "\nOsnap:\n  near");
    break;
   case AcDb::kOsMaskQuick:
    strcpy(osnapInfo, "\nOsnap:\n  quick");
    break;
   case AcDb::kOsMaskApint:
    strcpy(osnapInfo, "\nOsnap:\n  apint");
    break;
   case AcDb::kOsMaskImmediate:
    strcpy(osnapInfo, "\nOsnap:\n  immediate");
    break;

   case AcDb::kOsMaskAllowTan:
    strcpy(osnapInfo, "\nOsnap:\n  allowTan");
    break;
   case AcDb::kOsMaskDisablePerp:
    strcpy(osnapInfo, "\nOsnap:\n  DisablePerp");
    break;
   case AcDb::kOsMaskRelCartesian:
    strcpy(osnapInfo, "\nOsnap:\n  RelCartesian");
    break;
   case AcDb::kOsMaskRelPolar:
    strcpy(osnapInfo, "\nOsnap:\n  RelPolar");
    break;
   }
   if (strlen(osnapInfo))
   {
    if (keyPointEntities.length())
    {
     strcat(osnapInfo, "\nKey entities:");
     for (int i=0; i<keyPointEntities.length(); ++i)
     {
      if (Acad::eOk != (es = acdbOpenAcDbEntity(pEnt, keyPointEntities, AcDb::kForRead)))
       continue;

      sprintf(tempStr, "\n    %s", pEnt->isA()->name());
      strcat(osnapInfo, tempStr);
      pEnt->close();
     }
    }
   }
   strcat(mtooltipStr, osnapInfo);
  }
 }

 //
 // Do highlighting, only the top level entity is highlighted.
 //
 static AcDbObjectId oldHighlightId = AcDbObjectId::kNull;
 if(highlightId != oldHighlightId)
 {
  if (AcDbObjectId::kNull != oldHighlightId)
  {
   es = acdbOpenAcDbEntity(pEnt, oldHighlightId, AcDb::kForRead);
   if (es == Acad::eOk)
   {
    es = pEnt->unhighlight();
    pEnt->close();
    oldHighlightId = AcDbObjectId::kNull;
   }
  }
  es = acdbOpenAcDbEntity(pEnt, highlightId, AcDb::kForRead);
  if (es == Acad::eOk)
  {
   es = pEnt->highlight();
   pEnt->close();
   oldHighlightId = highlightId;
  }
 }

 // Turn on additional tooltip.
 bAppendToTooltipStr = true;
 pAdditionalTooltipString = mtooltipStr;
 return Acad::eOk;
}

void MTooltipOn()
{
  if (!gDocVars.docData().m_pIPM)
    new CSampleIPM;
}

void MTooltipOff()
{
  if (gDocVars.docData().m_pIPM)
    delete gDocVars.docData().m_pIPM;
}

// Init this application. Register your
// commands, reactors...
void InitApplication()
{
 acedRegCmds->addCommand("ASDK", "MTOOPTIPON", "MTON", ACRX_CMD_MODAL, MTooltipOn);
 acedRegCmds->addCommand("ASDK", "MTOOPTIPOFF", "MTOFF", ACRX_CMD_MODAL, MTooltipOff);

 acutPrintf("\nCommands are: MTOOPTIPON (MTON) and MTOOPTIPOFF (MTOFF).");
 MTooltipOn();
 acutPrintf("\nSample multiline tooltip is on.");
}

发表于 2009-5-24 12:42:00 | 显示全部楼层

该程序不是很稳定

如果用鼠标在窗口中快速移动

经常会莫名奇妙自动退出!

而且没有任何提示!

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 13:41 , Processed in 0.244601 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表