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

相关文章

gradle第三方Jar包依赖统一管理方式

《gradle第三方Jar包依赖统一管理方式》:本文主要介绍gradle第三方Jar包依赖统一管理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录背景实现1.顶层模块build.gradle添加依赖管理插件2.顶层模块build.gradle添加所有管理依赖包

基于Python打造一个智能单词管理神器

《基于Python打造一个智能单词管理神器》这篇文章主要为大家详细介绍了如何使用Python打造一个智能单词管理神器,从查询到导出的一站式解决,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 项目概述:为什么需要这个工具2. 环境搭建与快速入门2.1 环境要求2.2 首次运行配置3. 核心功能使用指

springboot使用Scheduling实现动态增删启停定时任务教程

《springboot使用Scheduling实现动态增删启停定时任务教程》:本文主要介绍springboot使用Scheduling实现动态增删启停定时任务教程,具有很好的参考价值,希望对大家有... 目录1、配置定时任务需要的线程池2、创建ScheduledFuture的包装类3、注册定时任务,增加、删

如何为Yarn配置国内源的详细教程

《如何为Yarn配置国内源的详细教程》在使用Yarn进行项目开发时,由于网络原因,直接使用官方源可能会导致下载速度慢或连接失败,配置国内源可以显著提高包的下载速度和稳定性,本文将详细介绍如何为Yarn... 目录一、查询当前使用的镜像源二、设置国内源1. 设置为淘宝镜像源2. 设置为其他国内源三、还原为官方

Maven的使用和配置国内源的保姆级教程

《Maven的使用和配置国内源的保姆级教程》Maven是⼀个项目管理工具,基于POM(ProjectObjectModel,项目对象模型)的概念,Maven可以通过一小段描述信息来管理项目的构建,报告... 目录1. 什么是Maven?2.创建⼀个Maven项目3.Maven 核心功能4.使用Maven H

HTML5中的Microdata与历史记录管理详解

《HTML5中的Microdata与历史记录管理详解》Microdata作为HTML5新增的一个特性,它允许开发者在HTML文档中添加更多的语义信息,以便于搜索引擎和浏览器更好地理解页面内容,本文将探... 目录html5中的Mijscrodata与历史记录管理背景简介html5中的Microdata使用M

Spring 基于XML配置 bean管理 Bean-IOC的方法

《Spring基于XML配置bean管理Bean-IOC的方法》:本文主要介绍Spring基于XML配置bean管理Bean-IOC的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一... 目录一. spring学习的核心内容二. 基于 XML 配置 bean1. 通过类型来获取 bean2. 通过

IDEA自动生成注释模板的配置教程

《IDEA自动生成注释模板的配置教程》本文介绍了如何在IntelliJIDEA中配置类和方法的注释模板,包括自动生成项目名称、包名、日期和时间等内容,以及如何定制参数和返回值的注释格式,需要的朋友可以... 目录项目场景配置方法类注释模板定义类开头的注释步骤类注释效果方法注释模板定义方法开头的注释步骤方法注

python uv包管理小结

《pythonuv包管理小结》uv是一个高性能的Python包管理工具,它不仅能够高效地处理包管理和依赖解析,还提供了对Python版本管理的支持,本文主要介绍了pythonuv包管理小结,具有一... 目录安装 uv使用 uv 管理 python 版本安装指定版本的 Python查看已安装的 Python

Python虚拟环境终极(含PyCharm的使用教程)

《Python虚拟环境终极(含PyCharm的使用教程)》:本文主要介绍Python虚拟环境终极(含PyCharm的使用教程),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录一、为什么需要虚拟环境?二、虚拟环境创建方式对比三、命令行创建虚拟环境(venv)3.1 基础命令3