Personal tools
You are here: Home Forum Use TUI with Shaper calling results from operations

TUI with Shaper calling results from operations

Up to Use

TUI with Shaper calling results from operations

Posted by Franco Otaola at November 23. 2020

Hello,

I am trying to translate my python code from Geometry to Shaper, but I am facing an small problem that I do not understand correctly.

when I call an object that has been created just in the previous line, I do not understand how it is called in the next function.

for example:

I have created an object call "body" from a fusion

body= model.addFuse(Part_1_doc, [model.selection("SOLID", "Cylinder_2_1"), model.selection("SOLID", "Cylinder_3_1"),model.selection("SOLID", "Cylinder_4_1"),model.selection("SOLID", "Cylinder_5_1"),model.selection("SOLID", "Cylinder_6_1"),model.selection("SOLID", "Cylinder_7_1"),model.selection("SOLID", "Cylinder_8_1")], keepSubResults = False);

my problem is that if I want to call it to do a mirror of it, I can not call it directly as model.selection("SOLID","body_1")

Symmetry_XY = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "body_1")], model.selection("FACE", "PartSet/YOZ"), keepOriginal = True, keepSubResults = True)

but if I do:

Symmetry_XY = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Fuse_1")], model.selection("FACE", "PartSet/YOZ"), keepOriginal = True, keepSubResults = True)

It works correctly, as it was the first fuse operation in the code, 

for small codes it would not be a problem to follow how many fuse operations I did and use "Fuse_*" each time, but as the code grows it becomes really hard to follow this notation.

In geometry TUI I didn't have this problem for example:

body = geompy.MakeFuseList([Extrusion_2, Extrusion_3, Extrusion_4, Extrusion_5, Extrusion_6, Extrusion_7, Extrusion_8], True, True)

Plane_X = geompy.MakePlane(O, OX, 2000)

bodySym= geompy.MakeMirrorByPlane(body , Plane_X)

Re: TUI with Shaper calling results from operations

Posted by Franco Otaola at November 23. 2020

for the moment I solved adding the line body.setName("body") after the creation of body, but is there any way to have the names as the variables? or I should do this each time?

thanks

Re: TUI with Shaper calling results from operations

Posted by Christophe Bourcier at November 25. 2020

Hi,

in your code, body is a feature. You can get its results with body.results(). So, replace:

[model.selection("SOLID", "Fuse_1")]

by:

body.results()

Christophe

Re: TUI with Shaper calling results from operations

Posted by Christophe Bourcier at November 25. 2020

You can also select all the results of a feature, by selecting the feature itself. In GUI, you get the prefix "all-in" when you select the feature.

You get it in the python dump also:

model.selection("COMPOUND", "all-in-Fuse_1")

Re: TUI with Shaper calling results from operations

Posted by Christophe Bourcier at November 25. 2020

Or if you want to get all sub-results names with the python API, you can do something like in the attached script.

Attachments

Re: TUI with Shaper calling results from operations

Posted by Franco Otaola at November 25. 2020

hello christophe,

first of all,

thanks a lot for the guidance, by any chance do you know where this is explained in the documentation? I feel like I am missing things to read... ahahaha. is there any more examples of TUI codes other than https://docs.salome-platform.org/latest/gui/SHAPER/General/TUI_tutorial.html
as I post it here : 

https://www.salome-platform.org/forum/forum_10/630816576/view
for example, after mirroring a solid, (so i would say, if I understood correctly) that is a feature, so the results for example i should use:
mirror.results()
until here everything okey, but then I do several symmetries(as if i create a cube from a quarter of cube) so 3 symetries, and then i want to fuse all if I use [model.selection("COMPOUND", "all-in-Symmetry_1")] in the fuse list the fuse will fail.
something like this:(see in python file)

Box_1 = model.addBox(Part_1_doc, 10, 10, 10)

Symmetry_1 = model.addSymmetry(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("FACE", "PartSet/XOY"), keepOriginal = True, keepSubResults = True)

Symmetry_1 = model.addSymmetry(Part_1_doc, [model.selection("COMPOUND", "all-in-Symmetry_1")], model.selection("FACE", "PartSet/XOZ"), keepOriginal = True, keepSubResults = True)

Symmetry_1 = model.addSymmetry(Part_1_doc, [model.selection("COMPOUND", "all-in-Symmetry_1")], model.selection("FACE", "PartSet/YOZ"), keepOriginal = True, keepSubResults = True)

completeBody = model.addFuse(Part_1_doc, [model.selection("COMPOUND", "all-in-Symmetry_1")], removeEdges = True, keepSubResults = True)

thanks!
best regards, franco

Attachments

Re: TUI with Shaper calling results from operations

Posted by Christophe Bourcier at November 26. 2020

As you have pointed out, there is nothing about advanced python usage in the documentation yet. There are many python test files included with shaper from which I have learnt some python specifities. But I agree it is tough to learn without some explainations (that are given in training sessions). And the python API could be improved with some helper functions.

About your particular issue, you have to look at the message of the features in error (with a black-red cross on their icon).

Edit the feature Symmetry_3, the error message appears on the status bar and on the tooltip on the greyed apply icon.

Indeed, you have selected the feature Symmetry_1 but its results have been concealed by the second Symmetry feature.

So you have to change the 2nd name of "all-in-Symmetry_1" in your script to "all-in-Symmetry_2", and the third to "all-in-Symmetry_3".

Then, there is still an error in Fuse.

Indeed, Fuse expects at least 2 input arguments (well, this can be improved in a further version to allow compound of solids like in Partition). But you can use getSubSolids from the python script of my previous post to select all the solids.

You can find the fixed script in attachment.

Christophe

Attachments

Re: TUI with Shaper calling results from operations

Posted by Franco Otaola at November 26. 2020

Thanks a lot, I thought about this from the error message when doing the fusion but i tried (yeah I know it is not clean at all...) to put the list of all-in-Symmetry_1 two times (as I was fusing 16 parts instead of the 8 that wanted...)
actually I found the documentation quiet good, but there were two major thigs that are missing (and in my opinion quiet important for TUI)
1. the calling of objects, your first code already would be more than enough but giving some hints in this, as for example the "all-in-xx" i could not find it or difference of using xxx.results() as I was coming from coding in python with GEOMETRY that at least that was easier...
2. simple examples, but donne from scratch from the TUI. for example the nut example is great (I think it is from cyprien tutorial, no? great tutorials!) but the code is more like a translation from the GUI workflow (like a dump file cleaner) but not using the "shorcuts" from the TUI that would be great. for example the use of getSubSolids (that I tried to find something like that in the doc without luck....)
sorry to bother you with so many questions but I take advantage of the discussion, are there missing implemented features in SHAPER that in the doc is not shown? I was looking to a equal function for geompy.BoundingBox and geompy.AreCoordsInside without any luck in the doc.

thaks a lot for the help.
Franco

 

Previously Christophe Bourcier wrote:

As you have pointed out, there is nothing about advanced python usage in the documentation yet. There are many python test files included with shaper from which I have learnt some python specifities. But I agree it is tough to learn without some explainations (that are given in training sessions). And the python API could be improved with some helper functions.

About your particular issue, you have to look at the message of the features in error (with a black-red cross on their icon).

Edit the feature Symmetry_3, the error message appears on the status bar and on the tooltip on the greyed apply icon.

Indeed, you have selected the feature Symmetry_1 but its results have been concealed by the second Symmetry feature.

So you have to change the 2nd name of "all-in-Symmetry_1" in your script to "all-in-Symmetry_2", and the third to "all-in-Symmetry_3".

Then, there is still an error in Fuse.

Indeed, Fuse expects at least 2 input arguments (well, this can be improved in a further version to allow compound of solids like in Partition). But you can use getSubSolids from the python script of my previous post to select all the solids.

You can find the fixed script in attachment.

Christophe

 

Powered by Ploneboard
Document Actions