Tekla Open API, Hide/Show Objects in Model

This article explains how you can use the Tekla Open API to hide and show objects in the model. Note that the API doesn’t provide any direct methods for hiding/showing objects in the model. This article will provide a workaround for achieving this.

 


Contents

Step 1, Add Libraries:

Add reference to the Tekla.Structures.Model library located in the path “C:Program FilesTekla Structures20.0ntbinplugins” and manually open the tekla model. This has been covered in the article below:


Step 2, Manually Create Filter (One Time Only):

You will need to manually create the following filter:

( Category Property Condition Value ) And/Or
Object User field 1 (USER_FIELD_1) Equals “Show”

Save the filter under the name “MyNewFilter”:
Blog_Tekla_API_HideShowObjects_3

Note: This step is one time only. Once the filter is created you will be able to use it in all other models.


Step 3:

With the previous filter in place all you need to do is change the value of “user field 1” for the objects in the model, and they will be hidden or shown. For example consider the model below:
Blog_Tekla_API_HideShowObjects_2
Lets say we only want to show the parts in the model. This can be achieved using the code below:

Imports TSM = Tekla.Structures.Model

    Private Sub ShowPartsOnly()
        Dim appModel As TSM.Model
        Dim objModel As TSM.ModelObject
        Dim objPart As TSM.Part
        Dim objViewEnum As TSM.UI.ModelViewEnumerator
        Dim objView As TSM.UI.View

        appModel = New TSM.Model

        'change the user field 1 attribute
        For Each objModel In appModel.GetModelObjectSelector.GetAllObjects
            objPart = TryCast(objModel, Tekla.Structures.Model.Part)
            If IsNothing(objPart) = False Then
                objPart.SetUserProperty("USER_FIELD_1", "Show")
            Else
                objModel.SetUserProperty("USER_FIELD_1", "Hide")
            End If
        Next

        'change the view filter
        objViewEnum = TSM.UI.ViewHandler.GetAllViews
        While objViewEnum.MoveNext
            objView = objViewEnum.Current
            objView.ViewFilter = "MyNewFilter"
            objView.Modify()
        End While

        appModel = Nothing
        objModel = Nothing
        objPart = Nothing
        objView = Nothing
        objViewEnum = Nothing
    End Sub

Lines 13~20 loop through all the objects in the model. If the object is a part, the “user field 1” attribute is set to “Show”. For all other objects the “user field 1” attribute is set to “Hide”.

Lines 23~28 loop through all the views in the model and change the view filter to “MyNewFilter” which was defined in step 2. By changing the view filters, all objects whos “user field 1” is not set to “show” will be hidden from the model.

Result:
Blog_Tekla_API_HideShowObjects_4
You can download the sample file and code used in this article from the link below:

See also:

If you need assistance with your Tekla model, or you are looking for a Tekla Open API programmer to hire feel free to contact me. Also please visit my home page  www.software-solutions-online.com

One thought on “Tekla Open API, Hide/Show Objects in Model”

Leave a Reply

Your email address will not be published. Required fields are marked *