Skip to content

Commit

Permalink
Merge pull request #5 from theTaikun/development
Browse files Browse the repository at this point in the history
Error handling for CSV with invalid data
  • Loading branch information
theTaikun authored Aug 28, 2021
2 parents 5bc2682 + 9afb707 commit c8ab655
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "PlotRock",
"description": "Create 3D plots from CSV data",
"author": "Isaac Phillips (theTaikun)",
"version": (0,0,1),
"version_code": 1, # not used by blender, but keeping track here
"version": (0,0,2),
"version_code": 2, # not used by blender, but keeping track here
"blender": (2, 92, 0),
"location": "File > Import > Import CSV for plotting",
"tracker_url": "https://github.com/theTaikun/plotrock/issues/new",
Expand Down
20 changes: 17 additions & 3 deletions plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ def convertData(csv_textdata, entry_delimiter=",", has_headers=True):
print("converting data")
raw_data = csv_textdata.as_string()
reader = csv.reader(StringIO(raw_data), delimiter=entry_delimiter) # read csv string as csv file
print("READER: {}".format(reader))
if(has_headers):
headers = next(reader)
print("headers: {}".format(headers))
else:
headers = None
string_list = list(reader)
pos_list = [list(map(float, x)) for x in string_list] # convert list of strings to list of floats
print("string_list: {}".format(string_list))
pos_list = [i for i in sanitizeData(string_list)]
print("pos_list: {}".format(pos_list))
return pos_list, headers

def sanitizeData(data):
for i in data:
try:
x = list(map(float, i))
yield x
except:
pass

# findRoot function courtesy of MMDTools addon
def findRoot(obj):
if obj:
Expand Down Expand Up @@ -50,6 +61,8 @@ def execute(self, **args): # execute() is called when running the operato
#self.delimiter = args.get("delimiter")
self.pos_list, self.headers = convertData(self.csv_textdata, self.csv_textdata['delimiter'], self.has_headers)

if self.pos_list is None:
return {'FINISHED'}

if self.obj is None:
print("no class obj")
Expand Down Expand Up @@ -271,8 +284,9 @@ def execute(self, context):

self.pos_list, self.headers = convertData(self.csv_textdata, self.delimiter, self.has_headers)

self.update_curve()
self.update_axis()
if self.pos_list is not None:
self.update_curve()
self.update_axis()
return {"FINISHED"}


Expand Down

0 comments on commit c8ab655

Please sign in to comment.