Tekla Structures API (Delphi): Connectivity and Simple Examples
Initially, it was planned to integrate with Tekla Structures specifically 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 come in handy the result obtained when working with Delphi.
If the Tekla Structures program is installed correctly, then in Project-> Import Type Library ... we find:
Most likely, they will not be installed immediately and you will have to change several Class names . Remember to connect Tekla_Structures_TLB and Tekla_Structures_Model_TLB in uses to the project.
To connect, it is necessary that Tekla Structures is started and the required model is opened in it.
There are several options for obtaining objects from the model:
Please note that in all cases, model elements are taken with repetition, i.e. if the assembly K-1 occurs five times in the model, then in objEnum it will meet as many times.
When writing the code, we used the api help distributed with Tekla Structures.
Perhaps someone will come in handy the result obtained when working with Delphi.
Connect Tekla Structures Libraries
If the Tekla Structures program is installed correctly, then in Project-> Import Type Library ... we find:
- Tekla_Structures (Version __)
- Tekla_Structures_Model (Version __)
Most likely, they will not be installed immediately and you will have to change several Class names . Remember 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 started and the required model is opened 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;
Please note that in all cases, model elements are taken with repetition, i.e. if the assembly K-1 occurs five times in the model, then in objEnum it will meet as many times.
Analysis of the obtained model objects
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, we used the api help distributed with Tekla Structures.