BDYCAD 发表于 2013-6-24 15:13:41

acdbtext如何加入AcDbDatabase

本帖最后由 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,LayerChar;
    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文件,但是文字输不出,请高手指点一下我,怎么写才对??

286168051 发表于 2013-6-24 19:32:37

测试中 明天给您答复

风树 发表于 2013-10-13 18:23:38

286168051 发表于 2013-6-24 19:32 static/image/common/back.gif
测试中 明天给您答复

有答案吗,我也想知道

luowy 发表于 2013-10-24 16:27:51

看来没人肯回答阿。
那我来把

1,运行时识别,直接用下面的
if (pEnt->isKindof( AcDbText::desc ) )//判断实体是不是acdbtext,其他对象同此操作
{....}
2,你这个是将选中的代码另存为一个dwg,直接使用pNewEnt = pEnt->clone(),来在内存中创建一个与pEnt一模一样的对象。其余不用变。

BDYCAD 发表于 2013-11-6 14:00:32

感 谢楼上大侠:)
页: [1]
查看完整版本: acdbtext如何加入AcDbDatabase