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.
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:
||User field 1 (USER_FIELD_1)
Save the filter under the name “MyNewFilter”:
Note: This step is one time only. Once the filter is created you will be able to use it in all other models.
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:
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
'change the view filter
objViewEnum = TSM.UI.ViewHandler.GetAllViews
objView = objViewEnum.Current
objView.ViewFilter = "MyNewFilter"
appModel = Nothing
objModel = Nothing
objPart = Nothing
objView = Nothing
objViewEnum = Nothing
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.
You can download the sample file and code used in this article from the link below:
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