Muggle.TsExtensions.CodingHelper 3.0.0-beta.1

This is a prerelease version of Muggle.TsExtensions.CodingHelper.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Muggle.TsExtensions.CodingHelper --version 3.0.0-beta.1
                    
NuGet\Install-Package Muggle.TsExtensions.CodingHelper -Version 3.0.0-beta.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Muggle.TsExtensions.CodingHelper" Version="3.0.0-beta.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muggle.TsExtensions.CodingHelper" Version="3.0.0-beta.1" />
                    
Directory.Packages.props
<PackageReference Include="Muggle.TsExtensions.CodingHelper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Muggle.TsExtensions.CodingHelper --version 3.0.0-beta.1
                    
#r "nuget: Muggle.TsExtensions.CodingHelper, 3.0.0-beta.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Muggle.TsExtensions.CodingHelper@3.0.0-beta.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Muggle.TsExtensions.CodingHelper&version=3.0.0-beta.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muggle.TsExtensions.CodingHelper&version=3.0.0-beta.1&prerelease
                    
Install as a Cake Tool

Muggle.TsExtensions.CodingHelper

中文版

This is a tool to assist in developing Tekla Structures components. Its features include:

  • Generate fields and utility methods for plugin data class, making it convenient to create or modify objects
  • Generate fields for plugin class (if needed)
  • Generate view model properties (if using a WPF interface)
  • Generate a simple user interface


Generate Fields and Utility Methods for Plugin Data Class

This generator provides the following set of attributes. Apply them to plugin data class as needed, and set the property default values to generate the corresponding fields:

  • PartAttribute
  • PlateAttribute
  • ChamferAttribute
  • BoltAttribute
  • StudAttribute
  • WeldAttribute
  • GeneralAttribute

Object properties and their corresponding fields along with the plugin parameter name patterns follow this document.

It also generates a "SetFieldsToDefaultIfUnset" method, a series of "Create*<T>" and "ModifyTo*<T>" methods.

The SetFieldsToDefaultIfUnset method is used to set fields whose values have not been set in the user interface to their default values.

The Create*<T> methods are used to create objects using the corresponding fields; the generic parameter is the type of object you want to obtain.

The ModifyTo*<T> methods are used to modify a given object using the corresponding fields.

Example

Use the attributes in the plugin data class like this:

// ====================
//    PluginData.cs
// ====================

[Part("main", Profile = "HM244*175*7*11")]
[Bolt(1, Shape = Circle, NumberOfBolts = 12, Diameter = 200)]
public partial class PluginData { }

Then, code similar to the following will be generated in the background:

// ====================
//    PluginData.g.cs
// ====================

public partial class PluginData 
{
    [StructuresField("PTmainNAME")] public string PartMainName;
    [StructuresField("PTmainPRF")] public string PartMainProfile;
    [StructuresField("PTmainMATL")] public string PartMainMaterial;
    [StructuresField("PTmainFNSH")] public string PartMainFinish;
    [StructuresField("PTmainCLS")] public int PartMainClass;
    [StructuresField("PTmainPTP")] public string PartMainPartPrefix;
    [StructuresField("PTmainPTN")] public int PartMainPartStartNumber;
    [StructuresField("PTmainASMP")] public string PartMainAssemblyPrefix;
    [StructuresField("PTmainASMN")] public int PartMainAssemblyStartNumber;
    [StructuresField("B1SHAPE")] public int Bolt1Shape;
    [StructuresField("B1STD")] public string Bolt1Standard;
    [StructuresField("B1SIZE")] public double Bolt1Size;
    [StructuresField("B1DISTX")] public string Bolt1DistX;
    [StructuresField("B1DISTY")] public string Bolt1DistY;
    [StructuresField("B1NUM")] public int Bolt1NumberOfBolts;
    [StructuresField("B1DIAM")] public double Bolt1Diameter;
    [StructuresField("B1TYPE")] public int Bolt1Type;
    [StructuresField("B1THRD")] public int Bolt1ThreadInMaterial;
    [StructuresField("B1LEN")] public double Bolt1Length;
    [StructuresField("B1CLEN")] public double Bolt1CutLength;
    [StructuresField("B1XLEN")] public double Bolt1ExtraLength;
    [StructuresField("B1TOL")] public double Bolt1Tolerance;
    [StructuresField("B1PLAIN")] public int Bolt1PlainType;
    [StructuresField("B1DEPTH")] public double Bolt1BlindHoleDepth;
    [StructuresField("B1HOLTY")] public int Bolt1HoleType;
    [StructuresField("B1SLOTX")] public double Bolt1SlottedHoleX;
    [StructuresField("B1SLOTY")] public double Bolt1SlottedHoleY;
    [StructuresField("B1SOFFX")] public double Bolt1SlotOffsetX; // Depends on OpenAPI version
    [StructuresField("B1SOFFY")] public double Bolt1SlotOffsetY; // Depends on OpenAPI version
    [StructuresField("B1RSLOT")] public int Bolt1RotateSlots;
    [StructuresField("B1HOLE1")] public int Bolt1Hole1;
    [StructuresField("B1HOLE2")] public int Bolt1Hole2;
    [StructuresField("B1HOLE3")] public int Bolt1Hole3;
    [StructuresField("B1HOLE4")] public int Bolt1Hole4;
    [StructuresField("B1HOLE5")] public int Bolt1Hole5;
    [StructuresField("B1ISBOT")] public int Bolt1IsBolt;
    [StructuresField("B1NUT1")] public int Bolt1UseNut1;
    [StructuresField("B1NUT2")] public int Bolt1UseNut1;
    [StructuresField("B1WSHR1")] public int Bolt1UseWasher1;
    [StructuresField("B1WSHR2")] public int Bolt1UseWasher2;
    [StructuresField("B1WSHR3")] public int Bolt1UseWasher3;
    
    public void SetFieldsToDefaultIfUnset()
    {
        /* ... */
    }
    
    public T CreatePartMain<T>() where T : Part, new() 
    {
        /* ... */
    }
    
    public void ModifyToPartMain<T>(ref T part) where T : Part 
    {
        /* ... */
    }
    
    public T CreateBolt1<T>() where T : BoltGroup, new() 
    {
        /* ... */
    }
    
    public void ModifyToBolt1<T>(ref T bolt) where T : BoltGroup 
    {
        /* ... */
    }
}

Then, you can use it within the plugin class like this:

// ====================
//    Plugin.cs
// ====================

[Plugin("Demo")]
public partial class Plugin : PluginBase 
{
    private PluginData Data { get; }
    
    public Plugin(PluginData data)
    {
        Data = data;
    }
    
    public override bool Run(List<InputDefinition> input) 
    {
        // Call this method first to set fields whose values have not been set to their default values
        Data.SetFieldsToDefaultIfUnset();
        
        /* ... */
        
        var main = CreatePartMain<Beam>(); // Create an object of type Beam
        main.StartPoint = p1;
        main.EndPoint = p2;
        main.Insert();
        
        /* ... */
        
        Beam beam = /* ... */ // Create an object of type Beam through other means
        ModifyToPartMain(ref beam);
        beam.Insert();
        
        /* ... */
        
        BoltGroup bolt = Data.Bolt1Shape switch 
        {
            1 => CreateBolt1<BoltCircle>(),
            2 => CreateBolt1<BoltXYList>(),
            _ => CreateBolt1<BoltArray>()
        };
        bolt.PartToBoltTo = main;
        bolt.PartToBeBolted = somePart;
        bolt.FirstPosition = p1;
        bolt.SecondPosition = p2;
        bolt.Insert();
        
        /* ... */
        
    }
    
    /* ... */
}

Generate Fields for Plugin Class

If you find accessing plugin parameters like Data.PartMainProfile redundant, you can apply the "FieldsFromDataAttribute" attribute to the plugin class. The generator will then generate fields for the plugin class that correspond one-to-one with the plugin data class fields. Call the "GetFieldValuesFrom" method at the appropriate place, and you can then access plugin parameters like _partMainProfile.


Generate View Model Properties

If you use a WPF user interface, apply the attributes provided in the Generate Fields and Utility Methods for Plugin Data Class section to the view model (which implements the INotifyPropertyChanged interface), and the generator will automatically generate the related properties for the view model.

The generator determines whether a class which these attributes are applied is a plugin data class or a view model class based on whether this class implements the INotifyPropertyChanged interface. So you can simply copy the attributes already applied to the plugin data class to the view model class.

This generator also provides the following base classes to offer some common code:

  • NotificationObject
  • ConnectionViewModel
  • DetailViewModel
  • CustomPartViewModel

Among them, NotificationObject implements the INotifyPropertyChanged interface, while the other three classes inherit from NotificationObject and respectively provide common tab properties for Connection, Detail, and CustomPart type plugin.

Make view model inherit from one of them as needed to avoid reimplementing related code.


Generate User Interface

Apply the "UserInterfaceAttribute" attribute to the plugin class to generate a simple user interface. On one hand, this makes debugging easer during the core logic development phase; on the other hand, it reduces the workload during the user interface development phase, because you can directly make slight edits based on the generated code.

Currently, supports INP and WPF; support for WinForm is planned for future versions.

Note: When using the INP user interface, the weld parameters need to be filled in the dialog first, click Apply, and create the component, then the parameter values will take effect. If you create the component first and then open the dialog to edit the weld parameters and click Modify, the parameter values won’t take effect.
It’s not clear yet whether this is a bug in Tekla Structures itself, or if something in the generated code doesn’t comply with Tekla Structures standards. If you know how to fix this issue, please contact with me.

Note: Because the official implementation of source generators does not allow outputting files with extensions other than .cs, when generating a WPF user interface, this generator bypasses the official approach and outputs a "WpfUi.g.xaml" file in the project directory. However, this also brings a drawback — when the generated WPF interface is no longer needed, this file must be deleted manually. (Although the WPF interface can be written in pure C# code, but doing so would lose the second convenience mentioned above.)


Demo

If there is anything you still do not understand, you can check out this demo project, or other plugin projects under that demo project's solution.

Preview0

Preview1

Preview2

Preview3

Preview4

Preview5

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0-beta.2 41 11/24/2026
3.0.0-beta.1 53 11/22/2026
2.1.0-beta.4 60 11/6/2026
2.1.0-beta.3 69 10/16/2026
2.1.0-beta.2 75 9/28/2026
2.1.0-beta.1 77 9/18/2026
2.0.0 122 9/18/2026
2.0.0-beta.4 85 7/3/2026
2.0.0-beta.3 79 6/26/2026
2.0.0-beta.1 77 6/5/2026
1.4.1 139 5/15/2026
1.4.0 122 5/11/2026
1.3.3 135 5/10/2026
1.3.2 131 4/27/2026
Loading failed

1. The original three sets of registration fields/properties and default value attributes have been merged into one set, making it easier to use.
           Previously:
           *FieldsAttribute was applied to plugin data class to register fields;
           *FieldDefaultValuesAttribute was applied to plugin class to register default values;
           *PropertiesAttribute was applied to view model class to register properties and default values.
           Now:
           Only one *Attribute is needed, applied to plugin data class and view model class. The generator automatically decides whether to generate fields and default values or properties and default values based on whether the class implements the INotifyPropertyChanged interface.
           2. The SetDataToDefaultIfUnset, Create*<T>, and ModifyTo*<T> methods that were previously generated in plugin class are now generated in plugin data class, and the SetDataToDefaultIfUnset method has been renamed SetFieldsToDefaultIfUnset.
           3. The previous FieldsFromAttribute has been renamed FieldsFromDataAttribute and no longer requires passing the data class type as a parameter.
           4. The previous three BoltCircle-related attributes have now been merged into BoltAttribute. Bolt now has three new fields/properties: Shape, NumberOfBolts, and Diameter.
           5. To compatible with stud-related parameters in the INP dialog, a new StudAttribute has been added. Both WPF and WinForm dialogs can freely choose either BoltAttribute or StudAttribute.
           6. Fixed the issue in previous versions where the CreateWeld*<T> and ModifyToWeld<T> methods did not set the BlindHoleDepth value.
           7. Add support for INP type in the user interface generation feature.
           
           1、原先三套注册字段/属性和默认值的特性,合并为一套,更易于使用。
           原先:
           *FieldsAttribute 应用于组件数据类上,以注册字段;
           *FieldDefaultValuesAttribute 应用于组件类上,以注册默认值;
           *PropertiesAttribute 应用于视图模型上,以注册属性和默认值。
           现在:
           只需要一套 *Attribute 应用于组件数据类和视图模型上,
           生成器自动根据类是否实现了 INotifyPropertyChanged 接口决定生成字段及默认值还是属性及默认值
           2、原先在组件类中生成的 SetDataToDefaultIfUnset、Create*<T> 和 ModifyTo*<T> 方法,现在移至组件数据类中生成,且 SetDataToDefaultIfUnset 方法重命名为 SetFieldsToDefaultIfUnset。
           3、原先的 FieldsFromAttribute 重命名为 FieldsFromDataAttribute,且不再需要传入数据类类型参数。
           4、原先 BoltCircle 相关的三个特性,现合并至 BoltAttribute,现在 Bolt 多了 Shape, NumberOfBolts, Diameter 三个字段/属性。
           5、为兼容 INP 对话框中栓钉相关的参数,新添加 StudAttribute 特性,WPF 和 WinForm 对话框可自由选用 BoltAttribute 或 StudAttribute 之一。
           6、修复之前版本 CreateWeld*<T> 和 ModifyToWeld<T> 方法未设置 BlindHoleDepth 值的问题。
           7、生成用户界面功能添加对 INP 类型的支持。