📜 ⬆️ ⬇️

Tekla Structure API (c #): connecting and retrieving a tree of objects

Tekla Structure ( see of.sayt ) - a system that automates the process of designing buildings. When used in large companies, it is natural to want to integrate Tekl into the already existing enterprise management system.

So, the first task is to get a tree of model objects. The tree should have the following form - model -> assemblies ( Assembly ) of which the model consists -> parts of which assemblies consist ( Part ). The object tree must be obtained from existing drawings, i.e. we will analyze the model through the prism of the list of drawings (it sounds obscure, but in the course of the article everything will become clear).

The used development system is the Visual Studio 2013 Community, c # language.

Tekla Structure has its api and even a special StartUp Package (you can download it after registering on the site), after installing it, DeveloperGuide, api help and examples appear in the directory where Tekla is installed.
')
After creating a new project, first of all we add the necessary * .dll to References. For the current task we need the following:
  1. Tekla.Structures.dll (common functions)
  2. Tekla.Structures.Model.dll (for working with the model itself)
  3. Tekla.Structures.Drawing.dll (for working with drawings)

Connect to Tekla Structure
To connect, it is necessary that Tekla Structure be launched and the required model be opened in it.

... using Tekla.Structures; using Tekla.Structures.Drawing; using Tekla.Structures.Model; ... Model model; DrawingHandler CurrentDrawingHandler; public MainForm() { model = new Model(); //    CurrentDrawingHandler = new DrawingHandler(); //    //    if (model.GetConnectionStatus() && CurrentDrawingHandler.GetConnectionStatus()) { InitializeComponent(); } else MessageBox.Show("Tekla Structures must be opened!"); } 

Getting a list of drawings


Two options have been developed for obtaining a list
  ... DrawingEnumerator drawingsEnum; if (rbSelectedDrawings.Checked) drawingsEnum = CurrentDrawingHandler.GetDrawingSelector().GetSelected(); // ,   else drawingsEnum = CurrentDrawingHandler.GetDrawings(); //    ... 

Building a tree


Here it is particularly worth noting the method of obtaining the drawing object ( Drawing ) as an object of the model ( Model ), since All information (composition, weight, length, brand, materials, etc.) is located in the model object.

To assemble:

 Assembly assembly = model.SelectModelObject(((drawingsEnum.Current as AssemblyDrawing)).AssemblyIdentifier) as Assembly; 

For details:

 Tekla.Structures.Model.Part part = model.SelectModelObject((drawingsEnum.Current as SinglePartDrawing).PartIdentifier) as Tekla.Structures.Model.Part; 

To get the parameters from the report, use the following method: ( all the available parameters can be viewed in Tekl when considering the drawing template ):

  int number = 0; assembly.GetReportProperty("MODEL_TOTAL", ref number); //    string assembly_pos = ""; assembly.GetReportProperty("ASSEMBLY_POS", ref assembly_pos); //    double thickness = 0.0; part.GetReportProperty("PROFILE.WIDTH", ref thickness); //   ... 

The very construction of the tree:

  ... NameElement = ""; ProjectInfo projectInfo = model.GetProjectInfo(); //    - , ,   .. ModelInfo modelInfo = model.GetInfo(); //    -      TreeNode parentNode = new TreeNode(); parentNode.Text = projectInfo.ProjectNumber; //   -   (  ) while (drawingsEnum.MoveNext()) //   { if (drawingsEnum.Current is AssemblyDrawing) //     { Assembly assembly = model.SelectModelObject(((drawingsEnum.Current as AssemblyDrawing)).AssemblyIdentifier) as Assembly; string assembly_pos = ""; assembly.GetReportProperty("ASSEMBLY_POS", ref assembly_pos); NameElement = assembly_pos; } else if (drawingsEnum.Current is SinglePartDrawing) //     { Tekla.Structures.Model.Part part = model.SelectModelObject((drawingsEnum.Current as SinglePartDrawing).PartIdentifier) as Tekla.Structures.Model.Part; string part_pos = ""; part.GetReportProperty("PART_POS", ref part_pos); NameElement = part_pos; } TreeNode drawingNode = new TreeNode(); drawingNode.Tag = drawingsEnum.Current; drawingNode.Text = NameElement; if (drawingsEnum.Current is AssemblyDrawing) AddChildDrawingObjectsToTreeNode(drawingNode, drawing as AssemblyDrawing); //      parentNode.Nodes.Add(drawingNode); } ... 

Getting assembly parts


Please note that the assembly has one main part assembly.GetMainPart () and many minor assembly.GetSecondaries (). We need to get both those and others.

 private void AddChildDrawingObjectsToTreeNode(TreeNode parentNode, AssemblyDrawing parentDrawing) { Assembly assembly = model.SelectModelObject(parentDrawing.AssemblyIdentifier) as Assembly; Tekla.Structures.Model.Part part = assembly.GetMainPart() as Tekla.Structures.Model.Part; string part_pos = ""; part.GetReportProperty("PART_POS", ref part_pos); TreeNode objectNode = new TreeNode(); objectNode.Tag = part; objectNode.Text = part_pos; parentNode.Nodes.Add(objectNode); ArrayList secondaries = assembly.GetSecondaries(); for (int i = 0; i < secondaries.Count; i++) { Tekla.Structures.Model.ModelObject modelObject = secondaries[i] as Tekla.Structures.Model.ModelObject; part_pos = ""; modelObject.GetReportProperty("PART_POS", ref part_pos); objectNode = new TreeNode(); objectNode.Tag = modelObject; objectNode.Text = part_pos; parentNode.Nodes.Add(objectNode); } } 

It is worth noting that from all the details ( Part ) we can also get the child elements using the method:

 ModelObjectEnumerator modelObjectEnum = part.GetChildren(); 

The first problem is solved.

Sources Used When Writing Code


  1. cadsupport.ru
  2. software-solutions-online.com
  3. topengineer.ru
  4. well and, of course, help on api, example and other data provided by Tekl itself

Source: https://habr.com/ru/post/262281/


All Articles