JA_JERRY 发表于 2005-3-30 21:31:00

[分享]图块插入源码

希望能对大家有用,我花了好久才看懂的,刚学编程不久不要笑我菜,欢迎批评指正
void CTestPlate::OnBlockInsert()
{
        // TODO: Add your control notification handler code here
        acDocManager->lockDocument(curDoc());
        AcDbObjectId blockId;               //要插入的块的Id值
        AcDbBlockTable *pBlockTable;
        acdbHostApplicationServices()->workingDatabase()
                ->getSymbolTable(pBlockTable,AcDb::kForRead);
        Acad::eOk!=pBlockTable->getAt("ASDK-NO-ATTR",
                blockId,AcDb::kForRead)//根据块名获得要插入的块的ID值
        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,1.0);
        acedTrans(&(normal.x),&from,&to,Adesk::kTrue,&(normal.x));//转换函数
        AcGePoint3d basePoint(12,23,0);//指定的插入点(可以根据需要输入)
        //acedGetPoint(NULL,"\nEnter insertion point:",asDblArray(basePoint));
        pBlkRef->setPosition(basePoint);
        pBlkRef->setRotation(0.0);
        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());
}

我的ARX 发表于 2005-4-1 10:11:00

谢谢楼主!!!

anston 发表于 2005-4-3 16:26:00

正好要用这个功能,先看看再改进一下

578749467 发表于 2010-11-2 18:10:00


谢谢楼主!!!

hourui800720 发表于 2011-7-13 23:35:00

谢谢,看下先
页: [1]
查看完整版本: [分享]图块插入源码