gdc666 发表于 2003-4-19 21:36:00

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

我写了一段代码想实现创建实体后存盘如下,编译链接都通过了。但是在2002上
加载的时候出现“文件读写错误”的提示框,我实在是不知道错在哪里,请大侠指教啊
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);

gdc666 发表于 2003-4-19 21:40:00

如题

gdc666 发表于 2003-4-19 22:05:00

那咋办呢???

JicketMoney 发表于 2003-4-20 11:07:00


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;
}
你的代码没有错吧,只不过多创建了一条线段和一条多段线

JicketMoney 发表于 2003-4-20 11:35:00

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

wwyfeng 发表于 2003-4-20 12:49:00

这段代码在2000上能用我试过
但我在插入图块后,在用saveAs就存不了!

gdc666 发表于 2003-4-21 23:04:00

在运行create时,这次没有出现那个出错对话框了,但时找不到那个face.dwg文件
,还请指教

gdc666 发表于 2003-4-21 23:11:00

3Q
页: [1]
查看完整版本: 救命啊!请教:Objectarx的一个具体而微的问题