金砖四国的爆炸装置。
此例程尝试分解块并将属性转换为 Text。我附上了编译好的DRX模块,命令名称是burst
class CommandBlockEx : public OdStaticRxObject
{
public:
const OdString localName() const { return globalName(); }
const OdString groupName() const { returnOdString(_T("DRXGLOBAL")); }
const OdString globalName() const { return OdString(_T("burst")); }
void execute(OdEdCommandContext* pCmdCtx)
{
ASSERT(pCmdCtx != NULL);
if(pCmdCtx == NULL)
return;
OdDbCommandContextPtr pDbCmdCtx(pCmdCtx);
OdDbUserIOPtr pDbIO = pDbCmdCtx->dbUserIO();
OdDbDatabasePtr pDb = pDbCmdCtx->database();
if(pDb.isNull())
return;
OdRxObjectPtrArray entsToAdd;
OdString message = DD_T("\nSelect Blocks to Explode: ");
OdDbSelectionSetPtr pSelectionSet = pDbIO->select(message);
OdDbObjectIdArray ids = pSelectionSet->objectIdArray();
pDbIO->putString(DD_T("\nFiltering non Block Entities: "));
ProgressMeter meter(ids.length());
meter.start();
for(unsigned int i = 0 ; i isKindOf(OdDbBlockReference::desc()))
continue;
OdDbBlockReferencePtr pBlockReference = objectPtr;
if(pBlockReference.isNull())
continue;
OdDbObjectIteratorPtr pAttributeIterator =
pBlockReference->attributeIterator();
for (pAttributeIterator->start();
!pAttributeIterator->done();
pAttributeIterator->step())
{
OdDbAttributePtr pAttribute =
pAttributeIterator->objectId().openObject(OdDb::kForRead);
OdDbTextPtr pText = OdDbText::createObject();
pText->setTextString(pAttribute->textString());
pText->setColor(pAttribute->color());
pText->setHeight(pAttribute->height());
pText->setPosition(pAttribute->position());
pText->setRotation(pAttribute->rotation());
pText->setTextStyle(pAttribute->textStyle());
pText->setVerticalMode(pAttribute->verticalMode());
entsToAdd.push_back((OdRxObjectPtr)pText);
}
pBlockReference->explode(entsToAdd);
pBlockReference->upgradeOpen();
pBlockReference->erase();
OdDbBlockTableRecordPtr pBtr =
pBlockReference->ownerId().openObject(OdDb::kForWrite);
if(pBtr.isNull())
continue;
for(unsigned int j = 0 ; j isKindOf(OdDbAttributeDefinition::desc()))
pBtr->appendOdDbEntity(ePtr);
}
}
meter.stop();
pDbIO->putString(DD_T("\n "));
}
};
**** Hidden Message *****
你好Daniel,
作为DRX的200%新手,我正在阅读上面的函数,有些东西吸引了我的注意力,为什么所有的铸件?
这里:
OdDbTextPtr pText=OdDbText::createObject(); // 这样开始
然后:
entsToAdd.push_back((OdRxObjectPtr)pText);//保存在这样的向量中
和:
OdDbEntityPtr ePtr=(OdDbEntityPtr)entsToAdd;//然后它是这样使用的
只是好奇,它可能是DRX需要的东西,不知道......(是的,我没有阅读您附加的zip文件中的内容)
谢谢! 我不知道,编译器抱怨说它需要一个造型。
我可能应该编造一个OdDbObjectPtrArray,而不是使用OdRxObjectPtrArray
不,虽然explode不需要ODRxObjectPtraray,但这些智能指针确实有一个cast方法,我应该研究一下
Daniel,
所以智能指针是那些以Ptr结尾的指针,我看到,与我在ObjectARX中使用的指针不同。
谢谢!
Daniel,
所以智能指针是那些以Ptr结尾的指针,我看到,与我在ObjectARX中使用的指针不同。
谢谢!
DRX非常光滑,几乎所有东西都C++类(RAII),甚至 ODA 版本的 resbuf 也是一个类。几乎每个类都有一个 create 方法,该方法返回指向对象新实例的智能指针。DRX 为您管理堆内存和 DbObjects 的状态。它的设计非常好,编码真的很愉快。
那听起来很不错....我有一个朋友,他正在将一个非常庞大的应用程序(ARX)移植到DRX....我需要拜访他,看看代码....
糟糕的是,我仍然坚持只使用autocad... 好吧,你可能想习惯智能指针,欧特克现在也在使用它们
哇,太简单了......我不想那样......
但是,它似乎在a2009上可用-我还在a2007
但是很高兴知道!!!
谢谢。
我在所有编码中使用智能指针,但这些对我来说看起来很新......没有调用
if(ent.openStatus () == Acad::eOk)
{
}
在做ARX工作时,我一直在使用它们...漂亮的小特色。
页:
[1]