Added poll() function to fix crash with no selected objects. Grouped registration functions.

This commit is contained in:
Bart Crouch
2010-04-30 09:58:42 +00:00
parent 7fa83667fb
commit 102ba8e6de

View File

@ -20,7 +20,7 @@
bl_addon_info = { bl_addon_info = {
'name': 'Object: Cloud Generator', 'name': 'Object: Cloud Generator',
'author': 'Nick Keeline(nrk)', 'author': 'Nick Keeline(nrk)',
'version': '0.5', 'version': '0.6',
'blender': (2, 5, 3), 'blender': (2, 5, 3),
'location': 'Tool Shelf ', 'location': 'Tool Shelf ',
'description': 'Creates Volumetric Clouds', 'description': 'Creates Volumetric Clouds',
@ -41,6 +41,7 @@ Rev 0.2 Added Point Density turbulence and fixed degenerate
Rev 0.3 Fixed bug in degenerate Rev 0.3 Fixed bug in degenerate
Rev 0.4 updated for api change/changed to new apply modifier technique Rev 0.4 updated for api change/changed to new apply modifier technique
Rev 0.5 made particle count equation with radius so radius increases with cloud volume Rev 0.5 made particle count equation with radius so radius increases with cloud volume
Rev 0.6 added poll function to operator, fixing crash with no selected objects
""" """
import bpy import bpy
@ -48,9 +49,6 @@ import mathutils
from math import * from math import *
from bpy.props import * from bpy.props import *
# Deselect All
bpy.ops.object.select_all(action='DESELECT')
# This routine takes an object and deletes all of the geometry in it # This routine takes an object and deletes all of the geometry in it
# and adds a bounding box to it. # and adds a bounding box to it.
@ -281,23 +279,6 @@ class VIEW3D_PT_tools_cloud(View3DPanel):
col.label(text="a cloud.") col.label(text="a cloud.")
# col.label(active_obj["CloudMember"]) # col.label(active_obj["CloudMember"])
classes = [VIEW3D_PT_tools_cloud]
def register():
register = bpy.types.register
for cls in classes:
register(cls)
def unregister():
unregister = bpy.types.unregister
for cls in classes:
unregister(cls)
if __name__ == "__main__":
register()
class GenerateCloud(bpy.types.Operator): class GenerateCloud(bpy.types.Operator):
bl_idname = "cloud.generate_cloud" bl_idname = "cloud.generate_cloud"
@ -306,6 +287,12 @@ class GenerateCloud(bpy.types.Operator):
bl_register = True bl_register = True
bl_undo = True bl_undo = True
def poll(self, context):
if not context.active_object:
return False
else:
return (context.active_object.type=='MESH')
def execute(self, context): def execute(self, context):
# Make variable that is the current .blend file main data blocks # Make variable that is the current .blend file main data blocks
main = context.main main = context.main
@ -316,7 +303,6 @@ class GenerateCloud(bpy.types.Operator):
# Make variable scene that is current scene # Make variable scene that is current scene
scene = context.scene scene = context.scene
if active_object and active_object.type == 'MESH':
# Parameters the user may want to change: # Parameters the user may want to change:
# Number of points this number is multiplied by the volume to get # Number of points this number is multiplied by the volume to get
# the number of points the scripts will put in the volume. # the number of points the scripts will put in the volume.
@ -330,7 +316,6 @@ class GenerateCloud(bpy.types.Operator):
degenerate = degenerateCloud(active_object) degenerate = degenerateCloud(active_object)
if degenerate: if degenerate:
if active_object is not None:
# Degenerate Cloud # Degenerate Cloud
mainObj = active_object mainObj = active_object
@ -390,14 +375,10 @@ class GenerateCloud(bpy.types.Operator):
###############Create Combined Object bounds################## ###############Create Combined Object bounds##################
# Make a list of all Selected objects. # Make a list of all Selected objects.
selectedObjects = bpy.context.selected_objects selectedObjects = bpy.context.selected_objects
if not selectedObjects:
selectedObjects = [bpy.context.active_object]
# Create a new object bounds # Create a new object bounds
if selectedObjects is None:
bounds = addNewObject(scene,
"CloudBounds",
[])
else:
bounds = addNewObject(scene, bounds = addNewObject(scene,
"CloudBounds", "CloudBounds",
selectedObjects[0]) selectedObjects[0])
@ -628,11 +609,25 @@ class GenerateCloud(bpy.types.Operator):
# scene.update() # scene.update()
#bpy.ops.ptcache.bake_all(bake=False) #bpy.ops.ptcache.bake_all(bake=False)
#self.report({'WARNING'}, "Generating Cloud")
return {'FINISHED'} return {'FINISHED'}
bpy.types.register(GenerateCloud)
classes = [VIEW3D_PT_tools_cloud,
GenerateCloud]
def register():
register = bpy.types.register
for cls in classes:
register(cls)
def unregister():
unregister = bpy.types.unregister
for cls in classes:
unregister(cls)
if __name__ == "__main__": if __name__ == "__main__":
bpy.ops.cloud.generate_cloud() register()