(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

相关文章

sky-take-out项目中Redis的使用示例详解

《sky-take-out项目中Redis的使用示例详解》SpringCache是Spring的缓存抽象层,通过注解简化缓存管理,支持Redis等提供者,适用于方法结果缓存、更新和删除操作,但无法实现... 目录Spring Cache主要特性核心注解1.@Cacheable2.@CachePut3.@Ca

QT Creator配置Kit的实现示例

《QTCreator配置Kit的实现示例》本文主要介绍了使用Qt5.12.12与VS2022时,因MSVC编译器版本不匹配及WindowsSDK缺失导致配置错误的问题解决,感兴趣的可以了解一下... 目录0、背景:qt5.12.12+vs2022一、症状:二、原因:(可以跳过,直奔后面的解决方法)三、解决方

MySQL中On duplicate key update的实现示例

《MySQL中Onduplicatekeyupdate的实现示例》ONDUPLICATEKEYUPDATE是一种MySQL的语法,它在插入新数据时,如果遇到唯一键冲突,则会执行更新操作,而不是抛... 目录1/ ON DUPLICATE KEY UPDATE的简介2/ ON DUPLICATE KEY UP

Python中Json和其他类型相互转换的实现示例

《Python中Json和其他类型相互转换的实现示例》本文介绍了在Python中使用json模块实现json数据与dict、object之间的高效转换,包括loads(),load(),dumps()... 项目中经常会用到json格式转为object对象、dict字典格式等。在此做个记录,方便后续用到该方

MySQL分库分表的实践示例

《MySQL分库分表的实践示例》MySQL分库分表适用于数据量大或并发压力高的场景,核心技术包括水平/垂直分片和分库,需应对分布式事务、跨库查询等挑战,通过中间件和解决方案实现,最佳实践为合理策略、备... 目录一、分库分表的触发条件1.1 数据量阈值1.2 并发压力二、分库分表的核心技术模块2.1 水平分

SpringBoot请求参数传递与接收示例详解

《SpringBoot请求参数传递与接收示例详解》本文给大家介绍SpringBoot请求参数传递与接收示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋... 目录I. 基础参数传递i.查询参数(Query Parameters)ii.路径参数(Path Va

RabbitMQ 延时队列插件安装与使用示例详解(基于 Delayed Message Plugin)

《RabbitMQ延时队列插件安装与使用示例详解(基于DelayedMessagePlugin)》本文详解RabbitMQ通过安装rabbitmq_delayed_message_exchan... 目录 一、什么是 RabbitMQ 延时队列? 二、安装前准备✅ RabbitMQ 环境要求 三、安装延时队

Redis实现高效内存管理的示例代码

《Redis实现高效内存管理的示例代码》Redis内存管理是其核心功能之一,为了高效地利用内存,Redis采用了多种技术和策略,如优化的数据结构、内存分配策略、内存回收、数据压缩等,下面就来详细的介绍... 目录1. 内存分配策略jemalloc 的使用2. 数据压缩和编码ziplist示例代码3. 优化的

GO语言短变量声明的实现示例

《GO语言短变量声明的实现示例》在Go语言中,短变量声明是一种简洁的变量声明方式,使用:=运算符,可以自动推断变量类型,下面就来具体介绍一下如何使用,感兴趣的可以了解一下... 目录基本语法功能特点与var的区别适用场景注意事项基本语法variableName := value功能特点1、自动类型推

Java中的stream流分组示例详解

《Java中的stream流分组示例详解》Java8StreamAPI以函数式风格处理集合数据,支持分组、统计等操作,可按单/多字段分组,使用String、Map.Entry或Java16record... 目录什么是stream流1、根据某个字段分组2、按多个字段分组(组合分组)1、方法一:使用 Stri