From c4127afa729e365957cce0b58293a4edf2b2c0cf Mon Sep 17 00:00:00 2001 From: theTaikun <43371347+theTaikun@users.noreply.github.com> Date: Sat, 11 Sep 2021 14:58:43 -0400 Subject: [PATCH 1/4] Keep track of plot min in addition to max --- plot.py | 12 ++++++++++-- properties.py | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plot.py b/plot.py index 489626b..a1cbfbb 100644 --- a/plot.py +++ b/plot.py @@ -107,13 +107,17 @@ def create_curve(self, coords_list): spline = self.spline spline.points.add(len(coords_list) -1 ) for i, val in enumerate(coords_list): - spline.points[i].co = (val + [0.0] + [1.0]) + spline.points[i].co = (val + [0.0] + [1.0]) # where val is [x, y], followed by + [z] + [w] # Size of Empty same for all axis => set as max of x and y value + min_x = min(coords_list)[0] + min_y = min(coords_list, key=lambda x: x[1])[1] max_x = max(coords_list)[0] # Max of nested list checks first val max_y = max(coords_list, key=lambda x: x[1])[1] # Funct to check max by second val, and return that val self.root.empty_display_size = max(max_x, max_y) # compares the 2 maxes + self.root.plotrock_settings.min_x = min_x + self.root.plotrock_settings.min_y = min_y self.root.plotrock_settings.max_x = max_x self.root.plotrock_settings.max_y = max_y self.crv.plotrock_csv = self.csv_textdata @@ -133,7 +137,7 @@ def create_obj(self): spline.use_smooth = False self.crv = crv self.spline = spline - self.obj = bpy.data.objects.new('object_name', crv) + self.obj = bpy.data.objects.new('plot', crv) self.obj.location[2] = 0.5 self.obj.parent = self.root bpy.data.scenes[0].collection.objects.link(self.obj) @@ -273,10 +277,14 @@ def update_curve(self): def update_axis(self): coords_list = self.pos_list # Size of Empty same for all axis => set as max of x and y value + min_x = min(coords_list)[0] # Max of nested list checks first val + min_y = min(coords_list, key=lambda x: x[1])[1] # Funct to check max by second val, and return that val max_x = max(coords_list)[0] # Max of nested list checks first val max_y = max(coords_list, key=lambda x: x[1])[1] # Funct to check max by second val, and return that val self.root.empty_display_size = max(max_x, max_y) # compares the 2 maxes + self.root.plotrock_settings.min_x = min_x + self.root.plotrock_settings.min_y = min_y self.root.plotrock_settings.max_x = max_x self.root.plotrock_settings.max_y = max_y diff --git a/properties.py b/properties.py index e1429cc..d146b69 100644 --- a/properties.py +++ b/properties.py @@ -13,6 +13,8 @@ ) class RootSettings(bpy.types.PropertyGroup): + min_x: bpy.props.FloatProperty() + min_y: bpy.props.FloatProperty() max_x: bpy.props.FloatProperty() max_y: bpy.props.FloatProperty() x_axis_label: bpy.props.PointerProperty(type=bpy.types.Object) From 708cd3cb8d561c31383b5b664ca2fe6f56e9e7cf Mon Sep 17 00:00:00 2001 From: theTaikun <43371347+theTaikun@users.noreply.github.com> Date: Sat, 11 Sep 2021 16:43:08 -0400 Subject: [PATCH 2/4] Place plots w/i range w/ opt. override panel entry Necessary for plots with large values - home prices - population size - etc... --- plot.py | 14 ++++++++++++++ ui_panel.py | 3 +++ 2 files changed, 17 insertions(+) diff --git a/plot.py b/plot.py index a1cbfbb..a7fa95f 100644 --- a/plot.py +++ b/plot.py @@ -68,6 +68,7 @@ def execute(self, **args): # execute() is called when running the operato print("no class obj") self.create_obj() self.create_curve(self.pos_list) + self.center_curve(self.obj) if(self.has_headers): print("x-axis: {}, y-axis: {}".format(self.headers[0], self.headers[1])) self.create_axis_text() @@ -77,6 +78,19 @@ def execute(self, **args): # execute() is called when running the operato return {'FINISHED'} + def center_curve(self, curv_obj): + driver_x = curv_obj.driver_add("location", 0) + var = driver_x.driver.variables.new() + driver_x.driver.expression = "-var" + var.targets[0].id = self.root + var.targets[0].data_path = "plotrock_settings.min_x" + + driver_y = curv_obj.driver_add("location", 1) + var = driver_y.driver.variables.new() + driver_y.driver.expression = "-var" + var.targets[0].id = self.root + var.targets[0].data_path = "plotrock_settings.min_y" + def create_axis_text(self): xaxis_crv = bpy.data.curves.new(type="FONT",name="xAxisCrv") xaxis_crv.align_x = "CENTER" diff --git a/ui_panel.py b/ui_panel.py index bf5622c..ae1c113 100644 --- a/ui_panel.py +++ b/ui_panel.py @@ -131,16 +131,19 @@ def draw(self, context): col.label(text=None) col.label(text="Depth") col.label(text="Size") + col.label(text="Min") col=split.column(align=True) col.label(text="X") col.prop(root.plotrock_settings.x_axis_label.data, 'extrude', text="") col.prop(root.plotrock_settings.x_axis_label.data, 'size', text="") + col.prop(root.plotrock_settings, 'min_x', text="") col=split.column() col.label(text="Y") col.prop(root.plotrock_settings.y_axis_label.data, 'extrude', text="") col.prop(root.plotrock_settings.y_axis_label.data, 'size', text="") + col.prop(root.plotrock_settings, 'min_y', text="") else: layout.label(text="Select an Axis") From df6393b3bef3fb206271d1fcf60f0a694c476d36 Mon Sep 17 00:00:00 2001 From: theTaikun <43371347+theTaikun@users.noreply.github.com> Date: Sat, 11 Sep 2021 17:30:07 -0400 Subject: [PATCH 3/4] Allow user to toggle using min plot ranges --- plot.py | 15 +++++++++++++-- properties.py | 2 ++ ui_panel.py | 16 ++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/plot.py b/plot.py index a7fa95f..5854efb 100644 --- a/plot.py +++ b/plot.py @@ -80,16 +80,27 @@ def execute(self, **args): # execute() is called when running the operato def center_curve(self, curv_obj): driver_x = curv_obj.driver_add("location", 0) + driver_x.driver.expression = "-offset if use_min_x else 0" var = driver_x.driver.variables.new() - driver_x.driver.expression = "-var" + var.name = "offset" var.targets[0].id = self.root var.targets[0].data_path = "plotrock_settings.min_x" + var2 = driver_x.driver.variables.new() + var2.name = "use_min_x" + var2.targets[0].id = self.root + var2.targets[0].data_path = "plotrock_settings.use_min_x" driver_y = curv_obj.driver_add("location", 1) + driver_y.driver.expression = "-offset if use_min_y else 0" var = driver_y.driver.variables.new() - driver_y.driver.expression = "-var" + var.name = "offset" var.targets[0].id = self.root var.targets[0].data_path = "plotrock_settings.min_y" + var2 = driver_y.driver.variables.new() + var2.name = "use_min_y" + var2.targets[0].id = self.root + var2.targets[0].data_path = "plotrock_settings.use_min_y" + def create_axis_text(self): xaxis_crv = bpy.data.curves.new(type="FONT",name="xAxisCrv") diff --git a/properties.py b/properties.py index d146b69..c251652 100644 --- a/properties.py +++ b/properties.py @@ -13,6 +13,8 @@ ) class RootSettings(bpy.types.PropertyGroup): + use_min_x: bpy.props.BoolProperty() + use_min_y: bpy.props.BoolProperty() min_x: bpy.props.FloatProperty() min_y: bpy.props.FloatProperty() max_x: bpy.props.FloatProperty() diff --git a/ui_panel.py b/ui_panel.py index ae1c113..8d279cc 100644 --- a/ui_panel.py +++ b/ui_panel.py @@ -131,18 +131,30 @@ def draw(self, context): col.label(text=None) col.label(text="Depth") col.label(text="Size") - col.label(text="Min") + col.label(text="Use Min") col=split.column(align=True) col.label(text="X") col.prop(root.plotrock_settings.x_axis_label.data, 'extrude', text="") col.prop(root.plotrock_settings.x_axis_label.data, 'size', text="") - col.prop(root.plotrock_settings, 'min_x', text="") + col.prop(root.plotrock_settings, 'use_min_x', text="") col=split.column() col.label(text="Y") col.prop(root.plotrock_settings.y_axis_label.data, 'extrude', text="") col.prop(root.plotrock_settings.y_axis_label.data, 'size', text="") + col.prop(root.plotrock_settings, 'use_min_y', text="") + + split = layout.split() + col=split.column() + col=split.column() + if(not root.plotrock_settings.use_min_x): + col.enabled=False + col.prop(root.plotrock_settings, 'min_x', text="") + + col=split.column() + if(not root.plotrock_settings.use_min_y): + col.enabled=False col.prop(root.plotrock_settings, 'min_y', text="") else: From 25cf36a2ce8c16048d2d4cec3e073597d8d868d3 Mon Sep 17 00:00:00 2001 From: theTaikun <43371347+theTaikun@users.noreply.github.com> Date: Sat, 11 Sep 2021 17:45:36 -0400 Subject: [PATCH 4/4] Bump to version v1.0.0 All major initial features and bugfixes added First major version --- __init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index d1d058e..76e9294 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,3), - "version_code": 3, # not used by blender, but keeping track here + "version": (1,0,0), + "version_code": 4, # 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",