Salome HOME
Revert "neutral fiber macro"
[modules/shaper.git] / src / PythonAddons / macros / importParameters / feature.py
old mode 100755 (executable)
new mode 100644 (file)
index c744cb1..bfe49e1
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
 # Copyright (C) 2016-2021  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 """importParameters
 Author: Nathalie Gore
 """
-import os
 
 from salome.shaper import model
-
+from salome.shaper import geom
 import ModelAPI
 import ParametersAPI
 
@@ -45,7 +43,7 @@ class importParameters(model.Feature):
 
     @staticmethod
     def FILE_ID():
-        """Returns ID of the file."""
+        """Returns ID of the file select parameter."""
         return "file_path"
 
     def getKind(self):
@@ -66,10 +64,10 @@ class importParameters(model.Feature):
     def existingParameters(self):
         """ Returns list of already existing parameters names"""
         aDoc = model.activeDocument()
-        aNbFeatures = aDoc.numInternalFeatures()
-        aNames = list()
+        aNbFeatures = aDoc.numInternalFeatures();
+        aNames = []
         for i in range(aNbFeatures):
-            aParamFeature = aDoc.internalFeature(i)
+            aParamFeature = aDoc.internalFeature(i);
             if aParamFeature is not None:
                 if aParamFeature.getKind() == ParametersAPI.ParametersAPI_Parameter.ID():
                     aNames.append(aParamFeature.name())
@@ -83,24 +81,24 @@ class importParameters(model.Feature):
         # Retrieving the user input
         apath    = self.string(self.FILE_ID())
         filepath = apath.value()
-        #print("filepath : '{}'".format(filepath))
+        #print("filepath : ", filepath)
         if filepath != "" :
-            if os.path.isfile(filepath):
-                # Creating the parameters in the current document
-                part = model.activeDocument()
-                aNames = self.existingParameters()
-                with open(filepath) as fic:
-                    for line in fic:
-                        defParameters = line.replace("\n","").split(' ')
-                        if len(defParameters) == 2 :
-                            if defParameters[0] not in aNames:
-                                model.addParameter(part, defParameters[0], defParameters[1])
-                                aNames.append(defParameters[0])
-                    fic.close()
-            else:
-                self.setError("The file '{}' does not exist".format(filepath))
-
-        return
+
+            # Creating the parameters in the current document
+            part = model.activeDocument()
+            aNames = self.existingParameters()
+
+            with open(filepath) as file:
+                for line in file:
+                    defParameters = line.replace("\n","").split(' ')
+                    if len(defParameters) == 2 :
+                        if defParameters[0] not in aNames:
+                            model.addParameter(part, defParameters[0], defParameters[1])
+                            aNames.append(defParameters[0])
+                file.close()
+                return
+
+            setError("The file does not exist")
 
     def isMacro(self):
         """Override Feature.initAttributes().