明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2044|回复: 7

关于进行文本标注

[复制链接]
发表于 2005-9-6 17:56:00 | 显示全部楼层 |阅读模式

新建图层“选址标注”;当鼠标点击屏幕位置(鼠标事件的响应?)时在点击位置标注内容:“建设项目选址意见书[2005字]”

哪位高手帮忙 回个话  做不了我可就完蛋了

现在已经完成了新建图层:

void createNewLayer(const CString LayerName, const int color)
{  AcDbLayerTable *pLayerTbl;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pLayerTbl, AcDb::kForWrite);
 //获得当前层表以便写入
    if (!pLayerTbl->has(LayerName)) {
        AcDbLayerTableRecord *pLayerTblRcd
            = new AcDbLayerTableRecord;
        pLayerTblRcd->setName(LayerName);
        pLayerTblRcd->setIsFrozen(0);// layer to THAWED解冻图层
        pLayerTblRcd->setIsOff(0);   // layer to ON  打开图层
        pLayerTblRcd->setVPDFLT(0);  // viewport default视口默认值
        pLayerTblRcd->setIsLocked(0);// un-locked   解锁图层

        AcCmColor color1;
        color1.setColorIndex(color); // set color to color
        pLayerTblRcd->setColor(color1);


        AcDbLinetypeTable *pLinetypeTbl;
        AcDbObjectId ltId;
        acdbHostApplicationServices()->workingDatabase()
            ->getSymbolTable(pLinetypeTbl, AcDb::kForRead);
        if ((pLinetypeTbl->getAt("CONTINUOUS", ltId))
            != Acad::eOk)
        {
            acutPrintf("\nUnable to find CONTINUOUS"
                " linetype. Using DASHED");
            pLinetypeTbl->getAt("CONTINUOUS", ltId);
        }
        pLinetypeTbl->close();//设置线型

        pLayerTblRcd->setLinetypeObjectId(ltId);


        pLayerTbl->add(pLayerTblRcd); //将层表记录添加到层表中!
        pLayerTblRcd->close();//关闭层表记录
        pLayerTbl->close();//关闭层表
    } else {
        pLayerTbl->close();
        acutPrintf("\n图层已经存在!");
    }
 /*
 AcDb:ineWeight lw;                 //设置层的线宽
 lw = AcDb::kLnWt080;                 //value:80
 pLayerTableRecord->setLineWeight(lw);
 */

}

 

 楼主| 发表于 2005-9-7 14:09:00 | 显示全部楼层

朋友给了段带码很管用,但是遇到两个问题:

1。文章是中文的时候出现乱码?

2。不知道如何设坐标点(下面的代码是坐标点已知的),使得在鼠标点击屏幕位置(鼠标事件的响应?)时的点击位置标注内容?

void addtext(   char textString[512])
{
 
 AcDbBlockTable *pBlockTablew;
 acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTablew, AcDb::kForRead);
 AcDbBlockTableRecord *pBlockTableRecordw;
 pBlockTablew->getAt(ACDB_MODEL_SPACE, pBlockTableRecordw, AcDb::kForWrite);
 pBlockTablew->close();


 AcGePoint3d textPosition(10.0, 10.0, 0.0);
 AcGePoint3d atextPosition(20.0, 10.0, 0.0);
 //char textString[512] = "建设项目选址意见书[2005字]    号红线附图";
 double textHeight = 5.5296;
 double textWidthFactor = 0.8000;
 double textRotation = 0.0;

 AcDbText *pText=new AcDbText(textPosition, textString, AcDbObjectId::kNull, textHeight, textRotation);
 pText->setHorizontalMode(AcDb::kTextMid);
 pText->setAlignmentPoint(atextPosition);

 AcDbObjectId textId;
 pBlockTableRecordw->appendAcDbEntity(textId, pText);
 pBlockTableRecordw->close();
 pText->close();
}

发表于 2005-9-8 08:29:00 | 显示全部楼层

我也想知道,帮你顶

发表于 2005-9-23 21:01:00 | 显示全部楼层

1。文章是中文的时候出现乱码?

>设置文本的样式

 

发表于 2005-9-23 21:32:00 | 显示全部楼层

 

 

AcDbTextStyleTableRecord* pStyleNew= new AcDbTextStyleTableRecord;

pStyleNew->setName((LPCTSTR)strName);
 pStyleNew->setFileName("gbenor.shx");
 pStyleNew->setBigFontFileName("gbcbig.shx");//支持中文
 pStyleNew->setXScale(1.0);

 楼主| 发表于 2005-9-24 09:53:00 | 显示全部楼层

谢谢这位朋友的关注  问题都已解决,给出代码如下:

 

 //准备开始文字注记
 AcDbBlockTable *pBlockTablew;
 acdbHostApplicationServices()->workingDatabase()
  ->getSymbolTable(pBlockTablew, AcDb::kForRead);
 AcDbBlockTableRecord *pBlockTableRecordw;
 pBlockTablew->getAt(ACDB_MODEL_SPACE,
  pBlockTableRecordw, AcDb::kForWrite);
 AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase ();

Acad::ErrorStatus  es; //打开数据库->块表->块表记录
 es = pDb->getBlockTable (pBlockTablew,AcDb::kForRead );
 // ERROR HANDLE
 es = pBlockTablew->getAt (ACDB_MODEL_SPACE,pBlockTableRecordw,AcDb::kForWrite );
 AcDbTextStyleTable *pTST;
 AcDbTextStyleTableRecord *pTSTR;
 es = pDb->getTextStyleTable (pTST,AcDb::kForRead );
 //文字样式表-〉文字样式表记录-〉打开记录读取
 AcDbObjectId idTextStyle;
 es = pTST->getAt("Standard",idTextStyle);
 es = pTST->getAt("Standard",pTSTR,AcDb::kForWrite );
 pTSTR->setFileName("HZTXT");//****
 if(es != Acad::eOk){
  acutPrintf("fail to get the standard text style\n");
 }
 //////////////////////////////////
 pBlockTablew->close();//关闭块表
 
    ads_point point;
 int ret; 
 ret = acedGetPoint(NULL,"\n输入文本标注中心点的坐标:",point);
 ret= acedCommand(RTSTR, "boundary",RTPOINT ,point, RTSTR, "",0) ;
 acutPrintf("\n你选的点坐标为 x = %.3f y = %.3f",point[0],point[1]);
 AcGePoint3d textPosition(point[0], point[1], 0.0);
 AcGePoint3d atextPosition(point[0], point[1], 0.0);
 
 double textHeight = 10;
 double textWidthFactor = 0.8000;
 double textRotation = 0.0;
 
 AcDbText *pText=new AcDbText(textPosition, textString, AcDbObjectId::kNull, textHeight, textRotation);
 pText->setHorizontalMode(AcDb::kTextMid);
 pText->setAlignmentPoint(atextPosition);
 pText->setColorIndex (1);
 
 pText->setTextStyle (idTextStyle);
 
 AcDbObjectId idTxt = AcDbObjectId::kNull ;
 pBlockTableRecordw->appendAcDbEntity(idTxt,pText);
 
 pTST->close();//文字样式表
 pTSTR->close();//文字样式表记录
 //////////////////////////////////////////////////////////////////////
 
 AcDbObjectId textId;
 pBlockTableRecordw->appendAcDbEntity(textId, pText); //*
 pBlockTableRecordw->close();
 pText->close();

发表于 2011-7-30 16:19:25 | 显示全部楼层
我的问题依旧
发表于 2011-7-30 16:19:57 | 显示全部楼层
我的问题依旧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 11:07 , Processed in 0.155242 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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