概述
盖梁是桥梁中常见的构件。在不同项目中,随着跨径、桥宽、桥梁类型不一样,盖梁类型多种多样,有标准的,也有非标标的。因此,设计过程中也经常需要画盖梁图。然而,画盖梁图技术含量不高,显得比较繁琐,通过二次开发的方式用命令快速生成显得非常必要。本文将用ARX的方式来实现盖梁生成。
原理
ARX是所有CAD开发方式中最直接也是最强大的一种,效率最高,可以编辑实体。不过,这种方式用到的语言为C++,不仅这门语言本身难度较大,搭建开发环境也比较复杂,CAD版本、ARX版本、VS编辑器版本间匹配比较苛刻。
本文开发示例开发环境采用CAD2014+ARX2014+VS2010,搭建过程可参考网上其他相关博文。
盖梁绘制过程:1. 先输入盖梁长、高,倒角长、高,柱间距、柱径、桩径等;2. 计算控制点位置;3. 绘制轮廓线。
代码
static void comdMyGroupCreateCapBeam ()
{
int beamLenght=300;
int beamHeight=80;
int chamferAngleLenght=25;
int chamferAngleHeight=40;
int columnDistance=130;
int columnHeight=200;
int pierLength=250;
int columnRadius=25;
int pierRadius=40;
AcGePoint3d ptLeft1(-beamLenght/2,0,0);
AcGePoint3d ptLeft2(-beamLenght/2,-beamHeight+chamferAngleHeight,0);
AcGePoint3d ptLeft3(-beamLenght/2+chamferAngleLenght,-beamHeight,0);
AcGePoint3d ptLeft4(-columnDistance/2-columnRadius,-beamHeight,0);
AcGePoint3d ptLeft5(-columnDistance/2-columnRadius,-beamHeight-columnHeight,0);
AcGePoint3d ptLeft6(-columnDistance/2-pierRadius,-beamHeight-columnHeight,0);
AcGePoint3d ptLeft7(-columnDistance/2-pierRadius,-beamHeight-columnHeight-pierLength,0);
AcGePoint3d ptInterLeft4(-columnDistance/2+columnRadius,-beamHeight,0);
AcGePoint3d ptInterLeft5(-columnDistance/2+columnRadius,-beamHeight-columnHeight,0);
AcGePoint3d ptInterLeft6(-columnDistance/2+pierRadius,-beamHeight-columnHeight,0);
AcGePoint3d ptInterLeft7(-columnDistance/2+pierRadius,-beamHeight-columnHeight-pierLength,0);
AcGePoint3d ptRight1(beamLenght/2,0,0);
AcGePoint3d ptRight2(beamLenght/2,-beamHeight+chamferAngleHeight,0);
AcGePoint3d ptRight3(beamLenght/2-chamferAngleLenght,-beamHeight,0);
AcGePoint3d ptRight4(columnDistance/2+columnRadius,-beamHeight,0);
AcGePoint3d ptRight5(columnDistance/2+columnRadius,-beamHeight-columnHeight,0);
AcGePoint3d ptRight6(columnDistance/2+pierRadius,-beamHeight-columnHeight,0);
AcGePoint3d ptRight7(columnDistance/2+pierRadius,-beamHeight-columnHeight-pierLength,0);
AcGePoint3d ptInterRight4(columnDistance/2-columnRadius,-beamHeight,0);
AcGePoint3d ptInterRight5(columnDistance/2-columnRadius,-beamHeight-columnHeight,0);
AcGePoint3d ptInterRight6(columnDistance/2-pierRadius,-beamHeight-columnHeight,0);
AcGePoint3d ptInterRight7(columnDistance/2-pierRadius,-beamHeight-columnHeight-pierLength,0);
AcDbLine *pLeft1=new AcDbLine(ptLeft1,ptLeft2);
AcDbLine *pLeft2=new AcDbLine(ptLeft2,ptLeft3);
AcDbLine *pLeft3=new AcDbLine(ptLeft4,ptLeft5);
AcDbLine *pLeft4=new AcDbLine(ptLeft6,ptLeft7);
AcDbLine *pInterLeft3=new AcDbLine(ptInterLeft4,ptInterLeft5);
AcDbLine *pInterLeft4=new AcDbLine(ptInterLeft6,ptInterLeft7);
AcDbLine *pRight1=new AcDbLine(ptRight1,ptRight2);
AcDbLine *pRight2=new AcDbLine(ptRight2,ptRight3);
AcDbLine *pRight3=new AcDbLine(ptRight4,ptRight5);
AcDbLine *pRight4=new AcDbLine(ptRight6,ptRight7);
AcDbLine *pInterRight3=new AcDbLine(ptInterRight4,ptInterRight5);
AcDbLine *pInterRight4=new AcDbLine(ptInterRight6,ptInterRight7);
AcDbLine *pHorizontal1=new AcDbLine(ptLeft1,ptRight1);
AcDbLine *pHorizontal2=new AcDbLine(ptLeft3,ptRight3);
AcDbLine *pHorizontal3=new AcDbLine(ptLeft6,ptInterLeft6);
AcDbLine *pHorizontal4=new AcDbLine(ptLeft7,ptInterLeft7);
AcDbLine *pHorizontal5=new AcDbLine(ptInterRight6,ptRight6);
AcDbLine *pHorizontal6=new AcDbLine(ptInterRight7,ptRight7);
addToBlockTableRecord(pLeft1);
addToBlockTableRecord(pLeft2);
addToBlockTableRecord(pLeft3);
addToBlockTableRecord(pLeft4);
addToBlockTableRecord(pInterLeft3);
addToBlockTableRecord(pInterLeft4);
addToBlockTableRecord(pRight1);
addToBlockTableRecord(pRight2);
addToBlockTableRecord(pRight3);
addToBlockTableRecord(pRight4);
addToBlockTableRecord(pInterRight3);
addToBlockTableRecord(pInterRight4);
addToBlockTableRecord(pHorizontal1);
addToBlockTableRecord(pHorizontal2);
addToBlockTableRecord(pHorizontal3);
addToBlockTableRecord(pHorizontal4);
addToBlockTableRecord(pHorizontal5);
addToBlockTableRecord(pHorizontal6);
}
static void addToBlockTableRecord(AcDbEntity *pLine)
{
AcDbBlockTable *pBlockTable;//声明只想块表的指针
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead);//获取快编织针
AcDbBlockTableRecord *pBlockTableRecord;//声明一个块表记录区的指针
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);//将空间模型区域的记录地址赋给上声明的变量 模式为写
AcDbObjectId lineld;//声明ID
pBlockTableRecord->appendAcDbEntity(lineld,pLine);//将ID与实体传入
pBlockTable->close();
pBlockTableRecord->close();
pLine->close();
}
ACED_ARXCOMMAND_ENTRY_AUTO(CmyProjectApp, comdMyGroup, CreateCapBeam, CreateCapBeam, ACRX_CMD_MODAL, NULL)//启动命令为“CreateCapBeam”
其中,comdMyGroupCreateCapBeam ()是生成盖梁的方法,addToBlockTableRecord(AcDbEntity *pLine)是将实体添加到模型空间方法,ACED_ARXCOMMAND_ENTRY_AUTO的作用则是添加命令。myProject是本示例的项目名称,如果项目名称调整时,ACED_ARXCOMMAND_ENTRY_AUTO的第一个参数相应调整。
生成效果
一个简单的盖梁就生成了,后续可以根据需要再增加标注、设置颜色、俯视图、侧面图、标题、下划线、文字说明、图框等。