[求助]获得CAD当前活动图形的基本信息的大体思路?
如题。新手求助。。我的问题是假如我在CAD中画了一条线,那么我如何通过ARX程序获得
它的图层,线性,颜色,线宽等基本信息呢?即如何从当前的块表记录获得
相关对象的ObjectID呢?
再扩展一下,假如是读取一个块对象的信息的话,如果用Iterator来实现的话,那么
相关对象的类型判断如何解决呢?
只求一个思路(如解决办法,相关函数,变量等),谢谢! :-)
首先是你想怎样使用这条线的信息,如果仅仅是想显示出来,就看看这个
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& 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& customOsnapModes,
AcDb::OsnapMask osnapOverrides,
const AcArray& customOsnapOverrides,
const AcArray& apertureEntities,
const AcArray >& nestedApertureEntities,
const AcArray& gsSelectionMark,
const AcArray& keyPointEntities,
const AcArray >& nestedKeyPointEntities,
const AcArray& keyPointGsSelectionMark,
const AcArray& alignmentPaths,
const AcGePoint3d& computedPoint,
const char* pTooltipString)
{
char mtooltipStr,
tempStr;
mtooltipStr = '\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
sprintf(tempStr, "\n%s%s%d%s", pEnt->isA()->name(), " 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, AcDb::kForRead))) {
sprintf(tempStr, "\nnested: %s", pEnt2->isA()->name());
strcat(mtooltipStr, tempStr);
pEnt2->close();
}
}
}
highlightId = apertureEntities;
}
//
// Analyze OSNAP.
//
if (history && Acad::eOsnapped)
{
char osnapInfo;
osnapInfo = '\0';
switch (osnapMask)
{
case AcDb::kOsMaskEnd:
strcpy(osnapInfo, "\nOsnap:\nend");
break;
case AcDb::kOsMaskMid:
strcpy(osnapInfo, "\nOsnap:\nmid");
break;
case AcDb::kOsMaskCen:
strcpy(osnapInfo, "\nOsnap:\ncenter");
break;
case AcDb::kOsMaskNode:
strcpy(osnapInfo, "\nOsnap:\nnode");
break;
case AcDb::kOsMaskQuad:
strcpy(osnapInfo, "\nOsnap:\nquadrant");
break;
case AcDb::kOsMaskInt:
strcpy(osnapInfo, "\nOsnap:\nintersection");
break;
case AcDb::kOsMaskIns:
strcpy(osnapInfo, "\nOsnap:\ninsert");
break;
case AcDb::kOsMaskPerp:
strcpy(osnapInfo, "\nOsnap:\nperpendicular");
break;
case AcDb::kOsMaskTan:
strcpy(osnapInfo, "\nOsnap:\ntangent");
break;
case AcDb::kOsMaskNear:
strcpy(osnapInfo, "\nOsnap:\nnear");
break;
case AcDb::kOsMaskQuick:
strcpy(osnapInfo, "\nOsnap:\nquick");
break;
case AcDb::kOsMaskApint:
strcpy(osnapInfo, "\nOsnap:\napint");
break;
case AcDb::kOsMaskImmediate:
strcpy(osnapInfo, "\nOsnap:\nimmediate");
break;
case AcDb::kOsMaskAllowTan:
strcpy(osnapInfo, "\nOsnap:\nallowTan");
break;
case AcDb::kOsMaskDisablePerp:
strcpy(osnapInfo, "\nOsnap:\nDisablePerp");
break;
case AcDb::kOsMaskRelCartesian:
strcpy(osnapInfo, "\nOsnap:\nRelCartesian");
break;
case AcDb::kOsMaskRelPolar:
strcpy(osnapInfo, "\nOsnap:\nRelPolar");
break;
}
if (strlen(osnapInfo))
{
if (keyPointEntities.length())
{
strcat(osnapInfo, "\nKey entities:");
for (int i=0; i
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.");
}
该程序不是很稳定
如果用鼠标在窗口中快速移动
经常会莫名奇妙自动退出!
而且没有任何提示!
页:
[1]