How to Programmatically Select Objects in the Model (Tekla Open API)

_config.yml

Background: What are we trying to do:

We have programmatically identified some model objects that we want to select in the model – to attract attention to the user and to allow her to easily identify all such objects. In this particular case we will be creating some beams. And then, we will select those beams in the model. Here is a code snippet to get you started:

           Model Model = new Model();
           Beam B = new Beam(new Point(0,0,0), new Point(0,0,1000));
           Beam B1 = new Beam(new Point(0,1000,0), new Point(0,1000,5000));
           Beam B2 = new Beam(new Point(0,2000,0), new Point(0,2000,5000));

           B.Insert();
           B1.Insert();
           B2.Insert();

           ArrayList ObjectsToSelect = new ArrayList();
           ObjectsToSelect.Add(B);
           ObjectsToSelect.Add(B1);
           ObjectsToSelect.Add(B2);

           Tekla.Structures.Model.UI.ModelObjectSelector MS = new Tekla.Structures.Model.UI.ModelObjectSelector();
           MS.Select(ObjectsToSelect);

           Model.CommitChanges();

It’s pretty straight forward and quite simple – once you know, that is.

Written on October 17, 2017