Weld from Grasshopper to Tekla

Hello,

I have developed my own solution for creating welds in the model. However, the biggest challenge I encountered was modifying existing welds because running the script again would create duplicate welds. I believe it is possible to implement a modification method, but for now, I delete the old weld and recreate it.

Here is how my solution works:

  • There is a text file containing GUID elements.
  • I select all the welds in the model.
  • I compare each weld with my GUID and choose the appropriate one.
  • I delete my welds and create them again.
  • Finally, I update the text file with a new GUID.

The problem I am facing is that the comparison process takes a long time when dealing with a large number of elements. I am open to suggestions on how to improve this concept.

I’m working in TS2021. I see thm like I’m looking for, but how I understand it work just after TS2022. SelectMetod

Thank you!

Here metod of choising

  void ChooseNeededOb(Model currentModel, List<string> GUIDList, List<Weld> WeldList)
  {
    ModelObject.ModelObjectEnum obType = ModelObject.ModelObjectEnum.WELD;
    ModelObjectEnumerator objects = currentModel.
      GetModelObjectSelector().GetAllObjectsWithType(obType);

    var counter = 0;
    foreach (Weld obj in objects)
    {
      for (var i = 0; i < GUIDList.Count;i++)
      {
        bool a = obj.Identifier.GUID.ToString() == GUIDList[i];

        if(obj != null && a)
        {
          WeldList.Add(obj);
          counter += 1;
          break;
        }
      }
      if (counter == (GUIDList.Count))
        break;
    }
  }

In file full code, if smb interested
weldCode.txt (9.8 KB)

Hi YAHOR,

see this example on how it could be done for beams, that can surely be adapted for welds as well:

Cheers,

-b

1 Like

If you search for a similar post in the forum you can easily get this one:

Tekla Weld - Grasshopper / Tekla - McNeel Forum

Anyway, here is the code I developed some time ago with @sebastian.lindholm help!

private void RunScript(DataTree<Point3d> Points, List<System.Object> MainPart, List<System.Object> SecondPart, bool WeldAround, bool WeldWorkShop, string WeldType_Above, int WeldSize_Above, int WeldAngle_Above, string WeldType_Below, int WeldSize_Below, int WeldAngle_Below, List<string> UdasNames, List<string> UDAS, ref object Polygonal_Welds)
  {

    
    //New Model
    var model = new Model();

    //Number of welds to create
    var Weld_Count = MainPart.Count;

    // created Welds
    var outWelds = new List<ModelObject>();

    // read GUIDs of previously created welds
    var storedGuids = ReadGuids();

    // create or modify welds according to the inputs
    for (int i = 0; i < Weld_Count; i++)
    {
      var mainpa = (Tekla.Structures.Model.Part) MainPart[i];
      var secpa = (Tekla.Structures.Model.Part) SecondPart[i];
      var points = Points.Branches[i];

      var guid = storedGuids.Count > i ? storedGuids[i] : "";

      // create a new weld
      var PWeld = new PolygonWeld();
      {
        //Definition of the part to be welded
        PWeld.MainObject = mainpa;
        PWeld.SecondaryObject = secpa;

        //Definition of the points
        foreach (var point in points)
        {
          PWeld.Polygon.Points.Add(new Tekla.Structures.Geometry3d.Point(point.X, point.Y, point.Z));
        }

        //General Properties
        PWeld.AroundWeld = WeldAround;
        PWeld.ShopWeld = WeldWorkShop;

        //Properties Line Above
        switch (WeldType_Above)
        {
          case "W0": PWeld.TypeAbove = PolygonWeld.WeldTypeEnum.WELD_TYPE_NONE;
            break;
          case "W10": PWeld.TypeAbove = PolygonWeld.WeldTypeEnum.WELD_TYPE_FILLET;
            break;
          case "W6": PWeld.TypeAbove = PolygonWeld.WeldTypeEnum.WELD_TYPE_SINGLE_BEVEL_BUTT_WITH_BROAD_ROOT_FACE;
            break;
          case "W4": PWeld.TypeAbove = PolygonWeld.WeldTypeEnum.WELD_TYPE_BEVEL_GROOVE_SINGLE_BEVEL_BUTT;
            break;
          case "W3": PWeld.TypeAbove = PolygonWeld.WeldTypeEnum.WELD_TYPE_BEVEL_GROOVE_SINGLE_V_BUTT;
            break;
          default: PWeld.TypeAbove = PolygonWeld.WeldTypeEnum.WELD_TYPE_NONE;
            break;
        }

        //Conditional to set no weld parameters
        if (WeldType_Above == "W0")
        {
          PWeld.SizeAbove = 0;
          PWeld.AngleAbove = 0;
        }
        else
        {
          PWeld.SizeAbove = WeldSize_Above;
          PWeld.AngleAbove = WeldAngle_Above;
        }

        //Properties Line Below

        switch (WeldType_Below)
        {
          case "W0": PWeld.TypeBelow = PolygonWeld.WeldTypeEnum.WELD_TYPE_NONE;
            break;
          case "W10": PWeld.TypeBelow = PolygonWeld.WeldTypeEnum.WELD_TYPE_FILLET;
            break;
          case "W6": PWeld.TypeBelow = PolygonWeld.WeldTypeEnum.WELD_TYPE_SINGLE_BEVEL_BUTT_WITH_BROAD_ROOT_FACE;
            break;
          case "W4": PWeld.TypeBelow = PolygonWeld.WeldTypeEnum.WELD_TYPE_BEVEL_GROOVE_SINGLE_BEVEL_BUTT;
            break;
          case "W3": PWeld.TypeBelow = PolygonWeld.WeldTypeEnum.WELD_TYPE_BEVEL_GROOVE_SINGLE_V_BUTT;
            break;
          default: PWeld.TypeBelow = PolygonWeld.WeldTypeEnum.WELD_TYPE_NONE;
            break;
        }

        //Conditional to set no weld parameters
        if (WeldType_Below == "W0")
        {
          PWeld.SizeBelow = 0;
          PWeld.AngleBelow = 0;
        }
        else
        {
          PWeld.SizeBelow = WeldSize_Below;
          PWeld.AngleBelow = WeldAngle_Below;
        }

        };

      // try setting its guid to the stored guid (if any)
      if (!string.IsNullOrEmpty(guid))
      {
        PWeld.Identifier = model.GetIdentifierByGUID(guid);
      }

      // check if the weld already exists in the model
      if (PWeld.Identifier.IsValid())
      {
        //Write UDAs
        int j;
        for (j = 0; j < UdasNames.Count; j++)
        {
          PWeld.SetUserProperty(UdasNames[j], UDAS[j]);
        }

        // weld was found in the model, just update it
        PWeld.Modify();
      }
      else
      {
        // weld was not found in the model, create a new one and store its guid
        PWeld.Insert();

        //Write UDAs
        int j;
        for (j = 0; j < UdasNames.Count; j++)
        {
          PWeld.SetUserProperty(UdasNames[j], UDAS[j]);
        }

        PWeld.Modify();

        var guidToStore = new Model().GetGUIDByIdentifier(PWeld.Identifier);
        if (storedGuids.Count > i)
          storedGuids[i] = guidToStore;
        else
          storedGuids.Add(guidToStore);
      }
      outWelds.Add(PWeld);
    }

    // delete old welds that weren't updated or reused
    for (int weldToDeleteIndex = outWelds.Count; weldToDeleteIndex < storedGuids.Count; weldToDeleteIndex++)
    {
      var PWeld = new PolygonWeld();
      PWeld.Identifier = model.GetIdentifierByGUID(storedGuids[weldToDeleteIndex]);
      if (PWeld.Identifier.IsValid())
      {
        PWeld.Delete();
      }
    }

    // store GUIDS of the new welds
    WriteGuids(storedGuids.Take(Weld_Count).ToList());


    model.CommitChanges();

    Polygonal_Welds = outWelds;

  }

  // <Custom additional code> 

  // METHODS FOR KEEPING TRACK OF CREATED OBJECTS USING THEIR GUIDS
  // In this case, just store and return the guids in the object inside this component.
  // To save the guids between sessions (or updates to this scripting component), these methods could write the guid list to e.g. a file instead.
  // Then, for mappping purposes, to keep track of this component use e.g. its instance guid (this.Component.InstanceGuid)
  private List<string> _storedGuids = new List<string>();
  private List<string> ReadGuids()
  {
    return new List<string>(_storedGuids);
  }
  private void WriteGuids(List < string > guids)
  {
    _storedGuids = guids;
  }

  /// <summary>
  /// This method will be called once every solution, before any calls to RunScript.
  /// </summary>


  // </Custom additional code> 
}

Regards!

2 Likes

Thank you! I did it. It works correctly now and thanks for that I can use Grasshopper component with weld for my steel connection.

1 Like

Thanks, I see some interesting lines in your code that I can use, but I have already written the code based on the example " C# Example 1: Create beams in Tekla". It looks similar