⬆️ ⬇️

Tekla Structures API (Delphi): Connection and Simple Examples

Originally planned to integrate with Tekla Structures on Delphi. But after some work was done in this direction, it was decided to switch to c # (see Tekla Structure API (c #): connecting and receiving a tree of objects ).



Perhaps someone will benefit from the result obtained when working with Delphi.



Connect Tekla Structures libraries



If the program Tekla Structures is installed correctly, then in the Project-> Import Type Library ... we find:





Most likely, they will not be installed immediately and you will have to change several Class names . Do not forget to connect Tekla_Structures_TLB and Tekla_Structures_Model_TLB in uses to the project.

')

Connect to Tekla Structures



To connect, it is necessary that Tekla Structures is running and the model you want to open in it.



procedure TeklaConnect; var appModel: TModel; pi: ProjectInfo; mi: ModelInfo; mainInfo: String; begin appModel := TModel.Create(self); //    Tekla  if appModel.GetConnectionStatus then //   begin pi := appModel.GetProjectInfo; //    - , ,   .. mi := appModel.GetInfo; //    -      mainInfo := 'ModelName: ' + mi.ModelName; mainInfo := mainInfo + ' ModelPath: ' + mi.ModelPath; mainInfo := mainInfo + ' ProjectNumber: ' + pi.ProjectNumber; end end; 


Getting model objects



There are several options for obtaining objects from the model:



 procedure TeklaConnect; var objEnum: ModelObjectEnumerator; appModel: TModel; mainInfo: String; begin ... objEnum := appModel.GetModelObjectSelector.GetAllObjects; // №1 objEnum := appModel.GetModelObjectSelector.GetAllObjectsWithType(ModelObjectEnum_BEAM); // №2 mainInfo := mainInfo + ' Size: ' + IntToStr(objEnum.GetSize); end; 


Note that in all variants, the model elements are taken with repetition, i.e. if the K-1 assembly occurs in the model five times, then it will meet as many times in objEnum.



Analysis of the received objects of the model



 procedure TeklaConnect; var appModel: TModel; objEnum, objEnumChild: ModelObjectEnumerator; objModel: ModelObject; BeamObject: Beam; objectInfo: String; p: Profile; m: Material; profile, material: WideString; length,profile_width: Double; begin objEnum := appModel.GetModelObjectSelector.GetAllObjects; while (objEnum.MoveNext) do begin if objEnum.Current <> nil then begin objModel := objEnum.Current; profile := ''; objModel.GetReportProperty('PROFILE',profile); //    - , ,   . material := ''; objModel.GetReportProperty('MATERIAL',material); //,     length := 0.0; objModel.GetReportProperty_2('LENGTH',length); // profile_width := 0.0; objModel.GetReportProperty_2('PROFILE.WIDTH',profile_width); // objEnumChild := objModel.GetChildren; //    end; end; //    objEnum := appModel.GetModelObjectSelector.GetAllObjectsWithType(ModelObjectEnum_BEAM); while (objEnum.MoveNext) do begin BeamObject := objEnum.Current as Beam; if (BeamObject <> nil) then begin p := BeamObject.Profile; //    - , ,   . m := BeamObject.Material; //,     objectInfo := BeamObject.GetPartMark; objectInfo := objectInfo + ' ' + p.ProfileString + ' ' + m.MaterialString; objEnumChild := BeamObject.GetChildren; //    end; end; end; 


When writing the code, the api reference was used, distributed with Tekla Structures.

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



All Articles