From 789657c2db1844d138f4ab854277479159742b35 Mon Sep 17 00:00:00 2001 From: theTaikun <43371347+theTaikun@users.noreply.github.com> Date: Mon, 23 Aug 2021 09:13:54 -0400 Subject: [PATCH 1/3] Prevent plot creation/update if CSV val causes err --- plot.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plot.py b/plot.py index 57f19b8..cafaacb 100644 --- a/plot.py +++ b/plot.py @@ -9,13 +9,19 @@ 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)) + try: + pos_list = [list(map(float, x)) for x in string_list] # convert list of strings to list of floats + except ValueError: + pos_list = None + print("pos_list: {}".format(pos_list)) return pos_list, headers # findRoot function courtesy of MMDTools addon @@ -50,6 +56,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") @@ -271,8 +279,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"} From f4d0223750a516617e8644d78cfa1b7ac8332ab6 Mon Sep 17 00:00:00 2001 From: theTaikun <43371347+theTaikun@users.noreply.github.com> Date: Fri, 27 Aug 2021 16:29:32 -0400 Subject: [PATCH 2/3] (+)ability to plot even if some values are errored previously, would not make a plot at all if any value error now, skips those error entries, and plots what it can --- plot.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plot.py b/plot.py index cafaacb..85c502a 100644 --- a/plot.py +++ b/plot.py @@ -17,13 +17,18 @@ def convertData(csv_textdata, entry_delimiter=",", has_headers=True): headers = None string_list = list(reader) print("string_list: {}".format(string_list)) - try: - pos_list = [list(map(float, x)) for x in string_list] # convert list of strings to list of floats - except ValueError: - pos_list = None + 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: From 9afb707f45956d22b5af4cba37138c8e2ddbd264 Mon Sep 17 00:00:00 2001 From: theTaikun <43371347+theTaikun@users.noreply.github.com> Date: Sat, 28 Aug 2021 10:50:28 -0400 Subject: [PATCH 3/3] Bump version number for adding error handling --- __init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 190dbc8..16765ce 100644 --- a/__init__.py +++ b/__init__.py @@ -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",