Back to index

salome-smesh  6.5.0
SMESH_test5.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #  File   : SMESH_test5.py
00025 #  Module : SMESH
00026 #
00027 import salome
00028 import smesh
00029 import SALOMEDS
00030 import CORBA
00031 import os
00032 import os.path
00033 
00034 smesh.SetCurrentStudy(salome.myStudy)
00035 
00036 def SetSObjName(theSObj,theName) :
00037     ok, anAttr = theSObj.FindAttribute("AttributeName")
00038     if ok:
00039         aName = anAttr._narrow(SALOMEDS.AttributeName)
00040         #print aName.__dict__
00041         aName.SetValue(theName)
00042 
00043 def ConvertMED2UNV(thePath,theFile) :
00044     anInitFileName = thePath + theFile
00045     aMeshes,aResult = smesh.CreateMeshesFromMED(anInitFileName)
00046     print aResult, aMeshes
00047 
00048     for iMesh in range(len(aMeshes)) :
00049         aMesh = aMeshes[iMesh]
00050         print aMesh.GetName(),
00051         aFileName = anInitFileName
00052         aFileName = os.path.basename(aFileName)
00053         aMesh.SetName(aFileName)
00054         print aMesh.GetName()
00055 
00056         aOutPath = '/tmp/'
00057         aFileName = aOutPath + theFile + "." + str(iMesh) + ".unv"
00058         aMesh.ExportUNV(aFileName)
00059         aMesh = smesh.CreateMeshesFromUNV(aFileName)
00060         print aMesh.GetName(),
00061         os.remove(aFileName)
00062         aFileName = os.path.basename(aFileName)
00063         aMesh.SetName(aFileName)
00064         print aMesh.GetName()
00065 
00066 aPath = os.getenv('DATA_DIR') + '/MedFiles/'
00067 aListDir = os.listdir(aPath)
00068 print aListDir
00069 
00070 for iFile in range(len(aListDir)) :
00071     aFileName = aListDir[iFile]
00072     aName,anExt = os.path.splitext(aFileName)
00073     if anExt == ".med" :
00074         aFileName = os.path.basename(aFileName)
00075         print aFileName
00076         ConvertMED2UNV(aPath,aFileName)
00077         #break
00078 
00079 salome.sg.updateObjBrowser(1)