VB.Net Delete Parts, Tekla Open API

This article explains how you can delete parts in a Tekla Structure model using the Tekla Open API in VB.Net.


Step 1:

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:

In order to delete a part you will need to have a reference to the parts object. In order to get reference to the parts object. I’ve explained how this can be done in the article below:

In this example we are going to delete all the Beam type Parts in the model. This can be done using the code below:

Sub main()
Dim appModel As Tekla.Structures.Model.Model
appModel = New Tekla.Structures.Model.Model
Dim objModel As Tekla.Structures.Model.ModelObject
Dim objBeam As Tekla.Structures.Model.Beam
For Each objModel In appModel.GetModelObjectSelector.GetAllObjects
objBeam = TryCast(objModel, Tekla.Structures.Model.Beam)
If IsNothing(objBeam) = False Then
'delete beam object
objBeam.Delete()
End If
Next
'apply changes
appModel.CommitChanges()
End Sub

Before:
Delete
After:
After

The code iterates through all the ModelObjects in the current model.

Note: Aside from the objects you have drawn there will be many system objects in there as well.

The code below will try to cast the object to a Beam type. If it succeeds, then we will know that the object is of the Beam type:

objBeam = TryCast(objModel, Tekla.Structures.Model.Beam)

Note: Beams and column are both of the Beam type in the Tekla Open API.

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

One thought on “VB.Net Delete Parts, Tekla Open API”

  1. PP says:

    Thanks

Leave a Reply

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