你这样试试: HDR_API BOOL fdm_InsertDwgFile(const TCHAR *FileName,const AcGePoint3d &insPt,AcDbObjectId &BlkRefId,const double ang,const TCHAR *lay) { BOOL state=FALSE; TCHAR FullPath[128]; if(ads_findfile(FileName,FullPath)==RTNORM) { AcDbDatabase *pDb=new AcDbDatabase(Adesk::kFalse); if(pDb->readDwgFile(FullPath)==Acad::eOk) { if(pDb!=NULL) { AcDbObjectId ObjId; if(acdbCurDwg()->insert(ObjId,_T("*U"),pDb)==Acad::eOk) { AcDbObjectId ReferenceId=AcDbObjectId::kNull; AcDbBlockReference *pReference=new AcDbBlockReference; pReference->setBlockTableRecord(ObjId); pReference->setPosition(insPt); pReference->setRotation(ang); pReference->setLayer(lay); if(fdm_addToModelSpace(BlkRefId,pReference)==Acad::eOk) { state=TRUE; } else delete pReference; } delete pDb; } } } return state; } //将实体加入到(模型/图纸)空间 HDR_API Acad::ErrorStatus fdm_addToModelSpace(AcDbObjectId &ObjId,AcDbEntity *pObj,BOOL IsToMs) { AcDbBlockTable *pBlockTable; AcDbBlockTableRecord *pSpaceRecord; Acad::ErrorStatus es; es=acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForRead); if(es==Acad::eOk) { if(IsToMs) es=pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord,AcDb::kForWrite); else es=pBlockTable->getAt(ACDB_PAPER_SPACE,pSpaceRecord,AcDb::kForWrite); if(es==Acad::eOk) { es=pSpaceRecord->appendAcDbEntity(ObjId,pObj); if(es==Acad::eOk) pObj->close(); pSpaceRecord->close(); } pBlockTable->close(); } return es; } |