-
- from os.path import basename
- filename = basename(filepath)
- print("filename : ", filename)
-
- # Creating the construction points in the current document
- part = model.activeDocument()
- lVertices = []
-
- startPoint = None
-
- with open(filepath) as file:
- for line in file:
- coord = line.split(' ')
- x = float(coord[0]); y = float(coord[1]); z = float(coord[2]);
- point = model.addPoint(part, x,y,z); point.execute(True)
- if startPoint == None : startPoint = point
- vertex = model.addVertex(part, [point.result()]); vertex.execute(True)
- lVertices.append(vertex.result())
- file.close()
- compound = model.addCompound(part, lVertices)
- compound.execute(True)
- folder = model.addFolder(part, startPoint, compound)
- folder.setName(filename)
- return
-
- setError("The file does not exist")
+ if os.path.isfile(filepath):
+ part = model.activeDocument()
+ if self.lfeatures :
+ for feature in self.lfeatures:
+ part.removeFeature(feature.feature())
+ self.lfeatures = list()
+ model.removeFolder(self.folder)
+
+ filename = os.path.basename(filepath)
+ nameRes = "Points_" + filename
+
+ # Creating the construction points in the current document
+ lVertices = list()
+
+ with open(filepath) as fic:
+ for line in fic:
+ coord = line.split(self.separator)
+ if len(coord) != 3:
+ return
+ point = model.addPoint(part, float(coord[0]),float(coord[1]),float(coord[2]))
+ point.execute(True)
+ self.lfeatures.append(point)
+ #vertex = model.addVertex(part, [point.result()]); vertex.execute(True); self.lfeatures.append(vertex)
+ lVertices.append(point.result())
+ fic.close()
+ compound = model.addCompound(part, lVertices)
+ compound.execute(True)
+ self.lfeatures.append(compound)
+ compound.result().setName(nameRes)
+ self.folder = model.addFolder(part, self.lfeatures[0], compound)
+ self.folder.setName(nameRes)
+ else:
+ self.setError("The file '{}' does not exist".format(filepath))
+
+ return