[Bf-extensions-cvs] [2aa13cb] master: Sapling Tree Gen: Cleanup, fix warning
lijenstina
noreply at git.blender.org
Sat Apr 8 00:25:16 CEST 2017
Commit: 2aa13cb25adfe95bbc57f4c7442c91f020df5f2d
Author: lijenstina
Date: Sat Apr 8 00:24:05 2017 +0200
Branches: master
https://developer.blender.org/rBA2aa13cb25adfe95bbc57f4c7442c91f020df5f2d
Sapling Tree Gen: Cleanup, fix warning
Bumped version to 0.3.3
Fix star imports
Pep8 cleanup
Fix RNA Warning: Current value "0" matches no enum
The EnumProperty function were passed an empty list
if there were no adequate objects in the scene
===================================================================
M add_curve_sapling/__init__.py
M add_curve_sapling/utils.py
===================================================================
diff --git a/add_curve_sapling/__init__.py b/add_curve_sapling/__init__.py
index fd6f5e9..1c91c1c 100644
--- a/add_curve_sapling/__init__.py
+++ b/add_curve_sapling/__init__.py
@@ -1,4 +1,4 @@
-#====================== BEGIN GPL LICENSE BLOCK ======================
+# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -14,18 +14,18 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-#======================= END GPL LICENSE BLOCK ========================
+# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Sapling Tree Gen",
"author": "Andrew Hale (TrumanBlending), Aaron Buchler",
- "version": (0, 3, 2),
+ "version": (0, 3, 3),
"blender": (2, 77, 0),
"location": "View3D > Add > Curve",
"description": ("Adds a parametric tree. The method is presented by "
"Jason Weber & Joseph Penn in their paper 'Creation and Rendering of "
- "Realistic Trees'."),
- "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+ "Realistic Trees'"),
+ "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/Curve/Sapling_Tree",
"category": "Add Curve"}
@@ -40,14 +40,21 @@ import time
import os
import ast
-#import cProfile
-
-from mathutils import *
-from math import pi, sin, degrees, radians, atan2, copysign
-from random import random, uniform, seed, choice, getstate, setstate
-from bpy.props import *
-
-from add_curve_sapling.utils import *
+# import cProfile
+
+from bpy.types import (
+ Operator,
+ Menu,
+ )
+from bpy.props import (
+ BoolProperty,
+ EnumProperty,
+ FloatProperty,
+ FloatVectorProperty,
+ IntProperty,
+ IntVectorProperty,
+ StringProperty,
+ )
useSet = False
@@ -97,16 +104,17 @@ branchmodes = [("original", "Original", "rotate around each branch"),
("rotate", "Rotate", "evenly distribute branches to point outward from center of tree"),
("random", "Random", "choose random point")]
+
def getPresetpath():
"""Support user defined scripts directory
Find the first ocurrence of add_curve_sapling/presets in possible script paths
and return it as preset path"""
- #presetpath = ""
- #for p in bpy.utils.script_paths():
+ # presetpath = ""
+ # for p in bpy.utils.script_paths():
# presetpath = os.path.join(p, 'addons', 'add_curve_sapling_3', 'presets')
# if os.path.exists(presetpath):
# break
- #return presetpath
+ # return presetpath
# why not just do this
script_file = os.path.realpath(__file__)
@@ -114,6 +122,7 @@ def getPresetpath():
directory = os.path.join(directory, "presets")
return directory
+
def getPresetpaths():
"""Return paths for both local and user preset folders"""
userDir = os.path.join(bpy.utils.script_path_user(), 'presets', 'operator', 'add_curve_sapling')
@@ -129,7 +138,8 @@ def getPresetpaths():
return (localDir, userDir)
-class ExportData(bpy.types.Operator):
+
+class ExportData(Operator):
"""This operator handles writing presets to file"""
bl_idname = 'sapling.exportdata'
bl_label = 'Export Preset'
@@ -139,24 +149,24 @@ class ExportData(bpy.types.Operator):
def execute(self, context):
# Unpack some data from the input
data, filename, overwrite = eval(self.data)
-
-# try:
-# # Check whether the file exists by trying to open it.
-# f = open(os.path.join(getPresetpaths()[1], filename + '.py'), 'r')
-# f.close()
-# # If it exists then report an error
-# self.report({'ERROR_INVALID_INPUT'}, 'Preset Already Exists')
-# return {'CANCELLED'}
-# except IOError:
-# if data:
-# # If it doesn't exist, create the file with the required data
-# f = open(os.path.join(getPresetpaths()[1], filename + '.py'), 'w')
-# f.write(data)
-# f.close()
-# return {'FINISHED'}
-# else:
-# return {'CANCELLED'}
-
+ """
+ try:
+ # Check whether the file exists by trying to open it.
+ f = open(os.path.join(getPresetpaths()[1], filename + '.py'), 'r')
+ f.close()
+ # If it exists then report an error
+ self.report({'ERROR_INVALID_INPUT'}, 'Preset Already Exists')
+ return {'CANCELLED'}
+ except IOError:
+ if data:
+ # If it doesn't exist, create the file with the required data
+ f = open(os.path.join(getPresetpaths()[1], filename + '.py'), 'w')
+ f.write(data)
+ f.close()
+ return {'FINISHED'}
+ else:
+ return {'CANCELLED'}
+ """
fpath1 = os.path.join(getPresetpaths()[0], filename + '.py')
fpath2 = os.path.join(getPresetpaths()[1], filename + '.py')
@@ -165,7 +175,7 @@ class ExportData(bpy.types.Operator):
self.report({'ERROR_INVALID_INPUT'}, 'Can\'t have same name as built-in preset')
return {'CANCELLED'}
elif (not os.path.exists(fpath2)) or (os.path.exists(fpath2) and overwrite):
- #if (it does not exist) or (exists and overwrite) then write file
+ # if (it does not exist) or (exists and overwrite) then write file
if data:
# If it doesn't exist, create the file with the required data
f = open(os.path.join(getPresetpaths()[1], filename + '.py'), 'w')
@@ -179,10 +189,11 @@ class ExportData(bpy.types.Operator):
self.report({'ERROR_INVALID_INPUT'}, 'Preset Already Exists')
return {'CANCELLED'}
-class ImportData(bpy.types.Operator):
+
+class ImportData(Operator):
"""This operator handles importing existing presets"""
- bl_idname = 'sapling.importdata'
- bl_label = 'Import Preset'
+ bl_idname = "sapling.importdata"
+ bl_label = "Import Preset"
filename = StringProperty()
@@ -196,15 +207,15 @@ class ImportData(bpy.types.Operator):
f = open(os.path.join(getPresetpaths()[1], self.filename), 'r')
settings = f.readline()
f.close()
- #print(settings)
+ # print(settings)
settings = ast.literal_eval(settings)
- #use old attractup
+ # use old attractup
if type(settings['attractUp']) == float:
atr = settings['attractUp']
settings['attractUp'] = [0, 0, atr, atr]
- #use old leaf rotations
+ # use old leaf rotations
if 'leafDownAngle' not in settings:
l = settings['levels']
settings['leafDownAngle'] = settings['downAngle'][min(l, 3)]
@@ -212,14 +223,15 @@ class ImportData(bpy.types.Operator):
settings['leafRotate'] = settings['rotate'][min(l, 3)]
settings['leafRotateV'] = settings['rotateV'][min(l, 3)]
- #zero leaf bend
+ # zero leaf bend
settings['bend'] = 0
# Set the flag to use the settings
useSet = True
return {'FINISHED'}
-class PresetMenu(bpy.types.Menu):
+
+class PresetMenu(Menu):
"""Create the preset menu by finding all preset files
in the preset directory"""
bl_idname = "sapling.presetmenu"
@@ -234,7 +246,8 @@ class PresetMenu(bpy.types.Menu):
for p in presets:
layout.operator("sapling.importdata", text=p[:-3]).filename = p
-class AddTree(bpy.types.Operator):
+
+class AddTree(Operator):
bl_idname = "curve.tree_add"
bl_label = "Sapling: Add Tree"
bl_options = {'REGISTER', 'UNDO'}
@@ -242,16 +255,13 @@ class AddTree(bpy.types.Operator):
def objectList(self, context):
objects = []
bObjects = bpy.data.objects
-# try:
-# bObjects = bpy.data.objects
-# except AttributeError:
-# pass
-# else:
+
for obj in bObjects:
if (obj.type in ['MESH', 'CURVE', 'SURFACE']) and (obj.name not in ['tree', 'leaves']):
objects.append((obj.name, obj.name, ""))
- return objects
+ return (objects if objects else
+ [('NONE', "No objects", "No appropriate objects in the Scene")])
def update_tree(self, context):
self.do_update = True
@@ -265,419 +275,606 @@ class AddTree(bpy.types.Operator):
def no_update_tree(self, context):
self.do_update = False
- do_update = BoolProperty(name='Do Update',
- default=True, options={'HIDDEN'})
-
- chooseSet = EnumProperty(name='Settings',
+ do_update = BoolProperty(
+ name='Do Update',
+ default=True, options={'HIDDEN'}
+ )
+ chooseSet = EnumProperty(
+ name='Settings',
description='Choose the settings to modify',
items=settings,
- default='0', update=no_update_tree)
- bevel = BoolProperty(name='Bevel',
+ default='0', update=no_update_tree
+ )
+ bevel = BoolProperty(
+ name='Bevel',
description='Whether the curve is beveled',
- default=False, update=update_tree)
- prune = BoolProperty(name='Prune',
+ default=False, update=update_tree
+ )
+ prune = BoolProperty(
+ name='Prune',
description='Whether the tree is pruned',
- default=False, update=update_tree)
- showLeaves = BoolProperty(name='Show Leaves',
+ default=False, update=update_tree
+ )
+ showLeaves = BoolProperty(
+ name='Show Leaves',
description='Whether the leaves are shown',
- default=False, update=update_tree)
- useArm = BoolProperty(name='Use Armature',
+ default=False, update=update_tree
+ )
+ useArm = BoolProperty(
+ name='Use Armature',
description='Whether the armature is generated',
- default=False, update=update_tree)
- seed = IntProperty(name='Random Seed',
+ default
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list