Personal tools
You are here: Home Forum How to use Salome? How to define points in a python script

How to define points in a python script

Up to How to use Salome?
  • How to define points in a python script

    Posted by Alex at July 18. 2009

    Hi Forum

     

    I have two questions

     

    I would like to know how one can define a set of points ( 240 to be more exact, each one with 12 digits precision ) which I have obtained from a run of XFoil ( they define a wing profile ) inside Salome Geometry...?

     

    I really do not feel much "at ease" into typing 2880 keystrokes in the gui to define points ....   :( 

    Can someone help me on this...?

    The other issue is on how do i define a curve from an equation ( a 3d twisted curve, like a spiralling helix ( xy spiral protruding helically in Z )

    Is there a way to do this in python... ?

     

    Thanks in advance

     

    Alex

     

     

     

     

    • Re: How to define points in a python script

      Posted by Roman Gášpár at February 27. 2013

      Hello guys

      I have a small problem with TUI...I understand the  philosophy, but I want to use variables as well. So my problem is that I dont know how to import variable into sketch script:

      import GEOM

      import geompy

      import math

      import SALOMEDS

       

       

      inRad = 110.5000000

       

      geompy.init_geom(theStudy)

       

      O = geompy.MakeVertex(0, 0, 0)

      OX = geompy.MakeVectorDXDYDZ(1, 0, 0)

      OY = geompy.MakeVectorDXDYDZ(0, 1, 0)

      OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)

      geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)

      Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F 0.000000 0.000000:TT 0.000000 inRad :R -45:C 65.300000 100.000000:R -55:L 100.000000:WW", geomObj_1 )

       

      geompy.addToStudy( O, 'O' )

      geompy.addToStudy( OX, 'OX' )

      geompy.addToStudy( OY, 'OY' )

      geompy.addToStudy( OZ, 'OZ' )

      geompy.addToStudy( Sketch_1, 'Sketch_1' )

       

       

       

      if salome.sg.hasDesktop():

        salome.sg.updateObjBrowser(1)

      The error report is this one:

      File "<input>", line 1, in <module>

      File "/home/gaspar/salome/Radial segmemt/studyBeta1_Forceskript3.py", line 80, in <module>

      Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F 0.000000 0.000000:TT 0.000000 inRad :R -45:C 65.300000 100.000000:R -55:L 100.000000:WW", geomObj_1 )

      File "/home/gaspar/salome/appli_V6_6_0/bin/salome/geompyDC.py", line 1765, in MakeSketcherOnPlane

      RaiseIfFailed("MakeSketcherOnPlane", self.CurvesOp)

      File "/home/gaspar/salome/appli_V6_6_0/bin/salome/geompyDC.py", line 102, in RaiseIfFailed

      raise RuntimeError, Method_name + " : " + Operation.GetErrorCode()

      RuntimeError: MakeSketcherOnPlane : TCollection_AsciiString::RealValue

       

      Can anybody explain that or fix it? I dont know what I have to do. 

      PS: I DONT want to use notebook !!! whit notebook and with ' - ' works.

      PS1: know anybody how to draw unclosed sketch?

       

      Thanks for your time

      Regards

      Roman 

      • Re: How to define points in a python script

        Posted by Saint Michael at February 28. 2013

        Previously Roman Gášpár wrote:

        I have a small problem with TUI...I understand the  philosophy, but I want to use variables as well. So my problem is that I dont know how to import variable into sketch script:

        Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F 0.000000 0.000000:TT 0.000000 inRad :R -45:C 65.300000 100.000000:R -55:L 100.000000:WW", geomObj_1 )

        Hi Roman

        It's very simple. The same way as C printf() but in Python, e.g. if a,b and c are Python variables, the sketcher command could be

             geompy.MakeSketcher(  "Sketcher:F %s %s:TT 0 %s" % (a,b,c

        ) )

         

        In your case:

        Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F 0.000000 0.000000:TT 0.000000 %s :R -45:C 65.300000 100.000000:R -55:L 100.000000:WW" % (inRad

        ), geomObj_1 )

         

        PS1: know anybody how to draw unclosed sketch?

        Do not append neither "WW" nor "WF" to the end of sketcher command.

        Here is the command to create a wire containing one straight edge:

        Sketch_1 = geompy.MakeSketcher("Sketcher:F 0 0:TT 40 0")

        St.Michael

    • Re: How to define points in a python script

      Posted by DAVID Gilles at July 18. 2009
      rui pereira wrote:

      Hi Forum

      I have two questions

      I would like to know how one can define a set of points ( 240 to be more exact, each one with 12 digits precision ) which I have obtained from a run of XFoil ( they define a wing profile ) inside Salome Geometry...?

      I really do not feel much "at ease" into typing 2880 keystrokes in the gui to define points ....   :( 

      Can someone help me on this...?

      The other issue is on how do i define a curve from an equation ( a 3d twisted curve, like a spiralling helix ( xy spiral protruding helically in Z )

      Is there a way to do this in python... ?

      Thanks in advance

      Alex


      Hello Alex,

      Here is a little script for you to start.

      import geompy,random,math

      nPts = 240
      print "Creating %s points"%nPts
      for i in range(nPts):
          x = random.random()
          y = random.random()
          z = random.random()
          v = geompy.MakeVertex(x, y, z)
          geompy.addToStudy(v, "Vertex_%d"%(i+1) )
      print "Done"

      print "Creating a spiral"
      nbPeriods=2
      period=1e-2
      t=0
      step=period/50
      ptList = []
      while (t<=2*math.pi*period):
          x=math.cos(2*math.pi*t/period)
          y=math.sin(2*math.pi*t/period)
          z=t*50
          t += step
          v = geompy.MakeVertex(x, y, z)
          geompy.addToStudy(v, "Helix_%f"%t )
          ptList.append(v)
      polyline = geompy.MakePolyline(ptList)
      interpol = geompy.MakeInterpol(ptList)
      geompy.addToStudy(polyline, "polyline" )
      geompy.addToStudy(interpol, "interpol" )
      print "Done"


      Here I create 240 points in the for loop. Those are random points but you can use this loop to read a file which contains your points.
      Then I calculate the coordinates of points on a helix and I use them to create points. Finally I use those points to create a curve (well 2: a polyline and an interpolate).

      Hope this will help you.

      Gilles
      • Re: How to define points in a python script

        Posted by Alex at July 19. 2009
        Hi Giles

        Thanks a lot for your reply...  :)

        Think I will have to know a lot more of Python Syntax before i can do in Salome Platform the same things that i do in ProE...   but it is worth it...

        Salome should have way more users, having a larger community would enhance experience exchanges and benefit all...

        Just one more question... my idea is to build a geometry that will be exported as *.stl to be meshed in OpenFOAM, it will then be used in an exterior flow simulation...

        Are *.stl created by Salome Platform ( Open Cascade geometry kernel ) of quality enough to be used in CFD models ( water tightness, and so...  )  ?

        Best regards

        Alex
        • Re: How to define points in a python script

          Posted by DAVID Gilles at July 19. 2009
          Hello Alex,

          Yes Python is very important in Salome. You should learn it if you want to use Salome at its best (some functions exist only in scripts, not in GUI).
          Concerning the export STL, the GEOM module has a command for this:

          Say you have created a geometry.
          import geompy
          #Export in STL ASCII:
          geompy.Export(myGeometry, "this_is_the_path_to_save.stl", "STL_ASCII";)
          #Export in STL binary:
          geompy.Export(myGeometry, "this_is_the_path_to_save.stl", "STL_Bin";)

          You should try then to import your geometry into another CAD modeler to see if it fits your need.

          By the way, a good way to work in Salome if you don't know the commands: do what you want to do in the GUI and then select File>Dump Study.
          this will create python scripts which contain the commands corresponding to what you have done in the user interface. Actually this is what I did for 2 lines above ;)
          Don't forget to have a look at the documentation as well : ther are many script examples.

          Regards,
          Gilles
          • Re: How to define points in a python script

            Posted by mohan allada at August 13. 2009

            Hello EDF,

            I was  wondering if  it  is possible to integerate  IA FEMESH package into SALOME. 

            IA_FEMESH is  develope by IOWA uinversity in USA based on VTK. This package present an

            exceptional way to mesh HEXA elments.  The only draw back is the geometry to be meshed can

            only be expressed as STL format.  STL geo is can some times be confusing to look at.  Hence I was

            thinking if the IA FEMESH is put into SALOME then one can used the IGES or STEP CAD file as a meshing

            geometery file.

            Can this be done ?

            Thanks . Do apologise if this not supposed to be suggested here.

             

             

Powered by Ploneboard
Document Actions