Edit existing welds in Tekla - C# Code optimization

Hello,
I downloaded and edited the script from Sajesh in this thread:

Specifically, I just need to be able to edit the size of many existing welds in a Tekla Structures model, with values already available through separate Grasshopper components.
So my code is:

  private void RunScript(System.Object Saldatura, double SizeA, double SizeB, ref object Weld)
  {
    Tekla.Structures.Model.Weld Saldat = (Tekla.Structures.Model.Weld) Saldatura;
    Saldat.SizeAbove = SizeA;
    Saldat.SizeBelow = SizeB;

    Saldat.Modify();
    Weld = Saldat;

    new Tekla.Structures.Model.Model().CommitChanges();
  }

The code works on small groups of welds, but it gets REALLY slow when connected to the Tekla Object Pipeline to get all the welds (there are 1500 weld objects), it seems to hang and finally crash.

I’m sure the code can be optimized and I think maybe the problem lies in the CommitChanges line, but I don’t have enough understanding of C# to be able to spot the bottleneck.

Can someone point me in the right direction?

Thank you very much

Hi Saverio, you’re probabaly right that calling CommitChanges for each weld is slow, rather it should be done only once after all the welds have been modified. To achieve that you could read in a list of objects instead:

And then handle the list like this:

  private void RunScript(List<System.Object> Saldatura, out object Weld)
  {
    var WeldList = new List<Tekla.Structures.Model.Weld>();

    foreach (var item in Saldatura)
    {
        Tekla.Structures.Model.Weld Saldat = (Tekla.Structures.Model.Weld) item;
        Saldat.SizeAbove = SizeA;
        Saldat.SizeBelow = SizeB;

        Saldat.Modify();

        WeldList.Add(Saldat);
    }

    new Tekla.Structures.Model.Model().CommitChanges();

    Weld = WeldList;
  }

Cheers,

-b

1 Like

Ok, that seems exactly what I was looking for, I’ll let you know how that works.

Thank you very much!

Saverio

1 Like