Exercise 5: Let the user select profile for columns
API contains Forms dialogs for profile catalog, rebar catalog, and mesh catalog to help developers of applications (and plug-ins) that have Forms and need to provide for example profile selection in UI.
You will learn how to use customized user interface controls to select profiles from the catalogs in Tekla Structures. After downloading the TSOpenAPISelfLearningExercises package from GitHub (button above), find the example code for this exercise at \Exercise5-UI-Select-Profile\ folder.
Before you start, open the project that you created in exercise 4.
Add user interface controls to Microsoft Visual Studio’s Toolbox
Open the Form1.cs[Design] tab.
On the Toolbox tab, right- click General and select Choose Items.
Click browse, navigate to \Program Files\Tekla Structures\[version]\nt\bin\dialogs\Tekla.Structures.Dialog.dll, open the Designer and click OK.
Let user select profile for columns
To get user interface controls to work, your Form must inherit from FormBase. In the Form’s constructor, call:
- On the Toolbox tab, under General, double-click ProfileCatalog to add it on your form. The item, that user selects from the dialog, will be stored to a SelectedProfile property.
Add a textbox to show the selected profile. When user types a profile to the textbox and clicks Select button, the typed profile should be selected automatically from the profile catalog dialog. Setting the property SelectedProfile to a certain value will select the value from the dialog when the dialog opens (if the value is included in the catalog).
To use the interface controls, create callbacks for the events SelectClicked and SelectionDone.
The SelectClicked event is raised when user clicks the Select button in your form. Modify the callback so that the value of SelectedProfile is set according to the value in the Form:
profileCatalog1.SelectedProfile = ColumnsProfileTextBox.Text;
- The SelectionDone event is raised when the profile or rebar selection dialog is closed. To update the text shown in your Form, use the method SetAttributeValue() and the value stored in SelectedProfile:
Modify the hardcoded values for the profile in the code.
Use values defined in the textboxes. For example:
Column.Profile.ProfileString = ColumnsProfileTextBox.Text;
- Then, bound values of controls to attributes.
- Test your application.
Your application form should look something like this: