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

news2024/9/20 22:55:32

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

  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 profile
    double 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);//声明形元素
    #endregion

    DPoint3d 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 dimension
    DPoint3d 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 column
    EllipseElement 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 BooleanSubtract
    Convert1.ElementToBody(out SolidKernelEntity entity1, beamSolid, true, false, false);//将实体转成SolidKernelEntity
    Convert1.ElementToBody(out SolidKernelEntity entity2, columnSolid, true, false, false);//将圆台实体元素转成SolidKernelEntity
    SolidKernelEntity[] entities = { entity2 };//声明实核实体集
    Modify.BooleanSubtract(ref entity1, ref entities, entities.Count());//用实核实体集中的实体与实体进行布尔减运算
    Convert1.BodyToElement(out Element resultElem, entity1, null, dgnModel);//将结果转换为元素
    #endregion

    #region Attach material
    MaterialId 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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1617350.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

小程序AI智能名片S2B2C商城系统:实现分销模式的四大要件深度解析

在当前的电商领域&#xff0c;小程序AI智能名片S2B2C商城系统正以其独特的分销模式&#xff0c;引领着行业创新的风潮。这种模式的成功&#xff0c;离不开四大核心要件&#xff1a;商品、机制、平台和运营。接下来&#xff0c;我们将对这四大要件进行深度解析。 首先&#xff0…

【LeetCode热题100】【多维动态规划】最小路径和

题目链接&#xff1a;64. 最小路径和 - 力扣&#xff08;LeetCode&#xff09; 给定一个包含非负整数的 m x n 网格 grid &#xff0c;请找出一条从左上角到右下角的路径&#xff0c;使得路径上的数字总和为最小。 说明&#xff1a;每次只能向下或者向右移动一步。 经典动态规…

2025年考研复习资料免费获取教程(内容持续更新)

文章目录 导文2025年政治考研复习资料获取2025年英语考研复习资料获取2025年英语一考研复习资料获取2025年英语二考研复习资料获取 2025年数学考研复习资料获取2025年数学一考研复习资料获取2025年数学二考研复习资料获取 导文 考研复习是每一位考研学子都必须经历的重要阶段&a…

重学java 19.面向对象 继承 上

走不出的那段阴霾&#xff0c;很多时候只不过是&#xff0c;我们把它当成了唯一 —— 24.4.22 面向对象整体知识导向&#xff1a; 知识梳理&#xff1a; 1.知道继承的好处 2.会使用继承 3.继承之后成员变量和成员方法的访问特点 4.方法的重写&#xff0c;知道方法重写的使用场景…

nginx配置https及wss

环境说明 服务器的是centos7 nginx版本nginx/1.20.1 springboot2.7.12 nginx安装教程点击这里 微信小程序wss配置 如果您的业务是开发微信小程序&#xff0c; 请先进行如下配置。 boot集成websocket maven <dependency><groupId>org.springframework.boot<…

【Elasticsearch】Elasticsearch 从入门到精通(一):基本介绍

《Elasticsearch 从入门到精通》共包含以下 2 2 2 篇文章&#xff1a; Elasticsearch 从入门到精通&#xff08;一&#xff09;&#xff1a;基本介绍Elasticsearch 从入门到精通&#xff08;二&#xff09;&#xff1a;基础使用 &#x1f60a; 如果您觉得这篇文章有用 ✔️ 的…

c语言应用,三子棋游戏设计

在c语言中&#xff0c;若是要实现三子棋游戏&#xff0c;需要我们对c语言的一维和二维数组的使用&#xff0c;函数的声明和调用&#xff0c;以及循环语句分支语句的结合等&#xff0c;这些知识的贯通。 首先&#xff0c;在设计游戏前我们要知道一下三子棋游戏的规则&#xff0…

NXopen c++快速分割体

通过对话框选择体以及分割该体的面&#xff0c;实现体的分割&#xff0c;相关资源请访问下载我的资源分享&#xff08;上传需要时间审核&#xff09; NXOpen::Session* theSession NXOpen::Session::GetSession();NXOpen::Part* workPart(theSession->Parts()->Work());…

【Linux学习】初始冯诺漫体系结构

文章目录 认识冯诺依曼系统 认识冯诺依曼系统 什么是冯诺依曼体系结构&#xff1f; 冯诺依曼体系结构是一种将程序指令和数据以二进制形式存放在主存储器中&#xff0c;由中央处理器统一控制和执行的计算机系统结构。冯诺依曼体系结构实现了程序的可编程性和硬件与软件的分离&…

mmdeploy框架转化模型

文章目录 1 从源码编译1.1 安装onnxruntime后端1.2 build mmdeploy1.3 install model converter 2 模型转换2.1 deploy用法2.2 示例 1 从源码编译 参考链接 reference2 git clone -b main https://github.com/open-mmlab/mmdeploy.git --recursive cd mmdeploy1.1 安装onnxru…

计算机缺少msvcp120.dll如何解决,7种详细的修复方法分享

msvcr120.dll文件是微软Visual C运行时库的一部分&#xff0c;版本号为12.0。这个DLL文件包含了许多用于支持在Windows上运行的应用程序的重要函数和组件。它是确保某些程序能够正确执行的关键组成部分&#xff0c;特别是那些使用C编写或依赖于某些Microsoft库的程序。 当用户…

C++ | Leetcode C++题解之第44题通配符匹配

题目&#xff1a; 题解&#xff1a; class Solution { public:bool isMatch(string s, string p) {auto allStars [](const string& str, int left, int right) {for (int i left; i < right; i) {if (str[i] ! *) {return false;}}return true;};auto charMatch []…

4月18号总结

java学习 网络编程 1.网络分层 网络分层是将网络通信划分为不同的逻辑层次&#xff0c;每一层负责特定的功能&#xff0c;从而实现网络通信的模块化和标准化。常用的网络分层模型包括OSI&#xff08;开放系统互联&#xff09;模型和TCP/IP模型。 特点和作用&#xff1a; 分…

(C++) 树状数组

目录 一、介绍 二、一维树状数组 2.1 区间长度 2.2 前驱和后继 2.3 查询前缀和 2.4 点更新 三、一维数组的实现 3.1 区间长度函数 3.2 前缀和 3.3 插入/更新 3.4 封装成类 一、介绍 树状数组&#xff08;Binary Indexed Tree&#xff0c;BIT&#xff09;&#xff0c;又称为 …

火绒安全概述

页面简介&#xff1a; 火绒安全是一款集多种安全功能于一体的国产软件&#xff0c;旨在为用户提供全面的计算机保护。本页面将详细介绍火绒安全的核心功能和使用方式。 页面内容概览&#xff1a; 杀毒防护 实时监控&#xff1a;详细介绍火绒安全如何实时检测系统中的文件和程序…

Pyside6:Spacer的使用,布局中控件顶格添加

在普通的布局&#xff0c;如水平或纵向布局中&#xff0c;我们的控件都会保持中间状态&#xff0c;如下&#xff1a; 但有许多情况下 &#xff0c;我们需要将控件布局为如下界面&#xff1a; 在前端开发时&#xff0c;我们很容易通过flex来进行布局&#xff0c;修正它的居中或者…

Github首页美化(updating)

Github首页美化 https://github.com/QInzhengk一、新建仓库二、美化Github首页主页访问量统计仓库状态统计常用语言占比统计社交链接 界面展示 https://github.com/QInzhengk 一、新建仓库 对Github首页进行美化&#xff0c;需要新建一个仓库名和自己 Github 用户名相同的仓库…

【数据库】三、数据库SQL语言命令(基础从入门到入土)

【全文两万多字&#xff0c;涵盖大部分常见情况&#xff0c;建议点赞收藏】 目录 文章目录 目录安装SQL语言1.使用2.DATABASE查看所有库新建数据库修改数据库删除数据库连接数据库 3.TABLE创建表查看库所有表删除表查看表信息重命名表修改表字段&#xff08;列&#xff09;表中…

Java---ideaIU-2023.1专业版使用以及安装方法

介绍 JetBrains 是一家专注于创建智能开发工具的前沿软件公司,包括:行业中领头的 Java IDE – IntelliJ IDEA,以及 Kotlin 编程语言。旗下常用的软件有IntelliJ IDEA、PhpStorm、RubyMine、Rider、WebStorm、goland、CLion、Pycharm&#xff0c;本安装包集成以上8款软件&#…

最大层内元素和

题目链接 最大层内元素和 题目描述 注意点 返回层内元素之和 最大 的那几层&#xff08;可能只有一层&#xff09;的层号&#xff0c;并返回其中 最小 的那个树中的节点数在 [1, 10000]范围内-10^5 < Node.val < 10^5 解答思路 广度优先遍历树&#xff0c;使用队列存…