Skip to content

Commit

Permalink
Merge pull request #9 from theTaikun/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
theTaikun authored Sep 11, 2021
2 parents 49332d8 + 25cf36a commit 856c1d3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 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,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",
Expand Down
37 changes: 35 additions & 2 deletions plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -77,6 +78,30 @@ 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)
driver_x.driver.expression = "-offset if use_min_x else 0"
var = driver_x.driver.variables.new()
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()
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")
xaxis_crv.align_x = "CENTER"
Expand Down Expand Up @@ -107,13 +132,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
Expand All @@ -133,7 +162,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)
Expand Down Expand Up @@ -273,10 +302,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

Expand Down
4 changes: 4 additions & 0 deletions properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
)

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()
max_y: bpy.props.FloatProperty()
x_axis_label: bpy.props.PointerProperty(type=bpy.types.Object)
Expand Down
15 changes: 15 additions & 0 deletions ui_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,31 @@ def draw(self, context):
col.label(text=None)
col.label(text="Depth")
col.label(text="Size")
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, '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:
layout.label(text="Select an Axis")
Expand Down

0 comments on commit 856c1d3

Please sign in to comment.