Shaper python object references

Hi,

I was expecting this to work

from salome.shaper import model
model.begin()
partSet = model.moduleDocument()
Part_1 = model.addPart(partSet)
partdoc = Part_1.document()
a_box = model.addBox(partdoc, 1, 2, 2)
moved_box=model.addTranslation(partdoc, [a_box],   vector = [0,0, 4] , keepSubResults = True)

That fails with this error
TypeError: in method ‘addTranslation’, argument 2 of type ‘std::list< ModelHighAPI_Selection,std::allocator< ModelHighAPI_Selection > > const &’

what am I doing wrong?

The code works by replacing the last line with this

moved_box=model.addTranslation(partdoc, [model.selection("COMPOUND", "all-in-"+a_box.name())],   vector = [0,0, 4] , keepSubResults = True)

But that makes the code hard to read and maintain, how do you know what name the module is using for the model.selection function?

Is there a better way of doing this?

thanks for your help

Hi,

you were almost there. Instead of passing a_box (which is the feature itself), just pass a_box.result():

moved_box=model.addTranslation(partdoc, [a_box.result()],   vector = [0,0, 4] , keepSubResults = True)

You can also use .results() if there are several results. To select last results from compounds or compsolids, use what is in the script from this message.

Other ways of selecting sub-shapes are described in this message.

Christophe

Many thanks Christophe that works.

1 Like