Hey guys,
like many others the API changes have broken my scripts
I have a simple script that I used to display a UI for a character
(based on the Sintel rig)
It has a few features like:
1.bone layers visibility
2.it displays certain properties with sliders
3.and there is a few buttons to turn parts of the mesh off
I have managed to update 1 and 2 but I can’t figure out the 3 bit.
The button should invoke an operator that turns the modifier on/off in the viewport
I have tested the code in the console and it works so it is obviously something wrong with the way I am trying to invoke it
I get a error:
AttributeError: ‘NoneType’ object has no attribute ‘data’
RNA_struct_free ‘vsb_Body’ freed while holding a python reference
here is the script
import bpy
import re
class DougieProperties(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Rig Properties"
@classmethod
def poll(self, context):
try:
ob = context.active_object
return (ob.name == "Dougie_Rig")
except AttributeError:
return 0
def draw(self, context):
pose_bones = context.active_object.pose.bones
layout = self.layout
col = layout.column()
col.label(text="Body:")
#Body Rotation
col.prop(pose_bones["Body"],'rotation_euler', index=0,text="Rot X", slider=False)
col.prop(pose_bones["Body"],'rotation_euler', index=1,text="Rot Y", slider=False)
col.prop(pose_bones["Body"],'rotation_euler', index=2,text="Rot Z", slider=False)
# Body Squash
col.prop(pose_bones["Body"],'scale', index=0,text="Body Squash", slider=False)
col.label(text="Tail:")
# Tail Rotaion
col.prop(pose_bones["Tail.1"], '["rot"]', text="Tail Hinge", slider=True)
# Tail Stretch
col.prop(pose_bones["Tail.1"],'scale', index=1,text="Tail Stretch", slider=False)
# Tail Auto IK
col.prop(pose_bones["Tail.5"].constraints["AutoIK"], 'mute',text="Auto IK Tail")
class DougieLayers(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Rig Layers"
@classmethod
def poll(self, context):
try:
ob = context.active_object
return (ob.name == "Dougie_Rig")
except AttributeError:
return 0
def draw(self, context):
layout = self.layout
col = layout.column()
# Layers
root = col.row()
root.label(text="Root:")
root.prop(context.active_object.data, "layers", index=16, toggle=True, text="Root")
body = col.row()
body.label(text="Body:")
body.prop(context.active_object.data, "layers", index=0, toggle=True, text="Body")
tail = col.row()
tail.label(text="Tail:")
tail.prop(context.active_object.data, "layers", index=2, toggle=True, text="Tail")
squash = col.row()
squash.label(text="Squash:")
squash.prop(context.active_object.data, "layers", index=1, toggle=True, text="Squash")
class DougieVisib(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Visibility"
@classmethod
def poll(self, context):
try:
ob = context.active_object
return (ob.name == "Dougie_Rig")
except AttributeError:
return 0
def draw(self, context):
layout = self.layout
col = layout.column()
row = col.row(align=True)
row.operator("vsb_Body", text="Body")
row.operator("vsb_Tail", text="Tail")
def is_selected(context, names):
try:
for name in names:
if context.active_pose_bone.name == name:
return True
for bone in context.selected_pose_bones:
for name in names:
if bone.name == name:
return True
except AttributeError:
pass
return False
class OBJECT_OT_Visib_Body(bpy.types.Operator):
bl_label = "Body"
bl_idname = "vsb_Body"
def invoke(self, context, event):
for mesh in ['Dougie']:
bpy.data.objects['Dougie'].modifiers['BodyVIS'].show_viewport = not(bpy.data.objects['Dougie'].modifiers['BodyVIS'].show_viewport)
return{'FINISHED'}
class OBJECT_OT_Visib_Tail(bpy.types.Operator):
bl_label = "Tail"
bl_idname = "vsb_Tail"
def invoke(self, context, event):
for mesh in ['Dougie']:
bpy.data.objects['Dougie'].modifiers['TailVIS'].show_viewport = not(bpy.data.objects['Dougie'].modifiers['TailVIS'].show_viewport)
return{'FINISHED'}
#bpy.types.register(OBJECT_OT_Visib_Body)
#bpy.types.register(OBJECT_OT_Visib_Tail)
#bpy.types.register(DougieLayers)
#bpy.types.register(DougieVisib)
#bpy.types.register(DougieProperties)
anybody know what I’m doing wrong?
if you need the blend let me know
cheers