- 积分
- 749
- 明经币
- 个
- 注册时间
- 2003-3-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2003-4-21 08:09:00
|
显示全部楼层
把你的代码和下面你码对照,看看有何不同?
//插入图形文件
Acad::ErrorStatus InsertDwgFile(CString strFilename,CString strBlockname)
{
Acad::ErrorStatus es;
AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);
pDb->readDwgFile(strFilename);
AcDbObjectId Id;
es = acdbHostApplicationServices()->workingDatabase()->insert(Id,strBlockname,pDb);
delete pDb;
return es;
}
//////////////////////////////////////////////////////////////
void InsertBlockWithAttributes(CString strBlockname,AcGePoint3d basePoint,double dAngle,AcGeScale3d scale)
{
// Build the block definition to be inserted.
AcDbObjectId blockId;
AcDbBlockTable *pBlockTable1;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable1, AcDb::kForWrite);
pBlockTable1->getAt(strBlockname,blockId);
pBlockTable1->close();
// Step 1: Allocate a block reference object.
AcDbBlockReference *pBlkRef = new AcDbBlockReference;
// Step 2: Set up the block reference to the newly
// created block definition.
pBlkRef->setBlockTableRecord(blockId);
// Give it the current UCS normal.
struct resbuf to, from;
from.restype = RTSHORT;
from.resval.rint = 1; // UCS
to.restype = RTSHORT;
to.resval.rint = 0; // WCS
AcGeVector3d normal(0.0, 0.0, 1.0);
acedTrans(&(normal.x), &from, &to, Adesk::kTrue,&(normal.x));
// Set the insertion point for the block reference.
pBlkRef->setPosition(basePoint);
// Indicate the LCS 0.0 angle, not necessarily the UCS 0.0 angle.
pBlkRef->setRotation(dAngle);
pBlkRef->setScaleFactors(scale);
pBlkRef->setNormal(normal);
// Step 3: Open the current database's model space
// block Table Record.
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
pBlockTable->close();
// Append the block reference to the model space
// block Table Record.
AcDbObjectId newEntId;
pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
pBlockTableRecord->close();
// Step 4: Open the block definition for read.
AcDbBlockTableRecord *pBlockDef;
acdbOpenObject(pBlockDef, blockId, AcDb::kForRead);
// Set up a block table record iterator to iterate
// over the attribute definitions.
AcDbBlockTableRecordIterator *pIterator;
pBlockDef->newIterator(pIterator);
AcDbEntity *pEnt;
AcDbAttributeDefinition *pAttdef;
for (pIterator->start(); !pIterator->done();
pIterator->step())
{
// Get the next entity.
pIterator->getEntity(pEnt, AcDb::kForRead);
// Make sure the entity is an attribute definition
// and not a constant.
pAttdef = AcDbAttributeDefinition::cast(pEnt);
if (pAttdef != NULL && !pAttdef->isConstant())
{
// We have a non-constant attribute definition,
// so build an attribute entity.
AcDbAttribute *pAtt = new AcDbAttribute();
pAtt->setPropertiesFrom(pAttdef);
pAtt->setInvisible(pAttdef->isInvisible());
// Translate the attribute by block reference.
// To be really correct, the entire block
// reference transform should be applied here.
basePoint = pAttdef->position();
basePoint += pBlkRef->position().asVector();
pAtt->setPosition(basePoint);
pAtt->setHeight(pAttdef->height());
pAtt->setRotation(pAttdef->rotation());
pAtt->setTag("Tag");
pAtt->setFieldLength(25);
char *pStr = pAttdef->tag();
pAtt->setTag(pStr);
free(pStr);
pAtt->setFieldLength(pAttdef->fieldLength());
// The database column value should be displayed.
// INSERT prompts for this.
pAtt->setTextString("Assigned Attribute Value");
AcDbObjectId attId;
pBlkRef->appendAttribute(attId, pAtt);
pAtt->close();
}
pEnt->close(); // use pEnt... pAttdef might be NULL
}
delete pIterator;
pBlockDef->close();
pBlkRef->close();
}
//////////////////////////////////////////
if(InsertDwgFile(strPath + "Block\\a0-0.dwg","A00") != Acad::eOk)
{
MessageBox("插入图形文件A0-0.Dwg不成功!");
return;
}
AcGePoint3d basePoint(-25,-10,0);
AcGeScale3d scale(1,1,1);
InsertBlockWithAttributes("A00",basePoint,0.0,scale); |
|