- UID
- 107450
- 积分
- 153
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-2-29
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[php]
void insrtBlk(CString blk_name)
{
char blkName[50];
AcDbDatabase *pCurDb;
AcDbBlockTable *pBlkTable;
AcDbBlockTableRecord *pBlkTableRecord;
AcDbBlockTableRecord *pBlkDefRecord;
AcDbBlockReference *pInsrtObj;
AcDbEntity *pEnt;
AcDbBlockTableRecordIterator *pIterator;
AcDbAttributeDefinition *pAttDef;
AcDbAttribute *pAtt;
AcDbObjectId blkId;
AcDbObjectId insrtId;
AcGePoint3d insPt(0.0,0.0,0.0);
AcGePoint3d basePt;
strcpy(blkName,blk_name);
char *pTagPrompt;
strcpy(blkName,blk_name);
if(blkName[0] == '\0')
{
acutPrintf("\nInvalid block name.");
return;
}
pCurDb = acdbHostApplicationServices()->workingDatabase();
pCurDb->getBlockTable(pBlkTable, AcDb::kForRead);
if(!pBlkTable->has(blkName))
{
acutPrintf("\nBlock definition %s not found. ", blkName);
pBlkTable->close();
return;
}
pBlkTable->getAt(blkName, blkId);
pBlkTable->getAt(ACDB_MODEL_SPACE, pBlkTableRecord, AcDb::kForWrite);
pBlkTable->close();
pInsrtObj = new AcDbBlockReference(insPt, blkId);
pBlkTableRecord->appendAcDbEntity(insrtId, pInsrtObj);
acdbOpenObject(pBlkDefRecord, blkId, AcDb::kForRead);
if(pBlkDefRecord->hasAttributeDefinitions())
{
pBlkDefRecord->newIterator(pIterator);
for(pIterator->start(); !pIterator->done(); pIterator->step())
{
pIterator->getEntity(pEnt, AcDb::kForRead);
pAttDef = AcDbAttributeDefinition::cast(pEnt);
if(pAttDef != NULL && !pAttDef->isConstant())
{
pAtt = new AcDbAttribute();
pAtt->setPropertiesFrom(pAttDef);
pAtt->setInvisible(pAttDef->isInvisible());
basePt = pAttDef->position();
basePt += pInsrtObj->position().asVector();
pAtt->setPosition(basePt);
pAtt->setHeight(pAttDef->height());
pAtt->setRotation(pAttDef->rotation());
pTagPrompt = pAttDef->tag();
pAtt->setTag(pTagPrompt);
free(pTagPrompt);
pTagPrompt = pAttDef->prompt();
acutPrintf("%s%s", "\n", pTagPrompt);
free(pTagPrompt);
pAtt->setFieldLength(25);
pAtt->setTextString("This is a test");
pInsrtObj->appendAttribute(pAtt);
pAtt->close();
}
pEnt->close();
}// for
}// if has attribute definitions
delete pIterator;
pBlkTableRecord->close();
pInsrtObj->close();
}
前面的insrtBlk函数用在下面的ReadBlockName的函数中就出错!
void ReadBlockName()
{
char *pLtName;
CString blkName;
AcDbDatabase *pCurDb = NULL;
AcDbBlockTable *pltTable;
AcDbBlockTableRecord *pLtTableRcd;
AcDbBlockTableIterator *pLtIterator;
pCurDb = acdbHostApplicationServices()->workingDatabase();
pCurDb->getBlockTable(pltTable, AcDb::kForRead);
pltTable->newIterator(pLtIterator);
for(; !pLtIterator->done(); pLtIterator->step())
{
pLtIterator->getRecord(pLtTableRcd, AcDb::kForRead);
pLtTableRcd->getName(pLtName);
pLtTableRcd->close();
blkName = pLtName;
if((blkName[0] != '*') && (blkName[0] != '\0'))
{ acutPrintf("\nBlock name: %s", blkName);
insrtBlk(blkName); //在这里
}
blkName.Empty();
delete [] pLtName;
}// for
delete pLtIterator;
pltTable->close();
}
[/php]
望高手指点! |
|