efdiloreto / PyTekla

Bringing CPython power to Tekla
MIT License
7 stars 3 forks source link

Select objects by get_objects and export to IFC #6

Closed meteozcan87 closed 3 months ago

meteozcan87 commented 3 months ago

Hello,

I am trying to select objects in model in order to use it in operations class.

Here is my code. model = wrap("Model.Model") operation = wrap("Model.Operations.Operation") selector = wrap("Model.UI.ModelObjectSelector") part_objects_generator = model.get_objects_with_types(["Part", "Weld", "BoltGroup"]) selector.select(part_objects_generator)

selector.select is required a System.Collections.ArrayList but model.get_objects_with_types() creates a Python.Runtime.PythonException: 'generator'.

I tried with list(part_objects_generator) but this time I have python list class not a System.Collections.ArrayList. How can I solve this problem?

Also I need to export to IFC but I only saw export to IFC4 in operation class of Tekla API. do you know how I can export to IFC?

Thank you for your answers.

efdiloreto commented 3 months ago

Hi, try not wrapping the selector. Create an instance from the .NET object:

from Tekla.Structures.Model.UI import ModelObjectSelector
from System.Collections import ArrayList

selector = ModelObjectSelector()

Then could be necessary to unwrap your objects:

objects_to_select = ArrayList()

for part in part_objects_generator:
    unwrapped_part = part.unwrap()
    objects_to_select.Add(unwrapped_part)

selector.Select(objects_to_select)
meteozcan87 commented 3 months ago

Thank you for your answer. Yesterday I did it with another approach with only using "from pytekla import wrap". Here is my code.

from pytekla import wrap from System.Collections import ArrayList

model = wrap("Model.Model") selector = wrap("Model.UI.ModelObjectSelector")

part_objects_generator = list(model.get_objects_with_types(["Part", "BoltGroup"])) array_list = ArrayList()

for obj in part_objects_generator : array_list.Add(obj .unwrap())

selector.select(array_list) model.commit_changes()

This also works. Do you know how to export IFC but not IFC4

image

Normally Tekla has 2 export options to IFC but in the documentation of Tekla API, in Operations class, I only saw export IFC4. It would be so nice if you know how to export IFC.

efdiloreto commented 3 months ago

AFAIK IFC4 is IFC. I'm missing something?

meteozcan87 commented 3 months ago

IFC has 2 different formats, IFC2x3 and IFC4. Thus Tekla Export has 2 different export applications for each. But unfortunately operation class of Tekla API has only create IFC4 to export IFC4 files. So this is about Tekla API not PyTekla, but I wanted to ask you that maybe you know a way to export. Thank you so much for your interest.