Personal tools
You are here: Home Forum Use Python loop to handle geometry objects

Python loop to handle geometry objects

Up to Use

Python loop to handle geometry objects

Posted by TMK at December 09. 2015

Hi all,

This is very noob question but anyway I would like to make a python script for Salome to make some points and lines automatically to different locations. This script is used to help bolt pretension modelling.

The idea is that I have a bolt geometry which is imported and modified with GUI. Then script would convert GUI objects (bolt1f1 and bolt1f2)  into python objects. Then it should make new points and lines with the python objects. I managed to do this with a script (only the beginning):

boltp1=geompy.MakeVertexOnSurface(bolt1f1,0.5,0.5)
boltp1s=geompy.addToStudy(boltp1,"bolt1p1") 

But when I try to make a for loop to make this same procedure for all bolts I can not make it work. It has something to do with the fact that I now use strings insted of geometry objects:

k=1
for i in range (1,k):
    boltp1=geompy.MakeVertexOnSurface("bolt"+`i`+"f1",0.5,0.5)
    boltp1s=geompy.addToStudy(boltp1,"bolt"+`i`+"p1")

 

How can I use this kind of loop so that it makes vertex on bolt1f1 surface which is python geometry object?

I would appreciate if Someone could help me with this. I am very beginner with this kind of stuff. See attached script file.

 Br,

TMK

Attachments

Re: Python loop to handle geometry objects

Posted by Roman NIKOLAEV at December 10. 2015

Hello TMK,

You have to use FindObjectByPath or FindObjectByName to get geometrical object by name, like this:

for i in range (1,k):
    GeomObj = None
    aList = salome.myStudy.FindObjectByName("bolt"+`i`+"f1","GEOM")
    if len(aList) > 0:
        SObject = aList[0]
        GeomObj = SObject.GetObject()

    if GeomObj is not None:
        boltp1=geompy.MakeVertexOnSurface(GeomObj,0.5,0.5)
        boltp1s=geompy.addToStudy(boltp1,"bolt"+`i`+"p1")
....
....
....

OR

for i in range (1,k):
    GeomObj = None
    SObject = salome.myStudy.FindObjectByPath("/Geometry/bolt"+`i`+"f1")
    if SObject is not None:       
        GeomObj = SObject.GetObject()

    if GeomObj is not None:
        boltp1=geompy.MakeVertexOnSurface(GeomObj,0.5,0.5)
        boltp1s=geompy.addToStudy(boltp1,"bolt"+`i`+"p1")
....
....
....

Regards,
Roman.

Re: Python loop to handle geometry objects

Posted by TMK at December 13. 2015

Hi Roman,

Thank you very much for your help. The script now works, but I would like to make it even better...

Now I would like to make one group of all bolt groups (bolt1,bolt2,bolt3,bolt4...) which should include all lower elements (points). Any idea how this can be achieved, I tried MakePartition command with append command without success. Later I would like to mesh this group and make element groups into mesh automatically.

See attached dump-file .

-TMK

Attachments

Re: Python loop to handle geometry objects

Posted by Roman NIKOLAEV at December 14. 2015

Hello TMK,

Try MakeCompound command.

Regards,

Roman.

Re: Python loop to handle geometry objects

Posted by robert galp at January 17. 2018
Powered by Ploneboard
Document Actions