Tekla 二次开发:PolyBeam API 完全解析 - 钢结构资源网 Tekla插件 CAD工具 犀牛GH汉化 套料 Tekla 二次开发:PolyBeam API 完全解析 - 钢结构资源网 Tekla插件 CAD工具 犀牛GH汉化 套料

Tekla 二次开发:PolyBeam API 完全解析

image.png

Tekla Structures PolyBeam API 完全解析

深入理解 Tekla 二次开发中的折梁构件对象

在 Tekla Structures 二次开发中,PolyBeam 类是 Part 的重要子类之一,用于创建具有多个折点的连续梁——包括折梁、墙板、条形基础、柱等连续线性构件。与 Beam 类不同,PolyBeam 通过一个轮廓(Contour)来定义其几何形状,可以描述任意折线路径上的等截面构件。

本文基于 Tekla Structures 2017 版本的 API 反编译代码,完整、系统地讲解 PolyBeam 类的继承体系、所有构造函数、所有自身属性、所有继承属性、所有自身方法、所有常用继承方法以及枚举类型,并提供大量可直接运行的代码示例。文中包含多张 SVG 示意图,帮助理解。


一、PolyBeam 类的继承体系

PolyBeam 是一个密封类(sealed class),位于 Tekla.Structures.Model 命名空间。其完整的继承层次如下图所示:

[图1:PolyBeam 类继承层次图]

image.png

从上图可以清晰地看出:

  • PolyBeam 直接继承自 Part,而 Part 继承自 ModelObjectModelObject 继承自 Object(即 Tekla.Structures.Model.Object)。

  • PolyBeam 是 Part 的最终子类,不能再被继承(sealed)。

  • PolyBeam 与 Beam 同为 Part 的子类,但前者用于折线路径,后者用于直线路径。

实际开发中,你通常实例化 PolyBeam 类并设置其轮廓点来创建折梁:

PolyBeam polyBeam = new PolyBeam();
polyBeam.Profile = "IPE200";
polyBeam.Material = "S355";
Contour contour = new Contour();
contour.AddContourPoint(new ContourPoint(new Point(0,0,0), null));
contour.AddContourPoint(new ContourPoint(new Point(5000,0,0), null));
contour.AddContourPoint(new ContourPoint(new Point(5000,3000,0), null));
polyBeam.Contour = contour;
polyBeam.Insert();

二、PolyBeam 类的构造函数

PolyBeam 类提供了两个公开的构造函数:

 
 
构造函数 说明
PolyBeam() 无参构造函数。创建一个默认类型的折梁(类型为 BEAM),轮廓为空,需要后续添加轮廓点。
PolyBeam(PolyBeamTypeEnum polyBeamType) 指定折梁类型的构造函数。内部会调用无参构造函数,然后设置类型。

[图2:PolyBeam 构造函数使用示意图]

image.png

示例

// 方式1:无参构造,之后手动设置轮廓和属性
PolyBeam beam1 = new PolyBeam();
beam1.Profile = "HEB200";
beam1.Material = "S355";
Contour contour1 = new Contour();
contour1.AddContourPoint(new ContourPoint(new Point(0,0,0), null));
contour1.AddContourPoint(new ContourPoint(new Point(3000,0,0), null));
beam1.Contour = contour1;

// 方式2:指定类型(例如创建一面墙板)
PolyBeam panel = new PolyBeam(PolyBeam.PolyBeamTypeEnum.PANEL);
panel.Profile = "PL10";
panel.Material = "C30";
// ... 添加轮廓点

三、PolyBeam 类的属性

3.1 PolyBeam 自身定义的属性

下表列出了 PolyBeam 类直接定义的公开属性(不包括继承来的属性):

 
 
属性名 类型 说明
Contour Contour 折梁的轮廓(Contour 对象)。该轮廓定义了折梁的中心线路径,由一系列 ContourPoint 组成。可读写。
Type PolyBeamTypeEnum 折梁的类型(只读)。在构造函数中设置,之后不可更改。

注意:Contour 是核心属性。Contour 类包含一个 ContourPoints 列表(ArrayList),每个 ContourPoint 具有 Point(坐标)和可选的 Chamfer(倒角)信息。至少需要 3 个点才能构成有效的多边形轮廓(当折梁为闭合截面时内部需要至少3个点,但折梁不要求闭合,实际应用中折线路径至少需要2个点?根据反编译代码,PolyBeamParametersCheck 方法要求 ContourPoints.Count < 3 时抛出异常,因此至少需要 3 个点。这一点比 Beam 更严格。)

3.2 继承自 Part 和 ModelObject 的常用属性

PolyBeam 从 Part 继承了以下常用属性:

 
 
属性名 类型 说明
Name string 零件名称
Class string 零件类别
Finish string 表面处理
Profile Profile 截面型材(沿轮廓线扫掠)
Material Material 材质
Position Position 位置定义(平面/深度/旋转)
PartNumber NumberingSeries 零件编号
AssemblyNumber NumberingSeries 构件编号
CastUnitType CastUnitTypeEnum 浇筑体类型
PourPhase int 浇筑体相位
Identifier Identifier 唯一标识符
IsUpToDate bool 是否已同步
ModificationTime DateTime 最后修改时间

[图3:PolyBeam 类的核心属性结构图]

image.png


四、PolyBeam 类的枚举类型

PolyBeam 类内部定义了一个枚举 PolyBeamTypeEnum,用于区分折梁的类型:

public enum PolyBeamTypeEnum
{
    BEAM,           // 普通折梁
    PANEL,          // 墙板
    STRIP_FOOTING,  // 条形基础
    COLUMN          // 柱
}

[图4:PolyBeamTypeEnum 枚举类型及含义]

image.png

使用示例:创建一个条形基础

PolyBeam footing = new PolyBeam(PolyBeam.PolyBeamTypeEnum.STRIP_FOOTING);
footing.Profile = "RECT300*500";
footing.Material = "C30";
// 添加轮廓点
Contour contour = new Contour();
contour.AddContourPoint(new ContourPoint(new Point(0,0,0), null));
contour.AddContourPoint(new ContourPoint(new Point(5000,0,0), null));
contour.AddContourPoint(new ContourPoint(new Point(5000,500,0), null)); // 第三个点必须
footing.Contour = contour;
footing.Insert();

注意:枚举值影响报表分类,不改变几何行为;几何完全由轮廓点决定。


五、PolyBeam 类的方法

5.1 PolyBeam 自身定义的方法

下表列出了 PolyBeam 类直接定义的所有公开方法(不包括继承来的方法):

 
 
方法 返回值 说明
AddContourPoint(ContourPoint contourPoint) bool 向折梁的轮廓中添加一个轮廓点。成功返回 true;最多支持 99 个点。
GetPolybeamCoordinateSystems() ArrayList of CoordinateSystem 获取折梁每个直线段的局部坐标系列表。每个 CoordinateSystem 对应一个线段。
Insert() bool 将当前折梁对象插入模型数据库。重写自 Part
Select() bool 在模型中选中当前折梁。重写自 Part
Modify() bool 将当前折梁的属性修改保存到模型数据库。重写自 Part
Delete() bool 从模型数据库中删除当前折梁。重写自 Part

注意:AddContourPoint 内部会检查 Contour.ContourPoints.Count < 99,因此最多 99 个点。实际创建时建议直接操作 Contour.ContourPoints 列表,或多次调用 AddContourPoint

5.2 继承自 Part 和 ModelObject 的常用方法

PolyBeam 从 Part 继承了以下常用方法(部分列表):

 
 
方法 说明
GetCenterLine(bool withCutsFittings) 获取折梁的中心线(受切割影响时)
GetReferenceLine(bool withCutsFittings) 获取折梁的参考线
GetSolid() 获取折梁的实体几何模型
GetSolid(FormingStates) 获取指定成型状态的实体
GetAssembly() 获取折梁所属的构件
GetBolts() 获取折梁上的所有螺栓
GetWelds() 获取折梁上的所有焊缝
GetComponents() 获取连接到折梁的所有组件
GetPartMark() 获取折梁的零件编号
GetDSTVCoordinateSystem() 获取 DSTV 坐标系
CompareTo(Part other) 比较两个零件是否相同

此外,从 ModelObject 继承了以下核心操作:

 
 
方法 说明
GetUserProperty(string) 获取自定义属性(UDA)值
SetUserProperty(string, object) 设置自定义属性(UDA)值
GetReportProperty(string) 获取报表属性值
GetAllReportProperties(...) 批量获取报表属性
GetAllUserProperties() 获取所有自定义属性

[图5:PolyBeam 类的常用操作流程]

image.png


六、完整代码示例

示例1:创建一根三折点的折梁(L型)

using Tekla.Structures.Model;
using Tekla.Structures.Geometry3d;

class Program
{
    static void Main()
    {
        Model model = new Model();
        if (!model.GetConnectionStatus())
        {
            Console.WriteLine("请先打开Tekla模型");
            return;
        }

        // 创建折梁对象
        PolyBeam polyBeam = new PolyBeam();
        polyBeam.Name = "LBracket";
        polyBeam.Class = "Primary";
        polyBeam.Profile = new Profile("IPE200");
        polyBeam.Material = new Material("S355");

        // 构建轮廓(折线路径)
        Contour contour = new Contour();
        contour.AddContourPoint(new ContourPoint(new Point(0, 0, 0), null));
        contour.AddContourPoint(new ContourPoint(new Point(3000, 0, 0), null));
        contour.AddContourPoint(new ContourPoint(new Point(3000, 2000, 0), null));
        polyBeam.Contour = contour;

        // 插入模型
        if (polyBeam.Insert())
        {
            model.CommitChanges();
            Console.WriteLine("L型折梁创建成功");
        }
        else
        {
            Console.WriteLine("创建失败");
        }
    }
}

示例2:创建一面墙板(使用类型枚举)

PolyBeam panel = new PolyBeam(PolyBeam.PolyBeamTypeEnum.PANEL);
panel.Name = "ShearWall";
panel.Profile = new Profile("PL12");
panel.Material = new Material("C30");

Contour contour = new Contour();
contour.AddContourPoint(new ContourPoint(new Point(0, 0, 0), null));
contour.AddContourPoint(new ContourPoint(new Point(4000, 0, 0), null));
contour.AddContourPoint(new ContourPoint(new Point(4000, 3000, 0), null));
contour.AddContourPoint(new ContourPoint(new Point(0, 3000, 0), null)); // 闭合轮廓
panel.Contour = contour;
panel.Insert();
model.CommitChanges();

示例3:遍历模型中的所有折梁并输出轮廓点数

ComponentEnumerator enumerator = model.GetComponents();
while (enumerator.MoveNext())
{
    PolyBeam polyBeam = enumerator.Current as PolyBeam;
    if (polyBeam != null)
    {
        Console.WriteLine($"折梁名称: {polyBeam.Name}");
        Console.WriteLine($"  轮廓点数: {polyBeam.Contour.ContourPoints.Count}");
        Console.WriteLine($"  类型: {polyBeam.Type}");
        Console.WriteLine($"  截面: {polyBeam.Profile.ProfileString}");
    }
}

示例4:获取折梁各段的局部坐标系

ArrayList coordSystems = polyBeam.GetPolybeamCoordinateSystems();
for (int i = 0; i < coordSystems.Count; i++)
{
    CoordinateSystem cs = coordSystems[i] as CoordinateSystem;
    if (cs != null)
    {
        Console.WriteLine($"第{i+1}段原点: ({cs.Origin.X}, {cs.Origin.Y}, {cs.Origin.Z})");
    }
}

[图6:折梁轮廓点与局部坐标系示意图]

image.png


七、常见问题与注意事项

问题1:创建 PolyBeam 时提示“Required information missing - ContourPoints”怎么办?

  • PolyBeam 的 Insert 方法内部会检查轮廓至少含有 3 个点。必须添加至少 3 个 ContourPoint 到 Contour 属性中。

问题2:PolyBeam 和 Beam 有什么区别?

  • Beam 只有起点和终点,是直线段;PolyBeam 可以有多个折点,描述任意折线路径。两者都继承自 Part,但 PolyBeam 要求轮廓点数量至少 3 个,且几何由轮廓决定。

问题3:ContourPoint 的第二个参数 Chamfer 有什么用?

  • Chamfer 可以设置倒角类型(如圆弧倒角、切角),用于在折点处平滑过渡。不设置(null)则为尖角。

问题4:如何创建闭合的折梁(如矩形框架)?

  • 添加的轮廓点首尾不自动闭合,需要显式添加最后一个点等于第一个点(或通过截面位置)。通常用于墙板、楼板等。

问题5:GetPolybeamCoordinateSystems() 返回的坐标系如何理解?

  • 每个线段对应一个局部坐标系。原点位于线段起点,X 轴沿线段的切线方向,Y 轴和 Z 轴根据全局坐标系统自动计算。可用于放置附属对象。

问题6:能否修改折梁的轮廓点数量?

  • 可以。直接修改 Contour.ContourPoints 列表(添加、删除、修改点),然后调用 Modify() 即可。


八、总结

PolyBeam 类是 Tekla OpenAPI 中创建折线构件的核心类。本文完整覆盖了:

  • 继承体系(PolyBeam → Part → ModelObject → Object

  • 全部两个构造函数

  • 全部自身属性(ContourType

  • 全部常用继承属性(来自 Part 和 ModelObject

  • 枚举 PolyBeamTypeEnum(4 种类型)

  • 全部自身方法(AddContourPointGetPolybeamCoordinateSystems, 重写的 Insert/Select/Modify/Delete

  • 全部常用继承方法(几何、装配、编号、UDA 等)

  • 多个可直接运行的代码示例

  • 多张 SVG 示意图,帮助理解继承关系、属性结构、枚举含义、操作流程和轮廓坐标系

无论你是要创建复杂的折线钢梁、混凝土墙板,还是条形基础,PolyBeam 都是不可或缺的工具。

QQ_1778130875151.png

QQ_1778130894832.png

 

评论 0

sitemap