明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3039|回复: 14

救命啊!请教:Objectarx的一个具体而微的问题

  [复制链接]
发表于 2003-4-19 21:36 | 显示全部楼层 |阅读模式
我写了一段代码想实现创建实体后存盘如下,编译链接都通过了。但是在AutoCAD2002上
加载的时候出现“文件读写错误”的提示框,我实在是不知道错在哪里,请大侠指教啊
void createDwg()
{
        AcDbDatabase*pDb=new AcDbDatabase();
        AcDbBlockTable*pBtbl;
        pDb->getSymbolTable(pBtbl,AcDb::kForRead);
        AcDbBlockTableRecord*pBtblRcd;
        pBtbl->getAt(ACDB_MODEL_SPACE,pBtblRcd,AcDb::kForWrite);
        pBtbl->close();
        AcDbCircle*pCir1=new AcDbCircle(AcGePoint3d(200,200,0),
                                           AcGeVector3d(0,0,1),50.0);
        AcDbCircle*pCir2=new AcDbCircle(AcGePoint3d(400,200,0),         
                                           AcGeVector3d(0,0,1),50.0);
        AcDbLine*pLine=new AcDbLine(AcGePoint3d(300,230,0),
                                           AcGePoint3d(300,50,0));
        pLine->setColorIndex(1);
        AcDbPolyline*pPolyline=new AcDbPolyline(4);
        AcGePoint2d pt;
        pt.x=220;
        pt.y=60;
        pPolyline->addVertexAt(0,pt,0.0,-1.0,-1.0);
        pt.x=250;
        pt.y=30;
        pPolyline->addVertexAt(1,pt,0.0,-1.0,-1.0);
        pt.x=350;
        pt.y=30;
        pPolyline->addVertexAt(2,pt,0.0,-1.0,-1.0);
        pt.x=380;
        pt.y=60;
        pPolyline->addVertexAt(3,pt,0.0,-1.0,-1.0);
        pPolyline->setThickness(100);
        pPolyline->setColorIndex(4);

        pBtblRcd->appendAcDbEntity(pCir1);
        pCir1->close();
        pBtblRcd->appendAcDbEntity(pCir2);
    pCir2->close();
        pBtblRcd->appendAcDbEntity(pLine);
        pLine->close();
        pBtblRcd->appendAcDbEntity(pPolyline);
        pPolyline->close();//以上分别创建了两个园,一条线,一条多义线
           //下面想把它们存盘

    saveAs("face.dwg");//难道问题就出在这里?
        delete pDb;
}

在响应消息kInitAppMsg时,定义了命令create
        acedRegCmds->addCommand("ASDK_DWG_COMMANDS","ASDK_CREATE",
                "CREATE",ACRX_CMD_MODAL,createDwg);
 楼主| 发表于 2003-4-19 21:40 | 显示全部楼层

对不起慌忙中写错了应该是pDb->saveAs("face.dwg");为什么加载后不行啊,郁闷

如题
发表于 2003-4-19 21:57 | 显示全部楼层

我也遇到同样问题!存不了!

 楼主| 发表于 2003-4-19 22:05 | 显示全部楼层

难道注定就存不了?或者是盗版的问题?

那咋办呢???
发表于 2003-4-20 11:07 | 显示全部楼层

以下代码引用帮助文档

本帖最后由 作者 于 2003-4-20 11:07:14 编辑

Example of Database Operations  


The following example shows the createDwg() routine, which creates a new database, obtains the model space block table record, and creates two circles that are added to model space. It uses the AcDbDatabase::saveAs() function to save the drawing. The second routine, readDwg(), reads in the saved drawing, opens the model space block table record, and iterates through it, printing the class names of the entities it contains.

void
createDwg()
{
    AcDbDatabase *pDb = new AcDbDatabase();
  
    AcDbBlockTable *pBtbl;
    pDb->getSymbolTable(pBtbl, AcDb::kForRead);

    AcDbBlockTableRecord *pBtblRcd;
    pBtbl->getAt(ACDB_MODEL_SPACE, pBtblRcd,
        AcDb::kForWrite);
    pBtbl->close();

    AcDbCircle *pCir1 = new AcDbCircle(AcGePoint3d(1,1,1),
                                       AcGeVector3d(0,0,1),
                                       1.0),
               *pCir2 = new AcDbCircle(AcGePoint3d(4,4,4),
                                       AcGeVector3d(0,0,1),
                                       2.0);
    pBtblRcd->appendAcDbEntity(pCir1);
    pCir1->close();
   
    pBtblRcd->appendAcDbEntity(pCir2);
    pCir2->close();
    pBtblRcd->close();

    // AcDbDatabase::saveAs() does not automatically
    // append a DWG file extension, so it
    // must be specified.
    //
    pDb->saveAs("test1.dwg");
    delete pDb;
}

你的代码没有错吧,只不过多创建了一条线段和一条多段线
发表于 2003-4-20 11:35 | 显示全部楼层

以上代码在AutoCAD2000中使用正常!

以上代码在AutoCAD2000中使用正常!
发表于 2003-4-20 12:49 | 显示全部楼层

一个问题

这段代码在2000上能用我试过
但我在插入图块后,在用saveAs就存不了!
发表于 2003-4-21 09:35 | 显示全部楼层

pBtblRcd->close();

 楼主| 发表于 2003-4-21 23:04 | 显示全部楼层

斑竹:我加了pBtblRcd->close();在pDb->saveAs("test1.dwg");前面

在运行create时,这次没有出现那个出错对话框了,但时找不到那个face.dwg文件
,还请指教
 楼主| 发表于 2003-4-21 23:11 | 显示全部楼层

解决了

3Q
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-20 18:03 , Processed in 0.221314 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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