- 积分
- 19100
- 明经币
- 个
- 注册时间
- 2003-8-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 BDYCAD 于 2013-6-24 15:27 编辑
- //InObjIDList为输出对象ID表
- //fileName为输出文件名称,格式如_T("C:\\abc.dwg")
- bool acdbSaveAsR14Dwg(AcDbObjectIdArray InObjIDList,const ACHAR* fileName){
- if (InObjIDList.length()==0)return FALSE;//没有对象,所以不往下远行程序,防止输出空文档
- AcDbDatabase *pDb = new AcDbDatabase();
- AcDbBlockTable *pBtbl;
- pDb->getSymbolTable(pBtbl, AcDb::kForRead);
- AcDbBlockTableRecord *pBtblRcd;
- pBtbl->getAt(ACDB_MODEL_SPACE, pBtblRcd,AcDb::kForWrite);
- pBtbl->close();
- AcDbObjectId ObjID;
- AcDbEntity *pEnt;
- AcGeMatrix3d xform1;
- AcGePoint3d ptStart(0,0,0), ptEnd(0,0,0);
- xform1.setTranslation(AcGeVector3d(ptEnd-ptStart));
- AcDbObjectId layid;
- AcDbLayerTable *pLayerTbl; //先声明一个空的层表指针
- pDb->getSymbolTable(pLayerTbl,AcDb::kForWrite);//当前图形数据库打开层表为写入状态
- AcDbLayerTableRecord *pLayerTblRcd= new AcDbLayerTableRecord();//笔线层表记录
- pLayerTblRcd->setName(_T("1")); //设定图层名
- pLayerTblRcd->setIsFrozen(0); // 图层解冻
- pLayerTblRcd->setIsOff(0); // 打开图层
- pLayerTblRcd->setVPDFLT(0); // 使用默认视口
- pLayerTblRcd->setIsLocked(0 ); // 图层解锁
- AcCmColor color; // AcCmColor是ACAD颜色管理类
- color.setColorIndex(1);// 图层颜色为红色
- pLayerTblRcd->setColor(color);
- pLayerTbl->add(pLayerTblRcd);
- pLayerTblRcd->close();
- pLayerTblRcd=new AcDbLayerTableRecord();//中心线层表记录
- pLayerTblRcd->setName(_T("2")); //设定图层名
- pLayerTblRcd->setIsFrozen(0); // 图层解冻
- pLayerTblRcd->setIsOff(0); // 打开图层
- pLayerTblRcd->setVPDFLT(0); // 使用默认视口
- pLayerTblRcd->setIsLocked(0 ); // 图层解锁
- color.setColorIndex(7);// 图层颜色为黑色
- pLayerTblRcd->setColor(color);
- pLayerTbl->add(pLayerTblRcd);
- pLayerTblRcd->close();
- pLayerTblRcd=new AcDbLayerTableRecord();//线槽层表记录
- pLayerTblRcd->setName(_T("5")); //设定图层名
- pLayerTblRcd->setIsFrozen(0); // 图层解冻
- pLayerTblRcd->setIsOff(0); // 打开图层
- pLayerTblRcd->setVPDFLT(0); // 使用默认视口
- pLayerTblRcd->setIsLocked(0 ); // 图层解锁
- color.setColorIndex(5);// 图层颜色为黑色
- pLayerTblRcd->setColor(color);
- pLayerTbl->add(pLayerTblRcd);
- pLayerTblRcd->close();
- pLayerTbl->close();
- AcGePoint3dArray PointList;
- for (int i=0;InObjIDList.length()>i;i++)
- {
- ObjID=InObjIDList.at(i);
- if (acdbOpenObject(pEnt,ObjID,AcDb::kForWrite)!=Acad::eOk)continue;
- const ACHAR *ObjNameChar=pEnt->isA()->name();
- const ACHAR *ObjLayer=pEnt->layer();
- PointList.removeAll();
- pEnt->getStretchPoints(PointList);
- pEnt->close();
- if (!_tcscmp(ObjNameChar,_T("AcDbLine")))
- {
- AcDbLine *newEnt=new AcDbLine(PointList.first(),PointList.last());
- pBtblRcd->appendAcDbEntity(newEnt);
- newEnt->setLayer(ObjLayer);
- newEnt->close();
- }
- if (!_tcscmp(ObjNameChar,_T("AcDbPolyline"))||
- !_tcscmp(ObjNameChar,_T("AcDb2dPolyline")))
- {
- AcDb2dPolyline *newEnt=new AcDb2dPolyline(AcDb::k2dSimplePoly,PointList,0.0,Adesk::kFalse);
- pBtblRcd->appendAcDbEntity(newEnt);
- newEnt->setLayer(ObjLayer);
- newEnt->close();
- }
- if (!_tcscmp(ObjNameChar,_T("AcDbCircle")))
- {
- AcDbCircle *pCir;
- if (acdbOpenObject(pCir,ObjID,AcDb::kForWrite)==Acad::eOk)
- {
- AcGePoint3d Cpt=pCir->center();
- ads_real Radius=pCir->radius();
- pCir->close();
- pCir=new AcDbCircle();
- pCir->setCenter(Cpt);
- pCir->setRadius(Radius);
- pCir->setLayer(ObjLayer);
- pBtblRcd->appendAcDbEntity(pCir);
- pCir->close();
- }
- }
- if (!_tcscmp(ObjNameChar,_T("AcDbText")))
- {
- AcDbText *pText;
- if (acdbOpenObject(pText,ObjID,AcDb::kForWrite)==Acad::eOk)
- {
- ACHAR TextChar[MAX_PATH],LayerChar[MAX_PATH];
- ads_real TextHigth=pText->height();
- _tcscpy(TextChar,pText->textString());
- AcGePoint3d Cpt=pText->position();
- AcDbObjectId TSid=pText->textStyle();
- pText->close();
- pText=new AcDbText();
- pText->setLayer(ObjLayer);
- pText->setTextString(TextChar);
- pText->setHeight(TextHigth);
- pText->setHorizontalMode(AcDb::kTextCenter);
- pText->setTextStyle(TSid);
- pText->setLayer(ObjLayer);
- //te->setVerticalMode(AcDb::kTextVertMid);
- pText->setAlignmentPoint(Cpt);
- AcDbBlockTable *blocktable;
- acdbHostApplicationServices()->workingDatabase()->getSymbolTable(blocktable,AcDb::kForRead);
- pDb->getSymbolTable(blocktable,AcDb::kForRead);
- AcDbBlockTableRecord *blocktablerecord;
- blocktable->getAt(ACDB_MODEL_SPACE,blocktablerecord,AcDb::kForWrite);
- blocktablerecord->appendAcDbEntity(pText);
- pBtblRcd->appendAcDbEntity(pText);
- blocktable->close();
- blocktablerecord->close();
- pText->close();
- }
- }
- }
- pBtblRcd->close();
- pDb->saveAs(fileName, false, AcDb::kDHL_1014);
- delete pDb;
- return TRUE;
- }
复制代码 如上代我近来正在写的代码。是把对象输出一个DWG文件,但是文字输不出,请高手指点一下我,怎么写才对??
|
|