void Jig3d::apply() throw(CmdException) { m_xform = m_xformTemp*m_xform; AcDbEntity* pE; if (acdbOpenObject(pE,m_int.m_idEntity,AcDb::kForWrite)==Acad::eOk) { Acad::ErrorStatus es; if ((es=pE->transformBy(m_xform))!=Acad::eOk) throw CmdException(es,"Transformation cannot be applied to object"); pE->close(); } }
void ArxEntityHelper::TransformEntities2( const AcDbObjectIdArray& objIds, const AcGeMatrix3d& xform ) { if( objIds.isEmpty() ) return; int len = objIds.length(); for( int i = 0; i < len; i++ ) { AcDbEntity* pEnt; if( Acad::eOk == acdbOpenAcDbEntity( pEnt, objIds[i], AcDb::kForWrite ) ) { pEnt->transformBy( xform ); pEnt->close(); } } }
Acad::ErrorStatus ArxDbgUtils::cloneAndXformObjects(AcDbDatabase* db, const AcDbObjectIdArray& entsToClone, const AcDbObjectId& ownerBlockId, const AcGeMatrix3d& xformMat, bool debugSpeak) { ASSERT(db != NULL); AcDbIdMapping idMap; Acad::ErrorStatus es = db->deepCloneObjects( const_cast<AcDbObjectIdArray&>(entsToClone), const_cast<AcDbObjectId&>(ownerBlockId), idMap); if (es != Acad::eOk) { ArxDbgUtils::rxErrorMsg(es); return es; } AcDbEntity* clonedEnt; AcDbIdPair idPair; AcDbIdMappingIter iter(idMap); for (iter.start(); !iter.done(); iter.next()) { if (!iter.getMap(idPair)) return Acad::eInvalidInput; if (idPair.isCloned()) { es = acdbOpenAcDbEntity(clonedEnt, idPair.value(), AcDb::kForWrite); if (es == Acad::eOk) { if (idPair.isPrimary()) { if (debugSpeak) acutPrintf(_T("\nCloned And Transformed: %s"), ArxDbgUtils::objToClassStr(clonedEnt)); clonedEnt->transformBy(xformMat); } else if (debugSpeak) acutPrintf(_T("\nCloned: %s"), ArxDbgUtils::objToClassStr(clonedEnt)); clonedEnt->close(); } else ArxDbgUtils::rxErrorMsg(es); } } return Acad::eOk; }
void ArxEntityHelper::TransformEntities( const AcDbObjectIdArray& objIds, const AcGeMatrix3d& xform ) { if( objIds.isEmpty() ) return; AcTransaction* pTrans = actrTransactionManager->startTransaction(); if( pTrans == 0 ) return; int len = objIds.length(); for( int i = 0; i < len; i++ ) { AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, objIds[i], AcDb::kForWrite ) ) continue; AcDbEntity* pEnt = AcDbEntity::cast( pObj ); if( pEnt == 0 ) continue; pEnt->transformBy( xform ); } actrTransactionManager->endTransaction(); }
static void BlockToEntity( const AcDbObjectId& blkId, const AcGeMatrix3d& blkXform, const AcStringArray& names, const AcStringArray& attValues, AcGeVoidPointerArray& ents ) { // 将块定义分解成独立的图元 // 将属性替换成多行文字 AcTransaction* pTrans = actrTransactionManager->startTransaction(); AcDbObject* pObj; if( Acad::eOk != pTrans->getObject( pObj, blkId, AcDb::kForRead ) ) { actrTransactionManager->abortTransaction(); return; } AcDbBlockTableRecord* pBTR = AcDbBlockTableRecord::cast( pObj ); // BUG:不能调用hasAttributeDefinitions()方法 // 调用之后,如果没有在块编辑器中对块进行修改, // 那么进行移动、夹点编辑等操作,没有动态显示效果 //if(!pBTR->hasAttributeDefinitions()) //{ // // 没有属性定义 // acutPrintf(_T("\n没有属性定义")); // actrTransactionManager->abortTransaction(); // return; //} AcDbBlockTableRecordIterator* pIterator; if( Acad::eOk != pBTR->newIterator( pIterator ) ) { actrTransactionManager->abortTransaction(); return; } // 遍历块中的图元,查找AcDbAttributeDefinition for( pIterator->start( true ); !pIterator->done(); pIterator->step( true ) ) { AcDbObjectId objId; if( Acad::eOk != pIterator->getEntityId( objId ) ) continue; if( Acad::eOk != pTrans->getObject( pObj, objId, AcDb::kForWrite ) ) continue; AcDbEntity* pEnt = AcDbEntity::cast( pObj ); if( !pEnt->isKindOf( AcDbAttributeDefinition::desc() ) ) { AcDbEntity* pClone = AcDbEntity::cast( pEnt->clone() ); pClone->transformBy( blkXform ); // 添加到实体集合 ents.append( pClone ); } else { AcDbAttributeDefinition* pAttDef = AcDbAttributeDefinition::cast( pEnt ); pAttDef->convertIntoMTextAttributeDefinition( Adesk::kTrue ); // 获取标签名称 ACHAR* pTag = pAttDef->tag(); int pos = names.find( pTag ); if( pos != -1 ) { // 获取多行文本对象 AcDbMText* pMText = pAttDef->getMTextAttributeDefinition(); pMText->transformBy( blkXform ); pMText->setContents( attValues[pos].kACharPtr() ); // 添加到实体集合 ents.append( pMText ); } acutDelString( pTag ); } } delete pIterator; actrTransactionManager->endTransaction(); }