(Tekla Structures二次开发)分享官方示例DimensionCreator

本文主要是介绍(Tekla Structures二次开发)分享官方示例DimensionCreator,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

分享一个Tekla官方的示例DimensionCreator,首先在vs中新建项目,添加引用文件,新建控件如下图所示:
窗口样式
控件名称如下代码所示:

        private System.Windows.Forms.Button angleDimensionButton;private System.Windows.Forms.Button radiusDimensionButton;private System.Windows.Forms.Button straightDimensionButton;private System.Windows.Forms.Button curvedRadialDimensionButton;private System.Windows.Forms.Button curvedOrthogonalDimensionButton;private System.Windows.Forms.CheckBox repeatCheckBox;private System.Windows.Forms.NumericUpDown distanceNumericUpDown;private System.Windows.Forms.Label distanceLabel;private System.Windows.Forms.NumericUpDown numberOfPointsToPickNumericUpDown;private System.Windows.Forms.Label numberOfPointsToPickLabel;private System.Windows.Forms.GroupBox groupBox1;private System.Windows.Forms.GroupBox groupBox2;private System.Windows.Forms.GroupBox groupBox3;private System.Windows.Forms.Button quitButton;

添加类,代码如下:

using System;
using Tekla.Structures.Drawing;
using Tekla.Structures.Geometry3d;
using Tekla.Structures.Drawing.UI;namespace DimensionCreator
{class DimensionCreator{private static readonly PointList lastPoints = new PointList();private static ViewBase lastView;public static bool Repeat = false;public static int Points = 3;static void PickPoints(int numberToPick, ref PointList pointList, ref ViewBase view){if(Repeat){view = lastView;foreach (Point pointt in lastPoints){pointList.Add(new Point(pointt));}return;}var picker = new DrawingHandler().GetPicker();int ii = numberToPick;lastPoints.Clear();while(--ii!=-1){Point point;picker.PickPoint("Pick point", out point, out view);pointList.Add(point);lastPoints.Add(new Point(point));}lastView = view;}public static void CreateAngleDimension(){PointList pointList = new PointList();ViewBase view = null;PickPoints(3, ref pointList, ref view);double distance = Math.Sqrt(new Vector(pointList[1] - pointList[0]).Dot(new Vector(pointList[1] - pointList[0])));double viewScale = 1.0;if (view is View)viewScale = (view as View).Attributes.Scale;distance = distance / viewScale;AngleDimension ad = new AngleDimension(view, pointList[0], pointList[1], pointList[2], distance);ad.Insert();new DrawingHandler().GetActiveDrawing().CommitChanges();}internal static void CreateRadiunDimension(double distance){PointList pointList = new PointList();ViewBase view = null;PickPoints(3, ref pointList, ref view);RadiusDimension rd = new RadiusDimension(view, pointList[0], pointList[1], pointList[2], distance);rd.Insert();new DrawingHandler().GetActiveDrawing().CommitChanges();}internal static void CreateStraightDimension(double distance){PointList pointList = new PointList();ViewBase view;Point firstPoint;Point secondPoint;Picker picker = new DrawingHandler().GetPicker();picker.PickTwoPoints("Pick first point", "Pick second point", out firstPoint, out secondPoint, out view);pointList.Add(firstPoint);pointList.Add(secondPoint);//获取与第一点,第二点连线方向垂直的向量Vector direction = new Vector(firstPoint.Y - secondPoint.Y, secondPoint.X - firstPoint.X, firstPoint.Z);StraightDimensionSet sds = new StraightDimensionSetHandler().CreateDimensionSet(view, pointList, direction, distance);//至少一点与零件关联,否则标记不起作用sds.Attributes.LeftLowerTag.Add(new TextElement("LeftLow"));sds.Attributes.LeftMiddleTag.Add(new TextElement("LeftMiddle"));sds.Attributes.LeftUpperTag.Add(new TextElement("LeftUpper"));sds.Attributes.RightLowerTag.Add(new TextElement("RightLow"));sds.Attributes.RightMiddleTag.Add(new TextElement("RightMiddle"));sds.Attributes.RightUpperTag.Add(new TextElement("RightUpper"));bool isOk = sds.Modify();new DrawingHandler().GetActiveDrawing().CommitChanges();}//弯曲尺寸(增加直角参考线)internal static void CreateCurvedOrthoDimension(double distance){PointList pointList = new PointList();ViewBase view = null;PickPoints(Points, ref pointList, ref view);new CurvedDimensionSetHandler().CreateCurvedDimensionSetOrthogonal(view, pointList[0], pointList[1],pointList[pointList.Count-1], pointList, distance);new DrawingHandler().GetActiveDrawing().CommitChanges();}//弯曲尺寸(增加半径参考线)internal static void CreateCurvedRadialDimension(double distance){PointList pointList = new PointList();ViewBase view = null;PickPoints(3, ref pointList, ref view);new CurvedDimensionSetHandler().CreateCurvedDimensionSetRadial(view, pointList[0], pointList[1], pointList[2],pointList, distance);new DrawingHandler().GetActiveDrawing().CommitChanges();}}
}

窗体控件操作代码如下:

using System;
using System.Windows.Forms;namespace DimensionCreator
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void angleDimensionButton_Click(object sender, EventArgs e){try { DimensionCreator.CreateAngleDimension(); }catch (Exception) { }}private void radiusDimensionButton_Click(object sender, EventArgs e){try { DimensionCreator.CreateRadiunDimension((double)this.distanceNumericUpDown.Value); }catch (Exception) { }}private void straightDimensionButton_Click(object sender, EventArgs e){try { DimensionCreator.CreateStraightDimension((double)this.distanceNumericUpDown.Value); }catch (Exception) { }}private void curvedRadialDimensionButton_Click(object sender, EventArgs e){try { DimensionCreator.CreateCurvedRadialDimension((double)this.distanceNumericUpDown.Value); }catch { }}private void curvedOrthogonalDimensionButton_Click(object sender, EventArgs e){try { DimensionCreator.CreateCurvedOrthoDimension((double)this.distanceNumericUpDown.Value); }catch (Exception) { }}private void repeatCheckBox_CheckedChanged(object sender, EventArgs e){DimensionCreator.Repeat = !DimensionCreator.Repeat;}private void numberOfPointsToPickNumericUpDown_ValueChanged(object sender, EventArgs e){DimensionCreator.Points = (int)this.numberOfPointsToPickNumericUpDown.Value;}}
}

说明:
半径标注与value框中的值无关,其余四个会受到distance值的影响。
其中“弯曲尺寸(增加直角参考线)”拾取点的数量会受到NumberOfPoint影响。

关于Option中Repeat的作用:使用除“直尺寸标注”外的四个标注中任一标注完后,勾选Repeat,另外三个不会再拾取点,而是使用第一个已经拾取的点进行标注。

这篇关于(Tekla Structures二次开发)分享官方示例DimensionCreator的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

SpringBoot中SM2公钥加密、私钥解密的实现示例详解

《SpringBoot中SM2公钥加密、私钥解密的实现示例详解》本文介绍了如何在SpringBoot项目中实现SM2公钥加密和私钥解密的功能,通过使用Hutool库和BouncyCastle依赖,简化... 目录一、前言1、加密信息(示例)2、加密结果(示例)二、实现代码1、yml文件配置2、创建SM2工具

MySQL 定时新增分区的实现示例

《MySQL定时新增分区的实现示例》本文主要介绍了通过存储过程和定时任务实现MySQL分区的自动创建,解决大数据量下手动维护的繁琐问题,具有一定的参考价值,感兴趣的可以了解一下... mysql创建好分区之后,有时候会需要自动创建分区。比如,一些表数据量非常大,有些数据是热点数据,按照日期分区MululbU

Python中你不知道的gzip高级用法分享

《Python中你不知道的gzip高级用法分享》在当今大数据时代,数据存储和传输成本已成为每个开发者必须考虑的问题,Python内置的gzip模块提供了一种简单高效的解决方案,下面小编就来和大家详细讲... 目录前言:为什么数据压缩如此重要1. gzip 模块基础介绍2. 基本压缩与解压缩操作2.1 压缩文

Python函数作用域示例详解

《Python函数作用域示例详解》本文介绍了Python中的LEGB作用域规则,详细解析了变量查找的四个层级,通过具体代码示例,展示了各层级的变量访问规则和特性,对python函数作用域相关知识感兴趣... 目录一、LEGB 规则二、作用域实例2.1 局部作用域(Local)2.2 闭包作用域(Enclos

C++20管道运算符的实现示例

《C++20管道运算符的实现示例》本文简要介绍C++20管道运算符的使用与实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录标准库的管道运算符使用自己实现类似的管道运算符我们不打算介绍太多,因为它实际属于c++20最为重要的

Java中调用数据库存储过程的示例代码

《Java中调用数据库存储过程的示例代码》本文介绍Java通过JDBC调用数据库存储过程的方法,涵盖参数类型、执行步骤及数据库差异,需注意异常处理与资源管理,以优化性能并实现复杂业务逻辑,感兴趣的朋友... 目录一、存储过程概述二、Java调用存储过程的基本javascript步骤三、Java调用存储过程示

ModelMapper基本使用和常见场景示例详解

《ModelMapper基本使用和常见场景示例详解》ModelMapper是Java对象映射库,支持自动映射、自定义规则、集合转换及高级配置(如匹配策略、转换器),可集成SpringBoot,减少样板... 目录1. 添加依赖2. 基本用法示例:简单对象映射3. 自定义映射规则4. 集合映射5. 高级配置匹

C++11作用域枚举(Scoped Enums)的实现示例

《C++11作用域枚举(ScopedEnums)的实现示例》枚举类型是一种非常实用的工具,C++11标准引入了作用域枚举,也称为强类型枚举,本文主要介绍了C++11作用域枚举(ScopedEnums... 目录一、引言二、传统枚举类型的局限性2.1 命名空间污染2.2 整型提升问题2.3 类型转换问题三、C

Java实现自定义table宽高的示例代码

《Java实现自定义table宽高的示例代码》在桌面应用、管理系统乃至报表工具中,表格(JTable)作为最常用的数据展示组件,不仅承载对数据的增删改查,还需要配合布局与视觉需求,而JavaSwing... 目录一、项目背景详细介绍二、项目需求详细介绍三、相关技术详细介绍四、实现思路详细介绍五、完整实现代码

Go语言代码格式化的技巧分享

《Go语言代码格式化的技巧分享》在Go语言的开发过程中,代码格式化是一个看似细微却至关重要的环节,良好的代码格式化不仅能提升代码的可读性,还能促进团队协作,减少因代码风格差异引发的问题,Go在代码格式... 目录一、Go 语言代码格式化的重要性二、Go 语言代码格式化工具:gofmt 与 go fmt(一)