- 积分
- 746
- 明经币
- 个
- 注册时间
- 2007-1-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2012-8-26 14:50:13
|
显示全部楼层
void insertblc(CString blcname,double x,double y,double z,double sf_x,double sf_y,double sf_z,double blcRotation)
{
if(blcname.Trim().GetLength()<1)return;//modified by yzh 20080901
//if(blcname==p[0][0])return;//modified by yzh 20090117
// TODO: Add your control notification handler code here
acDocManager->lockDocument(curDoc());
AcDbObjectId blockId; //要插入的块的Id值
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable,AcDb::kForRead);
//pBlockTable->getAt(blcname,blockId,AcDb::kForRead);//根据块名获得要插入的块的ID值
if ( pBlockTable->getAt(blcname,blockId,AcDb::kForRead) != Acad::eOk )
acutPrintf(L"\n块名%s不存在!",blcname);
AcDbBlockReference *pBlkRef=new AcDbBlockReference;//插入块实质是插入块的引用
pBlkRef->setBlockTableRecord(blockId);//指定所引用的图块表记录的对象ID
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,0.0);
acedTrans(&(normal.x),&from,&to,Adesk::kTrue,&(normal.x));//转换函数
AcGePoint3d basePoint(x,y,z);//指定的插入点(可以根据需要输入)
//acedGetPoint(NULL,"\\nEnter insertion point:",asDblArray(basePoint));
double sfx = pBlkRef->scaleFactors().sx;
double sfy = pBlkRef->scaleFactors().sy;
double sfz = pBlkRef->scaleFactors().sz;
pBlkRef->setScaleFactors(AcGeScale3d(sfx*sf_x, sfy*sf_y, sfz*sf_z));//后加改变块比例
pBlkRef->setPosition(basePoint);
double ro=blcRotation/180*3.1415926;
/*
360度=2*3.1415926=6.2831852弧度了?
180度=1*3.1415926=3.1415926弧度了?
90度=1/2*3.1415926=1.5707963弧度了?
*/
pBlkRef->setRotation(ro);
pBlkRef->setNormal(normal);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId newEntId;
pBlockTableRecord->appendAcDbEntity(newEntId,pBlkRef);
pBlockTableRecord->close();
pBlkRef->close();
acDocManager->lockDocument(curDoc());
} |
|