乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 40|回复: 2

to 版主

[复制链接]

5

主题

7

帖子

2

银币

初来乍到

Rank: 1

铜币
27
发表于 2003-4-19 22:07:00 | 显示全部楼层 |阅读模式
前段时间有篇名叫《编程日记(1)ARX中如何insert一个图》的文章怎么没看见了??
还有我按照上面的思路写了一段程序,但是插入后,当前窗口中没有我所插入的图形!请指教!!
程序代码如下:
void InsertBlock()
{
        char bName[256],pfName[256];
        int es;
        AcGePoint3d Pt(0,0,0);
        double Angle = 0.0;
        AcGeScale3d XrefScale(1,1,1);
        strcpy(bName,"first");
        strcpy(pfName,"F:\\FENGH\\program\\AutoCAD\\ObjectARX\\LibMag\\libmag.dwg");
        
        
        AcDbDatabase *pDbMS = new AcDbDatabase(Adesk::kFalse);
        if(pDbMS->readDwgFile(pfName) != Acad::eOk)
        {
                acutPrintf("\nThe file %s cannot be opend",pfName);
                return;
        }
//        pDbMS->getBlockTable(pBlockTable,AcDb::kForRead);
//        pBlockTable->close();        
        
        AcDbDatabase * curpDb = acdbHostApplicationServices()->workingDatabase();
        AcDbObjectId blockId;
        
        if((es = curpDb->insert(blockId, bName,pDbMS, true)) == Acad::eOk) //´ÓÊý¾Ý¿â²åÈëͼ¿âÖÐ
        {
                acutPrintf("\ninsert ok\n");
               
        }
        else
        {
                AfxMessageBox("Insert failed");
                delete pDbMS;
                return;
        }
        AcDbBlockReference *pBlkRef = new AcDbBlockReference; //´´½¨Ò»¸ö¿é±íÒýÓÃ
        pBlkRef->setBlockTableRecord(blockId);// Ö¸ÏòblockId;
        pBlkRef->setPosition(Pt);//ÉèÖÃλÖÃ
        pBlkRef->setRotation(Angle);//ÉèÖÃת½Ç
        pBlkRef->setScaleFactors( XrefScale);//ÉèÖ÷Ŵó±ÈÀý         AcDbBlockTable *pBlockTable;
        curpDb->getSymbolTable(pBlockTable, AcDb::kForRead);
        AcDbBlockTableRecord *pBlockTableRecord;
        pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
        pBlockTable->close();
        AcDbObjectId newEntId;
        pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
        pBlockTableRecord->close();
        
//        delete pDbMS;        
        acutPrintf("\nprogram begin add attribute\n");
        AcDbBlockTableRecord *pBlockDef;
        acdbOpenObject(pBlockDef, blockId, AcDb::kForRead);
        AcDbBlockTableRecordIterator *pIterator;
        pBlockDef->newIterator(pIterator);
        AcGePoint3d basePoint;
        AcDbEntity *pEnt;
        AcDbAttributeDefinition *pAttdef;
        for (pIterator->start(); !pIterator->done();
        pIterator->step())//½«source.dwgÖеÄËùÓÐAttibute½øÐбéÀú
        {
        pIterator->getEntity(pEnt, AcDb::kForRead);
        pAttdef = AcDbAttributeDefinition::cast(pEnt);
        
                if (pAttdef != NULL && !pAttdef->isConstant())
                {
            AcDbAttribute *pAtt = new AcDbAttribute();
            pAtt->setPropertiesFrom(pAttdef);
            pAtt->setInvisible(pAttdef->isInvisible());
            basePoint = pAttdef->position();
            basePoint += pBlkRef->position().asVector();
            pAtt->setPosition(basePoint);
            pAtt->setHeight(pAttdef->height());
            pAtt->setRotation(pAttdef->rotation());
            pAtt->setTag("Tag");
            pAtt->setFieldLength(25);
            char *pStr = pAttdef->tag();
            pAtt->setTag(pStr);
                        acutDelString(pStr);
            pAtt->setFieldLength(pAttdef->fieldLength());
            pAtt->setTextString("-");
            AcDbObjectId attId;
            pBlkRef->appendAttribute(attId, pAtt);
            pAtt->close();
        }
        pEnt->close(); // use pEnt... pAttdef might be NULL
    }
    pBlockDef->close();
        delete pIterator;
        delete pDbMS;        
        acutPrintf("\nprogram end!\n");
}
回复

使用道具 举报

7

主题

21

帖子

2

银币

初来乍到

Rank: 1

铜币
49
发表于 2003-4-21 08:09:00 | 显示全部楼层
//插入图形文件
Acad::ErrorStatus InsertDwgFile(CString strFilename,CString strBlockname)
{
        Acad::ErrorStatus es;
        AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);
        pDb->readDwgFile(strFilename);
        AcDbObjectId Id;
        es = acdbHostApplicationServices()->workingDatabase()->insert(Id,strBlockname,pDb);
        delete pDb;
        return es;
}
//////////////////////////////////////////////////////////////
void InsertBlockWithAttributes(CString strBlockname,AcGePoint3d basePoint,double dAngle,AcGeScale3d scale)
{
    // Build the block definition to be inserted.
    AcDbObjectId blockId;
        AcDbBlockTable *pBlockTable1;
          acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable1, AcDb::kForWrite);
          pBlockTable1->getAt(strBlockname,blockId);
          pBlockTable1->close();
    // Step 1: Allocate a block reference object.
    AcDbBlockReference *pBlkRef = new AcDbBlockReference;
    // Step 2: Set up the block reference to the newly
    // created block definition.
    pBlkRef->setBlockTableRecord(blockId);
    // Give it the current UCS normal.
    struct 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));
    // Set the insertion point for the block reference.
    pBlkRef->setPosition(basePoint);
    // Indicate the LCS 0.0 angle, not necessarily the UCS 0.0 angle.
    pBlkRef->setRotation(dAngle);
        pBlkRef->setScaleFactors(scale);
    pBlkRef->setNormal(normal);
    // Step 3: Open the current database's model space
    // block Table Record.
    AcDbBlockTable *pBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);
    AcDbBlockTableRecord *pBlockTableRecord;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
        AcDb::kForWrite);
    pBlockTable->close();
    // Append the block reference to the model space
    // block Table Record.
    AcDbObjectId newEntId;
    pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef);
    pBlockTableRecord->close();
    // Step 4: Open the block definition for read.
    AcDbBlockTableRecord *pBlockDef;
    acdbOpenObject(pBlockDef, blockId, AcDb::kForRead);
    // Set up a block table record iterator to iterate
    // over the attribute definitions.
    AcDbBlockTableRecordIterator *pIterator;
    pBlockDef->newIterator(pIterator);
    AcDbEntity *pEnt;
    AcDbAttributeDefinition *pAttdef;
    for (pIterator->start(); !pIterator->done();
        pIterator->step())
    {
        // Get the next entity.
        pIterator->getEntity(pEnt, AcDb::kForRead);
        // Make sure the entity is an attribute definition
        // and not a constant.
        pAttdef = AcDbAttributeDefinition::cast(pEnt);
        if (pAttdef != NULL && !pAttdef->isConstant())
                {
            // We have a non-constant attribute definition,
            // so build an attribute entity.
            AcDbAttribute *pAtt = new AcDbAttribute();
            pAtt->setPropertiesFrom(pAttdef);
            pAtt->setInvisible(pAttdef->isInvisible());
            // Translate the attribute by block reference.
            // To be really correct, the entire block
            // reference transform should be applied here.
            basePoint = pAttdef->position();
            basePoint += pBlkRef->position().asVector();
            pAtt->setPosition(basePoint);
            pAtt->setHeight(pAttdef->height());
            pAtt->setRotation(pAttdef->rotation());
            pAtt->setTag("Tag");
            pAtt->setFieldLength(25);
            char *pStr = pAttdef->tag();
            pAtt->setTag(pStr);
            free(pStr);
            pAtt->setFieldLength(pAttdef->fieldLength());
            // The database column value should be displayed.
            // INSERT prompts for this.
            pAtt->setTextString("Assigned Attribute Value");
            AcDbObjectId attId;
            pBlkRef->appendAttribute(attId, pAtt);
            pAtt->close();
        }
        pEnt->close(); // use pEnt... pAttdef might be NULL
    }
    delete pIterator;
    pBlockDef->close();
    pBlkRef->close();
}
//////////////////////////////////////////
if(InsertDwgFile(strPath + "Block\\a0-0.dwg","A00") != Acad::eOk)
                                {
                                        MessageBox("插入图形文件A0-0.Dwg不成功!");
                                        return;
                                }
AcGePoint3d basePoint(-25,-10,0);
                                AcGeScale3d scale(1,1,1);
                                InsertBlockWithAttributes("A00",basePoint,0.0,scale);
回复

使用道具 举报

32

主题

150

帖子

7

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
278
发表于 2003-4-22 11:49:00 | 显示全部楼层
运行InsertDwgFile()后,得到一个ID,创建一个AcDbBlockReference, 并将它指向ID所代表的AcDbBlockRecord, 然后将这个AcDbBlockReference加入pDb所代表的图形数据库中.
你的程序中,得到ID后,没有操作这个ID.
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2024-11-22 09:14 , Processed in 0.348321 second(s), 69 queries .

© 2020-2024 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表