天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 47|回复: 0

[ObjectARX›] 图块位置不变的情况下重设块的插入点

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]void ResetAllInstances(AcDbBlockTableRecord * pBlockTableRecord, AcGeVector3d &translation)
{

// Note that this function does not implement any error checking.
// We are assuming that pBlockTableREcord was opened for write by the calling function

// Iterate through all block references of this block table record.
AcDbBlockReferenceIdIterator * pIterator;
pBlockTableRecord->newBlockReferenceIdIterator(pIterator);
for (pIterator->start();!pIterator->done();pIterator->step())
{
  AcDbBlockReference * pBlockRef;
  pIterator->getBlockReference(pBlockRef, AcDb::kForWrite,true);

  // Transform the translation vector from block coordinates to world coordinates.
  AcGeVector3d realTranslation = (pBlockRef->blockTransform())*translation;

  // Translate the block reference to counter the effect of the origin change.
  pBlockRef->setPosition(pBlockRef->position()+realTranslation);


  pBlockRef->close();
} // Next block reference
delete pIterator;
}[/code]


[code]
// This is command 'SGP'
void testFunc()
{

// Note that error checking is minimal.

ads_name ename ;
ads_point pt ;

// Ask the user to select an object
if( acedEntSel ("\nSelect the Block Reference", ename, pt) != RTNORM )
  return ;

// Open it
AcDbObjectId objId;
acdbGetObjectId (objId, ename) ;
AcDbEntity * pEnt;
acdbOpenObject (pEnt, objId, AcDb::kForRead);

// Check its a block reference
AcDbBlockReference *pRef = AcDbBlockReference::cast(pEnt);
if (pRef == NULL)
{
  pEnt->close();
  return;
}

// Get the block reference's associated block table record.
AcDbObjectId blockId =pRef->blockTableRecord ();
pRef->close();
AcDbBlockTableRecord *pBlockTableRecord;
acdbOpenObject (pBlockTableRecord, blockId, AcDb::kForWrite);

// Store the BTR's current origin (we'll need it later).
AcGePoint3d origin = pBlockTableRecord->origin();

// And set its new origin to (0, 0, 0)
pBlockTableRecord->setOrigin(AcGePoint3d(0, 0, 0));


// Create a translation vector for the change in displacement required to offset the origin change (in the block's coordinate system)
AcGeVector3d translation;
translation.set(-origin[X], -origin[Y], -origin[Z]);

// Now process all instances of this block reference to compensate for the change in the block origin
ResetAllInstances(pBlockTableRecord, translation);

pBlockTableRecord->close();
}[/code]

 

 

 

 

[ObjectARX›] 图块位置不变的情况下重设块的插入点
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 13:24 , Processed in 0.156849 second(s), 26 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表