5 from salome.shaper import model
6 from salome.shaper import geom
10 class importParameters(model.Feature):
11 """Import of Construction points
14 # Feature initializations
17 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
18 model.Feature.__init__(self)
22 """Return Id of the Feature."""
23 return "importParameters"
27 """Returns ID of the file select parameter."""
31 """Override Feature.getKind()"""
32 return importParameters.ID()
35 # Initialization of the dialog panel
37 def initAttributes(self):
38 """Override Feature.initAttributes()"""
39 # Creating the input argument of the feature
40 self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
43 # Get existing parameters names
45 def existingParameters(self):
46 """ Returns list of already existing parameters names"""
47 aDoc = model.activeDocument()
48 aNbFeatures = aDoc.numInternalFeatures();
50 for i in range(aNbFeatures):
51 aParamFeature = aDoc.internalFeature(i);
52 if aParamFeature is not None:
53 if aParamFeature.getKind() == ParametersAPI.ParametersAPI_Parameter.ID():
54 aNames.append(aParamFeature.name())
58 # Execution of the Import
61 """F.execute() -- execute the Feature"""
62 # Retrieving the user input
63 apath = self.string(self.FILE_ID())
64 filepath = apath.value()
65 #print("filepath : ", filepath)
68 # Creating the parameters in the current document
69 part = model.activeDocument()
70 aNames = self.existingParameters()
72 with open(filepath) as file:
74 defParameters = line.replace("\n","").split(' ')
75 if len(defParameters) == 2 :
76 if defParameters[0] not in aNames:
77 model.addParameter(part, defParameters[0], defParameters[1])
78 aNames.append(defParameters[0])
82 setError("The file does not exist")
85 """Override Feature.initAttributes().
88 importParameters feature is macro: removes itself on the creation transaction