注册 登录
明经CAD社区 返回首页

Gu_xl的个人空间 http://www.mjtd.com/?161460 [收藏] [复制] [分享] [RSS]

日志

用arx方法创建南方CASS的高程点

热度 6已有 2862 次阅读2014-4-15 09:06 |个人分类:VC++、ARX|系统分类:开发| 南方CASS, 高程点

//By Gu_xl
// AcGePoint3d insPt 插入点
// double scale 图块比例,1:1000比例尺 scale = 1.0
// AcDbObjectId &objId 返回的高程点ID
// double height 标注的高程值 ,默认 = -9999.0,高程值采用insPt的Z值
Acad::ErrorStatus CreateGC200(AcDbDatabase *pDb,AcGePoint3d insPt,double scale,AcDbObjectId &objId,int num = 3,double height = -9999.0);
Acad::ErrorStatus CreateGC200(AcDbDatabase *pDb,AcGePoint3d insPt,double scale,AcDbObjectId &objId,int num,double height)
{
if (pDb == NULL)
{
pDb = acdbHostApplicationServices()->workingDatabase();
}
AcDbBlockTable *pBlockTable;
AcDbBlockTableRecord *pBlockTableRecord;
AcDbLayerTable *pLayerTable;
AcDbLayerTableRecord *pLayerTableRecord;
AcDbLinetypeTable *pLineTypeTable;
AcDbTextStyleTable *pTextStyleTable;
AcDbTextStyleTableRecord *pTextStyleTableRecord;
AcDbObjectId BlockTableRecordId,LayerTableRecordId,lineTypeTableId,TextStyleTableRecordId;
Acad::ErrorStatus es;
es = pDb->getLinetypeTable(pLineTypeTable,AcDb::kForRead);
if (es != Acad::eOk)
{
return es;
}
es = pLineTypeTable->getAt(_T("Continuous"),lineTypeTableId);
if (es != Acad::eOk)
{
pLineTypeTable->close();
return es;
}
pLineTypeTable->close();
es = pDb->getBlockTable(pBlockTable,AcDb::kForRead);
if (es != Acad::eOk)
{
return es;
}
if (pBlockTable->has(_T("GC200")))
{
//得到块定义ID
pBlockTable->getAt(_T("GC200"),BlockTableRecordId);
}
else
{
//创建图块定义
es = pBlockTable->upgradeOpen();
if (es != Acad::eOk)
{
pBlockTable->close();
return es;
}
pBlockTableRecord = new AcDbBlockTableRecord();
pBlockTableRecord->setName(_T("GC200"));
pBlockTable->add(BlockTableRecordId,pBlockTableRecord);
AcGePoint3dArray vertices;
double elevation = 0,defStartWidth = 0.4,defEndWidth = 0.4;
AcGeDoubleArray *bulges = new AcGeDoubleArray;
vertices.append(AcGePoint3d(-0.2,0.0,0.0));
vertices.append(AcGePoint3d(0.2,0.0,0.0));
bulges->append(1.0);
bulges->append(1.0);
AcDb2dPolyline *pPoly = new AcDb2dPolyline(AcDb::k2dSimplePoly,vertices,elevation,Adesk::kTrue,defStartWidth,defEndWidth,bulges);
acad_free(bulges);

pPoly->setLayer(_T("0"));
pPoly->setColorIndex(256);
pPoly->setLinetype(lineTypeTableId);
pBlockTableRecord->appendAcDbEntity(pPoly);
pPoly->close();
pBlockTableRecord->close();
pBlockTable->downgradeOpen();
}

//创建GCD图层
es = pDb->getLayerTable(pLayerTable,AcDb::kForRead);
if (es != Acad::eOk)
{
pBlockTable->close();
return es;
}
if (pLayerTable->has(_T("GCD")))
{
pLayerTable->getAt(_T("GCD"),LayerTableRecordId);
pLayerTable->close();
else
{
es = pLayerTable->upgradeOpen();
if (es != Acad::eOk)
{
pLayerTable->close();
pBlockTable->close();
return es;
}
pLayerTableRecord = new AcDbLayerTableRecord;
pLayerTableRecord->setName(_T("GCD"));
AcCmColor color;
color.setColorIndex(7);
pLayerTableRecord->setColor(color);
pLayerTableRecord->setLinetypeObjectId(lineTypeTableId);
pLayerTable->add(LayerTableRecordId,pLayerTableRecord);
pLayerTableRecord->close();
pLayerTable->close();
}
//创建HZ字体
es = pDb->getTextStyleTable(pTextStyleTable,AcDb::kForRead);
if (es != Acad::eOk)
{
pBlockTable->close();
return es;
}
if (pTextStyleTable->has(_T("HZ")))
{
pTextStyleTable->getAt(_T("HZ"),TextStyleTableRecordId);
pTextStyleTable->close();
}
else
{
es = pTextStyleTable->upgradeOpen();
if (es != Acad::eOk)
{
pTextStyleTable->close();
pBlockTable->close();
return es;
}
pTextStyleTableRecord = new AcDbTextStyleTableRecord;
pTextStyleTableRecord->setName(_T("HZ"));
pTextStyleTableRecord->setBigFontFileName(_T("hztxt.shx"));
pTextStyleTableRecord->setFileName(_T("rs.shx"));
pTextStyleTableRecord->setTextSize(0);
pTextStyleTable->add(TextStyleTableRecordId,pTextStyleTableRecord);
pTextStyleTableRecord->close();
pTextStyleTable->close();

}
es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForWrite);
if (es != Acad::eOk)
{
pBlockTable->close();
return es;
}
//插入块
AcDbBlockReference *pBlockRef = new AcDbBlockReference(insPt,BlockTableRecordId);
pBlockRef->setLayer(LayerTableRecordId);
AcGeScale3d Scale3d(scale,scale,scale);
pBlockRef->setScaleFactors(Scale3d);
ads_point p1,p2;
ads_point_set(asDblArray(insPt),p1);
acutPolar(p1,0,scale * 1.2,p2);
ACHAR sText[40];
//保存系统变量dimzin
int dimzin ;
CSystem::GetSysVar(_T("DIMZIN"),dimzin);
CSystem::SetSysVar(_T("DIMZIN"),0);
if (g_Equal(height,-9999.0,1e-3))
{
acdbRToS(p1[Z],2,num,sText);
else
{
acdbRToS(height,2,num,sText);
}
//恢复系统变量dimzin
CSystem::SetSysVar(_T("DIMZIN"),dimzin);
AcDbAttribute *pAttribute = new AcDbAttribute(asPnt3d(p2),sText,_T("height"),TextStyleTableRecordId);
pAttribute->setHeight(2.0 * scale);
pAttribute->setWidthFactor(0.8);
pBlockRef->appendAttribute(pAttribute);

//创建扩展数据
struct resbuf *pRb;
pRb = acutBuildList(AcDb::kDxfRegAppName,_T("SOUTH"),AcDb::kDxfXdAsciiString,_T("202101"),RTNONE);
acdbRegApp(_T("SOUTH"));
pBlockRef->setXData(pRb);
acutRelRb(pRb);
//块添加到块表记录
es = pBlockTableRecord->appendAcDbEntity(objId,pBlockRef);
pAttribute->close();
pBlockRef->close();
pBlockTableRecord->close();
pBlockTable->close();
return es;
}

路过

雷人
5

握手

鲜花

鸡蛋

刚表态过的朋友 (5 人)

发表评论 评论 (1 个评论)

回复 测不准 2016-8-4 21:41
同行啊

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

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

GMT+8, 2024-4-29 02:57 , Processed in 0.182628 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部