Bentley二次开发教程16-元素管理-巩固练习

2024-04-23 13:04

本文主要是介绍Bentley二次开发教程16-元素管理-巩固练习,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

该练习中的方法涉及到前两期的方法,主要步骤为:

  1. 使用拉伸实体功能创建梁与圆柱并进行变换
  2. 对梁截面进行标注并进行变换
  3. 对梁与圆柱执行布尔运算
  4. 对实体进行材质附加
public static void CmdPracticeWork(string unparsed)
{DgnFile dgnFile = Session.Instance.GetActiveDgnFile();//获得当前激活的文件DgnModel dgnModel = Session.Instance.GetActiveDgnModel();//获取当前的模型空间double uorPerMeter = Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMeter;//分辨率单位转换为米#region Create beam#region Create profiledouble H = 700 * uorPerMeter/1000;double H1 = 125 * uorPerMeter / 1000, H2 = 125 * uorPerMeter / 1000;double H3 = 275 * uorPerMeter / 1000;double H4 = 75 * uorPerMeter / 1000, B4 = 75 * uorPerMeter / 1000;double H5 = 100 * uorPerMeter / 1000;double B3 = 125 * uorPerMeter / 1000;double B1 = 400 * uorPerMeter / 1000;double B2 = 300 * uorPerMeter / 1000;double B = 150 * uorPerMeter / 1000;DPoint3d p1 = new DPoint3d(-1 * 0.5 * B1, 0, 0);//声明体元素端点DPoint3d p2 = new DPoint3d(-1 * 0.5 * B1, 0, H2);DPoint3d p3 = new DPoint3d(-0.5 * B, 0, H2 + H5);DPoint3d p4 = new DPoint3d(-0.5 * B, 0, H2 + H5 + H3);DPoint3d p5 = new DPoint3d(-0.5 * B2, 0, H2 + H5 + H3 + H4);DPoint3d p6 = new DPoint3d(-0.5 * B2, 0, H);DPoint3d p7 = new DPoint3d(0.5 * B2, 0, H);DPoint3d p8 = new DPoint3d(0.5 * B2, 0, H2 + H5 + H3 + H4);DPoint3d p9 = new DPoint3d(0.5 * B, 0, H2 + H5 + H3);DPoint3d p10 = new DPoint3d(0.5 * B, 0, H2 + H5);DPoint3d p11 = new DPoint3d(0.5 * B1, 0, H2);DPoint3d p12 = new DPoint3d(0.5 * B1, 0, 0);DPoint3d[] pos = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12 };//将面元素端点添加到面元素端点数组中ShapeElement shape = new ShapeElement(dgnModel, null, pos);//声明形元素#endregionDPoint3d origin = DPoint3d.Zero;//声明拉伸基点DVector3d extrudeVector = new DVector3d(0, 12 * uorPerMeter, 0);//声明拉伸向量SurfaceOrSolidElement beamSolid = SurfaceOrSolidElement.CreateProjectionElement(dgnModel, null, shape, origin, extrudeVector, DTransform3d.Identity, true);//使用投影的方式声明拉伸体元素            #endregion#region Create dimensionDPoint3d d1 = new DPoint3d(-0.5 * B1, 0, -50 * uorPerMeter / 1000);//声明标注点DPoint3d d2 = new DPoint3d(0.5 * B1, 0, -50 * uorPerMeter / 1000);//声明标注点DPoint3d[] dimensionPos1 = { d1, d2 };//声明标注点数组DMatrix3d dMatrix1 = new DMatrix3d(-1, 0, 0, 0, 0, 1, 0, -1, 0);//声明变换矩阵DimensionElement dimEle1 = CreateDimensionElement(dgnFile, dgnModel, dimensionPos1, string.Empty, dMatrix1);//声明标注元素dimEle1.AddToModel();//将标注元素写入模型DPoint3d d3 = new DPoint3d(-0.5 * B1, 0, -10 * uorPerMeter / 1000);DPoint3d d4 = new DPoint3d(-0.5 * B, 0, -10 * uorPerMeter / 1000);DPoint3d d5 = new DPoint3d(0.5 * B, 0, -10 * uorPerMeter / 1000);DPoint3d d6 = new DPoint3d(0.5 * B1, 0, -10 * uorPerMeter / 1000);DPoint3d[] dimensionPos2 = { d3, d4, d5, d6 };DimensionElement dimEle2 = CreateDimensionElement(dgnFile, dgnModel, dimensionPos2, string.Empty, dMatrix1);dimEle2.AddToModel();//将标注元素写入模型DMatrix3d dMatrix2 = DMatrix3d.FromRows(new DVector3d(0, 1, 0), new DVector3d(-1, 0, 0), new DVector3d(0, 0, 1));DMatrix3d dMatrix = DMatrix3d.Multiply(dMatrix1, dMatrix2);DPoint3d d7 = new DPoint3d(-0.5 * B1 - 50 * uorPerMeter / 1000, 0, 0);DPoint3d d8 = new DPoint3d(-0.5 * B1 - 50 * uorPerMeter / 1000, 0, H);DPoint3d[] dimensionPos3 = { d7, d8 };DimensionElement dimEle3 = CreateDimensionElement(dgnFile, dgnModel, dimensionPos3, string.Empty, dMatrix);dimEle3.AddToModel();//将标注元素写入模型DPoint3d d9 = new DPoint3d(-0.5 * B1 - 10 * uorPerMeter / 1000, 0, 0);DPoint3d d10 = new DPoint3d(-0.5 * B1 - 10 * uorPerMeter / 1000, 0, H2);DPoint3d d11 = new DPoint3d(-0.5 * B1 - 10 * uorPerMeter / 1000, 0, H2 + H5);DPoint3d d12 = new DPoint3d(-0.5 * B1 - 10 * uorPerMeter / 1000, 0, H2 + H5 + H3);DPoint3d d13 = new DPoint3d(-0.5 * B1 - 10 * uorPerMeter / 1000, 0, H2 + H5 + H3 + H4);DPoint3d d14 = new DPoint3d(-0.5 * B1 - 10 * uorPerMeter / 1000, 0, H);DPoint3d[] dimensionPos4 = { d9, d10, d11, d12, d13, d14 };DimensionElement dimEle4 = CreateDimensionElement(dgnFile, dgnModel, dimensionPos4, string.Empty, dMatrix);dimEle4.AddToModel();//将标注元素写入模型#endregion#region Create columnEllipseElement ellipse = new EllipseElement(dgnModel,null, DPoint3d.Zero,350*uorPerMeter/1000, 350 * uorPerMeter / 1000,DMatrix3d.Identity);DVector3d columnVector = new DVector3d(0, 0, 3 * uorPerMeter);//声明拉伸向量SurfaceOrSolidElement columnSolid = SurfaceOrSolidElement.CreateProjectionElement(dgnModel, null, ellipse, DPoint3d.Zero, columnVector, DTransform3d.Identity, true);//使用投影的方式声明拉伸体元素            DTransform3d dTransform3D= DTransform3d.FromTranslation(new DPoint3d(0,12*uorPerMeter,-1*uorPerMeter));//声明变换几何,执行元素平移操作TransformInfo trans = new TransformInfo(dTransform3D);//声明变换信息columnSolid.ApplyTransform(trans);//对拉伸圆柱体施加变换信息#endregion#region BooleanSubtractConvert1.ElementToBody(out SolidKernelEntity entity1, beamSolid, true, false, false);//将实体转成SolidKernelEntityConvert1.ElementToBody(out SolidKernelEntity entity2, columnSolid, true, false, false);//将圆台实体元素转成SolidKernelEntitySolidKernelEntity[] entities = { entity2 };//声明实核实体集Modify.BooleanSubtract(ref entity1, ref entities, entities.Count());//用实核实体集中的实体与实体进行布尔减运算Convert1.BodyToElement(out Element resultElem, entity1, null, dgnModel);//将结果转换为元素#endregion#region Attach materialMaterialId id = FindMaterial(dgnFile, dgnModel);AttachMaterialToElement(id, resultElem);AttachMaterialToElement(id, columnSolid);#endregion
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
代码中用到的几个方法:

private static void AttachMaterialToElement(MaterialId id, Element elem)
{            if (id != null){MaterialPropertiesExtension propertiesExtension = MaterialPropertiesExtension.GetAsMaterialPropertiesExtension((DisplayableElement)elem);//为拉伸实体元素设置材料属性            propertiesExtension.AddMaterialAttachment(id);//添加嵌入的材料信息propertiesExtension.StoresAttachmentInfo(id);//保存拉伸实体元素的材料信息           propertiesExtension.AddToModel();//将拉伸实体写入模型}
}private static MaterialId FindMaterial(DgnFile dgnFile, DgnModel dgnModel)
{MaterialTable matTbl = new MaterialTable(dgnFile);//声明材料表matTbl.Name = "MyMaterialTable";//声明材料表名称PaletteInfo[] palInfo = MaterialManager.GetPalettesInSearchPath("MS_MATERIAL");//从MS_MATERIAL的环境变量声明路径下读取材料图表if (palInfo.Length < 1)//判断是否获取到材料图表{MessageCenter.Instance.ShowInfoMessage("Can't get palette", null, true);//输出错误信息return null;//返回}for (int i = 0; i < palInfo.Count(); i++)//遍历材料图表{if (palInfo[i].Name == "Concrete&Pavers")//判断材料图表是否名为Concrete&Pavers{matTbl.AddPalette(palInfo[i]);//添加材料图表至材料表break;//跳出循环}else if (i == palInfo.Count() - 1)//若未找到名为lightwidgets的材料图表{MessageCenter.Instance.ShowErrorMessage("Can't find material lib named lightwidgets, please check","Can't find material lib named lightwidgets, please check",true);//输出错误信息}}MaterialManager.SetActiveTable(matTbl, dgnModel);//设置当前材料表为激活图表MaterialManager.SaveTable(matTbl);//保存材料表MaterialId id = new MaterialId("Concrete_1");//查找名为Concrete_1的材料return id;
}

这篇关于Bentley二次开发教程16-元素管理-巩固练习的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/928870

相关文章

JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)

《JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)》:本文主要介绍如何在IntelliJIDEA2020.1中创建和部署一个JavaWeb项目,包括创建项目、配置Tomcat服务... 目录简介:一、创建项目二、tomcat部署1、将tomcat解压在一个自己找得到路径2、在idea中添加

Python + Streamlit项目部署方案超详细教程(非Docker版)

《Python+Streamlit项目部署方案超详细教程(非Docker版)》Streamlit是一款强大的Python框架,专为机器学习及数据可视化打造,:本文主要介绍Python+St... 目录一、针对 Alibaba Cloud linux/Centos 系统的完整部署方案1. 服务器基础配置(阿里

Spring IOC核心原理详解与运用实战教程

《SpringIOC核心原理详解与运用实战教程》本文详细解析了SpringIOC容器的核心原理,包括BeanFactory体系、依赖注入机制、循环依赖解决和三级缓存机制,同时,介绍了SpringBo... 目录1. Spring IOC核心原理深度解析1.1 BeanFactory体系与内部结构1.1.1

SpringBoot集成iText快速生成PDF教程

《SpringBoot集成iText快速生成PDF教程》本文介绍了如何在SpringBoot项目中集成iText9.4.0生成PDF文档,包括新特性的介绍、环境准备、Service层实现、Contro... 目录SpringBoot集成iText 9.4.0生成PDF一、iText 9新特性与架构变革二、环

2025最新版Android Studio安装及组件配置教程(SDK、JDK、Gradle)

《2025最新版AndroidStudio安装及组件配置教程(SDK、JDK、Gradle)》:本文主要介绍2025最新版AndroidStudio安装及组件配置(SDK、JDK、Gradle... 目录原生 android 简介Android Studio必备组件一、Android Studio安装二、A

前端Visual Studio Code安装配置教程之下载、汉化、常用组件及基本操作

《前端VisualStudioCode安装配置教程之下载、汉化、常用组件及基本操作》VisualStudioCode是微软推出的一个强大的代码编辑器,功能强大,操作简单便捷,还有着良好的用户界面,... 目录一、Visual Studio Code下载二、汉化三、常用组件1、Auto Rename Tag2

JavaScript装饰器从基础到实战教程

《JavaScript装饰器从基础到实战教程》装饰器是js中一种声明式语法特性,用于在不修改原始代码的情况下,动态扩展类、方法、属性或参数的行为,本文将从基础概念入手,逐步讲解装饰器的类型、用法、进阶... 目录一、装饰器基础概念1.1 什么是装饰器?1.2 装饰器的语法1.3 装饰器的执行时机二、装饰器的

MySQL 5.7彻底卸载与重新安装保姆级教程(附常见问题解决)

《MySQL5.7彻底卸载与重新安装保姆级教程(附常见问题解决)》:本文主要介绍MySQL5.7彻底卸载与重新安装保姆级教程的相关资料,步骤包括停止服务、卸载程序、删除文件和注册表项、清理环境... 目录一、彻底卸载旧版本mysql(核心步骤)二、MySQL 5.7重新安装与配置三、常见问题解决总结废话不多

Elasticsearch 的索引管理与映射配置实战指南

《Elasticsearch的索引管理与映射配置实战指南》在本文中,我们深入探讨了Elasticsearch中索引与映射的基本概念及其重要性,通过详细的操作示例,我们了解了如何创建、更新和删除索引,... 目录一、索引操作(一)创建索引(二)删除索引(三)关闭索引(四)打开索引(五)索引别名二、映射操作(一

Linux创建服务使用systemctl管理详解

《Linux创建服务使用systemctl管理详解》文章指导在Linux中创建systemd服务,设置文件权限为所有者读写、其他只读,重新加载配置,启动服务并检查状态,确保服务正常运行,关键步骤包括权... 目录创建服务 /usr/lib/systemd/system/设置服务文件权限:所有者读写js,其他