Tekla Open API: Views
This article explains how you can create/modify/delete views in the model using the Tekla Open API in VB.Net. For more information about View Filters please see the article below:
Contents
Step 1:
Add reference to the Tekla.Structures.Model and the Tekla.Structures library located in the path “C:Program FilesTekla Structures20.0ntbinplugins” and manually open the tekla model. This has been covered in the article below:
Delete Existing Views:
Views are defined by their name. In the figure below you can see that the model has only 1 defined view and it has the name “MyNewView”:
Views can be deleted using the function below:
Imports TSM = Tekla.Structures.Model ''' <summary> ''' Delete All Views in the Model ''' </summary> ''' <remarks></remarks> Private Sub DeleteAllViews() Dim objViews As Tekla.Structures.Model.UI.ModelViewEnumerator objViews = TSM.UI.ViewHandler.GetAllViews While objViews.MoveNext objViews.Current.Delete() End While End Sub
The code above deletes all views in the model. Using the code below you can be more specific. The code below deletes only the view with the name “GRID A”:
Imports TSM = Tekla.Structures.Model ''' <summary> ''' Delete the View with the Name "GRID A" ''' </summary> ''' <remarks></remarks> Private Sub DeleteSpecificViews() Dim objViews As Tekla.Structures.Model.UI.ModelViewEnumerator objViews = TSM.UI.ViewHandler.GetAllViews While objViews.MoveNext If objViews.Current.Name = "GRID A" Then objViews.Current.Delete() End If End While End Sub
Creating New Views:
The code below will create a new view with the name “MyNewView”:
Imports TSM = Tekla.Structures.Model Imports TSG = Tekla.Structures.Geometry3d ''' <summary> ''' Creates a new view with the name "MyNewView" ''' </summary> ''' <remarks></remarks> Private Sub CreateNewView() Dim objView As TSM.UI.View objView = New TSM.UI.View objView.Name = "MyNewView" objView.ViewCoordinateSystem.AxisX = New TSG.Vector(1, 0, 0) objView.ViewCoordinateSystem.AxisY = New TSG.Vector(0, 1, 0) objView.WorkArea.MinPoint = New TSG.Point(-3000, -3000, 0) objView.WorkArea.MaxPoint = New TSG.Point(15000, 33000, 18000) objView.ViewDepthUp = 50000 objView.ViewDepthDown = 25000 objView.Insert() End Sub
The view will not be activated using the code above. You will be able to find it in your view list:
Modify Existing Views:
In order to modify an existing view, the first step will be to get reference to it. The rest is similar to inserting a new view:
Imports TSM = Tekla.Structures.Model Imports TSG = Tekla.Structures.Geometry3d ''' <summary> ''' Loops through all the views in the model until the "MyNewView" view is found. ''' It will then modify the view ''' </summary> ''' <remarks></remarks> Private Sub ModifyView() Dim objViews As Tekla.Structures.Model.UI.ModelViewEnumerator Dim objView As TSM.UI.View objViews = TSM.UI.ViewHandler.GetAllViews While objViews.MoveNext If objViews.Current.Name = "MyNewView" Then objView = objViews.Current objView.ViewCoordinateSystem.AxisX = New TSG.Vector(0, 1, 0) objView.ViewCoordinateSystem.AxisY = New TSG.Vector(1, 0, 0) objView.WorkArea.MinPoint = New TSG.Point(0, 0, 0) objView.WorkArea.MaxPoint = New TSG.Point(1000, 3000, 1000) objView.ViewDepthUp = 50000 objView.ViewDepthDown = 25000 objView.Modify() End If End While End Sub
The while loop on line 14 iterates through all the views in the model. Line 15 checks its name for a match. If a match is found lines 16~26 modify its properties.
You can download the sample file and code for 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