API Reference
Wrappers#
BaseWrapper
#
A base wrapper for Tekla Structures API objects.
This class provides a more Pythonic interface for interacting with Tekla Structures software.
When an attribute is accessed, the class uses the __getattr__
and __getattribute__
methods to convert the attribute to a more Pythonic format.
This class also uses the wrap
function to automatically convert wrapped objects to their internal Tekla.Structures format when they are set as attributes.
When a C# IEnumerator instance is returned, this class converts it to a Python generator. Similarly, when an IDictionary subclass is returned, this class converts it to a Python dictionary.
References#
https://developer.tekla.com/tekla-structures/api/22/8180
Source code in pytekla\wrappers.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
__init__(tekla_object)
#
Initializes the class using a Tekla API object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tekla_object |
Tekla.Structures object
|
The object to wrap. |
required |
unwrap()
#
Get the original Tekla Structures object that is wrapped by this class or subclass instance.
Returns:
Type | Description |
---|---|
Tekla.Structures object
|
The original Tekla Structures object. |
Examples:
Source code in pytekla\wrappers.py
__repr__()
#
Return a string representation of the class name of the wrapped Tekla object.
Returns:
Type | Description |
---|---|
str
|
The string representation of the class name of the wrapped Tekla object. |
Examples:
Source code in pytekla\wrappers.py
WithUserPropertyMixin
#
Source code in pytekla\wrappers.py
get_user_property(property_name, property_type)
#
Gets the value of a user property for the given property_name
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property_name |
str
|
The name of the user property. |
required |
property_type |
type
|
The type of the user property, must be |
required |
Returns:
Type | Description |
---|---|
str, int, float or None
|
The value of the user property. None if it was not found. |
Raises:
Type | Description |
---|---|
TypeError
|
If |
Examples:
>>> model_object_wrapper = ModelObjectWrapper(some_tekla_object)
>>> value = model_object_wrapper.get_user_property('property_name', str)
Source code in pytekla\wrappers.py
set_user_property(property_name, value)
#
Sets the user property with the specified name to the specified value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property_name |
str
|
The name of the user property. |
required |
value |
str, int or float
|
The value to set the user property to. |
required |
Returns:
Type | Description |
---|---|
bool
|
Indicates if the property was set. |
Raises:
Type | Description |
---|---|
TypeError
|
If the value type is not one of [str, int, float]. |
Examples:
>>> model_object_wrapper = ModelObjectWrapper(some_tekla_object)
>>> model_object_wrapper.set_user_property('property_name', value)
Source code in pytekla\wrappers.py
ModelObjectWrapper
#
Bases: BaseWrapper
, WithUserPropertyMixin
This class is a wrapper around Tekla.Structures.Model.ModelObject that provides helper methods for working with ModelObject's properties.
Examples:
Instantiate a ModelObjectWrapper
instance from a Tekla Structures object:
>>> from Tekla.Structures.Model import Beam
>>> from pytekla import ModelObjectWrapper
>>> wrapped_beam = ModelObjectWrapper(Beam())
Access the wrapped object's attributes using Python's preferred naming convention:
Retrieve the original Tekla Structures object from the ModelObjectWrapper
instance:
References#
https://developer.tekla.com/tekla-structures/api/22/14416
Source code in pytekla\wrappers.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
__init__(tekla_object)
#
Initializes the class using a Tekla API ModelObject object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tekla_object |
Tekla.Structures object
|
The object to wrap. |
required |
get_report_property(property_name, property_type)
#
Gets the value of a report property for the given property_name
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property_name |
str
|
The name of the report property. |
required |
property_type |
type
|
The type of the report property, must be |
required |
Returns:
Type | Description |
---|---|
str, int, float or None
|
The value of the report property. None if it was not found. |
Raises:
Type | Description |
---|---|
TypeError
|
If |
Examples:
>>> model_object_wrapper = ModelObjectWrapper(some_tekla_object)
>>> value = model_object_wrapper.get_report_property('property_name', str)
Source code in pytekla\wrappers.py
get_all_user_properties()
#
Get all user properties of the Tekla Model Object as a dictionary.
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing the user properties and their values, with keys as property names and values as property values. |
Examples:
>>> model_object_wrapper = ModelObjectWrapper(some_tekla_object)
>>> user_properties = model_object_wrapper.get_all_user_properties()
Source code in pytekla\wrappers.py
get_multiple_report_properties(string_names=None, float_names=None, int_names=None)
#
Get multiple report properties as a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_names |
list of str, optional
|
A list of string property names to retrieve. |
None
|
float_names |
list of str, optional
|
A list of float property names to retrieve. |
None
|
int_names |
list of str, optional
|
A list of integer property names to retrieve. |
None
|
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing the report properties and their values, with keys as property names and values as property values. |
Examples:
>>> model_object_wrapper = ModelObjectWrapper(some_model_object)
>>> report_properties = model_object_wrapper.get_multiple_report_properties(
... string_names=['Property1', 'Property2'],
... float_names=['Property3', 'Property4'],
... int_names=['Property5', 'Property6']
... )
>>> report_properties
{'Property1': 'value1', 'Property2': 'value2', 'Property3': 0.5, 'Property4': 2.0, 'Property5': 1, 'Property6': 3}
Source code in pytekla\wrappers.py
get_dynamic_string_property(property_name)
#
Get the value of a dynamic string property.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property_name |
str
|
The name of the property to retrieve. |
required |
Returns:
Type | Description |
---|---|
str or None
|
The value of the specified dynamic string property. None if the property was not found. |
Examples:
>>> model_object_wrapper = ModelObjectWrapper(some_model_object)
>>> value = model_object_wrapper.get_dynamic_string_property('property_name')
Source code in pytekla\wrappers.py
set_multiple_user_properties(**kwargs)
#
Sets multiple user properties with the specified names to the specified values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
dict
|
The names and values of the user properties to set. |
{}
|
Returns:
Type | Description |
---|---|
bool
|
Indicates if the properties were set. |
Examples:
>>> model_object_wrapper = ModelObjectWrapper(some_model_object)
>>> model_object_wrapper.set_multiple_user_properties(prop1="value1", prop2=123, prop3=3.14)
True
Source code in pytekla\wrappers.py
set_dynamic_string_property(property_name, value)
#
Sets the dynamic string property with the specified name to the specified value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property_name |
str
|
The name of the dynamic string property. |
required |
value |
str
|
The value to set the dynamic string property to. |
required |
Returns:
Type | Description |
---|---|
bool
|
Indicates if the property was set. |
Raises:
Type | Description |
---|---|
TypeError
|
If the value type is not str. |
Examples:
>>> model_object_wrapper = ModelObjectWrapper(some_model_object)
>>> model_object_wrapper.set_dynamic_string_property("my_property", "my_value")
True
Source code in pytekla\wrappers.py
ModelWrapper
#
Bases: BaseWrapper
Wrapper for the Tekla.Structures.Model.Model class.
This class provides a convenient interface for interacting with the Tekla Structures Model. It has several methods to get objects from the model.
References#
https://developer.tekla.com/tekla-structures/api/22/14382
Source code in pytekla\wrappers.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
|
__init__(tekla_object=None)
#
Create a new ModelWrapper instance.
Examples:
Source code in pytekla\wrappers.py
pick_objects(object_type='object', prompt=None)
#
Pick and element from the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
object_type |
str, optional
|
The object type to select. Must be one of the following options: (object, part, weld, bolt group, reinforcement). By default "object". |
'object'
|
prompt |
str, optional
|
The string to display as user guidance. By default None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If the object_type parameter is incorrect. |
Returns:
Type | Description |
---|---|
generator
|
A generator of |
Examples:
>>> model = ModelWrapper()
>>> picked_objects = model.pick_objects(object_type="part", prompt="Select parts from the model")
>>> for obj in selected_element:
>>> print(obj)
Source code in pytekla\wrappers.py
get_all_objects()
#
Get all objects in the model.
Returns:
Type | Description |
---|---|
generator
|
A generator of |
Examples:
>>> model = ModelWrapper()
>>> objects = model.get_all_objects()
>>> for obj in objects:
>>> print(obj)
Source code in pytekla\wrappers.py
get_selected_objects()
#
Get the currently selected objects in the model.
Returns:
Type | Description |
---|---|
generator
|
A generator of |
Examples:
>>> model = ModelWrapper()
>>> selected_objects = model.get_model_selected_objects()
>>> for obj in selected_objects:
>>> print(obj)
Source code in pytekla\wrappers.py
get_objects_with_types(types)
#
Get all objects in the model with specified types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
types |
iterable of str
|
The object types to retrieve. |
required |
Returns:
Type | Description |
---|---|
generator
|
A generator of |
Examples:
>>> model = ModelWrapper()
>>> objects = model.get_objects_with_types(["Part", "Weld"])
>>> for obj in objects:
>>> print(obj)
Source code in pytekla\wrappers.py
get_objects_by_filter(model_filter)
#
Get objects from model applying an existing filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_filter |
str or Tekla.Structures.Filtering.FilterExpression
|
The filter to be applied to the model. It can be a string with the filter name, or a wrapped or unwrapped object of a FilterExpression subclass. |
required |
Returns:
Type | Description |
---|---|
generator
|
A generator of |
Examples:
>>> model = ModelWrapper()
>>> filtered_objects = model.get_objects_by_filter("my filter")
>>> for obj in filtered_objects:
>>> print(obj)
Source code in pytekla\wrappers.py
get_objects_by_bounding_box(min_point_coords, max_point_coords)
#
Get objects from the model that are inside a bounding box defined by two points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_point_coords |
(x
|
The minimum point coordinates of the bounding box. |
required |
max_point_coords : (x: float, y: float, z: float) The maximum point coordinates of the bounding box.
Returns:
Type | Description |
---|---|
generator
|
A generator of |
Examples:
>>> model = ModelWrapper()
>>> min_point = (0.0, 0.0, 0.0)
>>> max_point = (10.0, 10.0, 10.0)
>>> filtered_objects = model.get_objects_by_bounding_box(min_point, max_point)
>>> for obj in filtered_objects:
>>> print(obj)
Source code in pytekla\wrappers.py
DrawingDbObjectWrapper
#
Bases: BaseWrapper
, WithUserPropertyMixin
A wrapper class for Tekla.Structures.Drawing.DataBaseObject subclasses.
Examples:
>>> from pytekla import DrawingDbOjectWrapper
>>> drawing_wrapper = DrawingDbOjectWrapper("Drawing.GADrawing")
>>> drawing_wrapper.set_user_property('property_name', 'property_value')
References#
https://developer.tekla.com/tekla-structures/api/22/10404
Source code in pytekla\wrappers.py
get_all_user_properties()
#
Return a dictionary containing all of the user-defined properties associated with this DatabaseObject object.
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing the user-defined properties, where the keys are the names of the properties and the values are their corresponding values. |
Notes#
This method retrieves all of the user-defined properties associated with this DatabaseObject object, regardless of their data type. The properties are returned as a dictionary, where the keys are the property names and the values are their corresponding values.
Examples:
>>> from pytekla import DrawingWrapper
>>> drawing_wrapper = DrawingWrapper("GADrawing")
>>> user_props = drawing_wrapper.get_all_user_properties()
>>> user_props
{'property1': 'value1', 'property2': 42, 'property3': 3.14}
Source code in pytekla\wrappers.py
DrawingHandlerWrapper
#
Bases: BaseWrapper
A wrapper class for Tekla.Structures.Drawing.DrawingHandler.
Examples:
>>> from pytekla import DrawingHandlerWrapper
>>> drawing_handler = DrawingHandlerWrapper()
>>> drawings = list(drawing_handler.get_drawings())
>>> active_drawing = drawing_handler.get_active_drawing()
References#
https://developer.tekla.com/tekla-structures/api/22/10647
Source code in pytekla\wrappers.py
__init__(tekla_object=None)
#
Create a new DrawingHandlerWrapper instance.
Examples:
Source code in pytekla\wrappers.py
get_drawings()
#
Generate all of the drawing objects in the Tekla model.
Returns:
Type | Description |
---|---|
generator
|
A generator of |
Examples:
>>> from pytekla import DrawingHandlerWrapper
>>> drawing_handler = DrawingHandlerWrapper()
>>> drawings = list(drawing_handler.get_drawings())
Source code in pytekla\wrappers.py
get_active_drawing()
#
Return the active drawing object, if one is currently selected.
Returns:
Type | Description |
---|---|
DrawingDbObjectWrapper or None
|
A DrawingWrapper object for the currently active drawing, or None if no drawing is currently active. |
Examples:
>>> from pytekla import DrawingHandlerWrapper
>>> drawing_handler = DrawingHandlerWrapper()
>>> active_drawing = drawing_handler.get_active_drawing()
Source code in pytekla\wrappers.py
wrap(some_object, *args, detect_types=True)
#
Wrap the given object with a suitable wrapper class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
some_object |
object
|
The object to wrap. |
required |
args |
Any values that you want to pass to the wrapped object to instanciate it. |
()
|
|
detect_types |
bool, optional
|
Whether to automatically detect the type of the object and wrap it with an appropriate class. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
object
|
The wrapped object. |
Notes#
This function checks if the given object is a class and returns it unchanged if so. Otherwise, if
detect_types
is True, it attempts to determine the type using the namescape path of the object and wrap it with an appropriate
class. If the object is not a string will try to wrap it with an appropriate class. If the object is not of a known type, it is returned unchanged.
The possible wrapper classes are:
-
BaseWrapper
: The base wrapper class that other wrappers inherit from. Can wrap any object in the Tekla.Structures namespace. -
ModelObjectWrapper
: A wrapper for Tekla.Structures.Model.ModelObject subclasses instances. -
ModelWrapper
: A wrapper for Tekla.Structures.Model.Model instances. -
DrawingDbObjectWrapper
: A wrapper for Tekla.Structures.Drawing.DatabaseObject subclasses instances. -
DrawingHandlerWrapper
: A wrapper for Tekla.Structures.Drawing.DrawingHandler instances.
Examples:
Source code in pytekla\wrappers.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 |
|
Data manager#
create_model_objects_dataframe(objects, report_properties=None, user_properties=None, attributes=None, use_all_user_properties=False)
#
Create a pandas DataFrame from objects based on provided properties and attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objects |
iterable of ModelObjectWrapper
|
A iterable of objects to be transformed into a DataFrame. |
required |
report_properties |
dict, optional
|
A dictionary of report properties to be extracted from each object, with key being the report property name and value being the report property type. Default is None. |
None
|
user_properties |
dict, optional
|
A dictionary of user properties to be extracted from each object, with key being the user property name and value being the user property type. Default is None. |
None
|
attributes |
list, optional
|
A list of object attributes to be extracted from each object. Default is None. |
None
|
use_all_user_properties |
bool, optional
|
A flag indicating if all user properties should be extracted from each object. If set to True, the |
False
|
Returns:
Type | Description |
---|---|
pd.DataFrame
|
A pandas DataFrame containing the extracted information. |
Examples:
>>> objects = [obj1, obj2, obj3]
>>> report_properties = {'prop1': int, 'prop2': str}
>>> user_properties = {'prop3': float, 'prop4': str}
>>> attributes = ['attr1', 'attr2', 'attr2.attr3']
>>> create_dataframe(objects, report_properties, user_properties, attributes)
prop1 prop2 prop3 prop4 attr1 attr2 attr3
0 1 A 3.14 B1 1.0 0.5 0.7
1 2 C 6.28 B2 2.0 1.0 1.1
2 3 E 9.42 B3 3.0 1.5 1.5