API Reference

Detailed and full API reference helps you master Tekla development

This is the most recent version of Tekla Open API.
For older versions, please visit Tekla Warehouse.

Meta.Microsoft.Help.Id
M:Tekla.Structures.Model.Model.FetchModelObjects(System.Collections.Generic.List{System.String},System.Boolean)

ModelFetchModelObjects Method

Fetches a list of modelobjects based on given guid list of objects, checks if guid is native or external (for reference model object) and optionally selects objects before returning them.

Namespace:  Tekla.Structures.Model
Assembly:  Tekla.Structures.Model (in Tekla.Structures.Model.dll) Version: 2020.0.0.0 (2020.0.55582.0)
Syntax
public List<ModelObject> FetchModelObjects(
	List<string> Guids,
	bool SelectInstances = true
)

Parameters

Guids
Type: System.Collections.GenericListString
The GUID list to look for in the model.
SelectInstances (Optional)
Type: SystemBoolean
Optional parameter whether object is selected, default = true.

Return Value

Type: ListModelObject
The model objects with the given guids, or empty list if any of the objects do not exists or object data loading failed for some reason.
Examples
Guids of selected model objects are stored to list and fetched using guid list:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Tekla.Structures.Model;
using TSMU = Tekla.Structures.Model.UI;

public class Example
{
    public void Example1()
    {
        Model model = new Model();

        var selector = new TSMU.ModelObjectSelector();
        var selection = selector.GetSelectedObjects();
        var guidList = new List<string>();

        foreach (ModelObject obj in selection)
        {
            var ro = obj as ReferenceModelObject;
            string guid = string.Empty;
            if (ro != null)
            {
                if(ro.GetReportProperty("EXTERNAL.GUID", ref guid))
                    guidList.Add(guid);
            }
            else
            {
                guidList.Add(obj.Identifier.GUID.ToString());
            }
        }

        var objList = model.FetchModelObjects(guidList, false);

        MessageBox.Show(objList.Count.ToString() + " objects found.");
    }
}
See Also