(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

相关文章

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

在 Spring Boot 中使用 @Autowired和 @Bean注解的示例详解

《在SpringBoot中使用@Autowired和@Bean注解的示例详解》本文通过一个示例演示了如何在SpringBoot中使用@Autowired和@Bean注解进行依赖注入和Bean... 目录在 Spring Boot 中使用 @Autowired 和 @Bean 注解示例背景1. 定义 Stud

oracle DBMS_SQL.PARSE的使用方法和示例

《oracleDBMS_SQL.PARSE的使用方法和示例》DBMS_SQL是Oracle数据库中的一个强大包,用于动态构建和执行SQL语句,DBMS_SQL.PARSE过程解析SQL语句或PL/S... 目录语法示例注意事项DBMS_SQL 是 oracle 数据库中的一个强大包,它允许动态地构建和执行

如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解

《如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解》:本文主要介绍如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别的相关资料,描述了如何使用海康威视设备网络SD... 目录前言开发流程问题和解决方案dll库加载不到的问题老旧版本sdk不兼容的问题关键实现流程总结前言作为

Python中顺序结构和循环结构示例代码

《Python中顺序结构和循环结构示例代码》:本文主要介绍Python中的条件语句和循环语句,条件语句用于根据条件执行不同的代码块,循环语句用于重复执行一段代码,文章还详细说明了range函数的使... 目录一、条件语句(1)条件语句的定义(2)条件语句的语法(a)单分支 if(b)双分支 if-else(

Python中Markdown库的使用示例详解

《Python中Markdown库的使用示例详解》Markdown库是一个用于处理Markdown文本的Python工具,这篇文章主要为大家详细介绍了Markdown库的具体使用,感兴趣的... 目录一、背景二、什么是 Markdown 库三、如何安装这个库四、库函数使用方法1. markdown.mark

linux进程D状态的解决思路分享

《linux进程D状态的解决思路分享》在Linux系统中,进程在内核模式下等待I/O完成时会进入不间断睡眠状态(D状态),这种状态下,进程无法通过普通方式被杀死,本文通过实验模拟了这种状态,并分析了如... 目录1. 问题描述2. 问题分析3. 实验模拟3.1 使用losetup创建一个卷作为pv的磁盘3.

MySQL数据库函数之JSON_EXTRACT示例代码

《MySQL数据库函数之JSON_EXTRACT示例代码》:本文主要介绍MySQL数据库函数之JSON_EXTRACT的相关资料,JSON_EXTRACT()函数用于从JSON文档中提取值,支持对... 目录前言基本语法路径表达式示例示例 1: 提取简单值示例 2: 提取嵌套值示例 3: 提取数组中的值注意

MySQL8.2.0安装教程分享

《MySQL8.2.0安装教程分享》这篇文章详细介绍了如何在Windows系统上安装MySQL数据库软件,包括下载、安装、配置和设置环境变量的步骤... 目录mysql的安装图文1.python访问网址2javascript.点击3.进入Downloads向下滑动4.选择Community Server5.