I have just started to teach myself Python in Blender 2.5
So hopefully this is an easy question to answer
I am using the Pantin Rig and trying to Hide different body parts with the “restrict_view”
and add this to a button that lives on the Properties Tab in the 3D view (n)
I have got this working but I can only make one object disappear with one button
this is fine for some sections of the rig but other parts are made up of more than one mesh object (eg. the Head, Neck, eyes, eylids etc)
The Way I have done it is by creating a varibale
eg:
HeadMesh = bpy.context.scene.objects['Head']
this grabs the object called “Head” and then I call it later and add it to a column button
This works, as I said, but I cannot figure out how to get the variable HeadMesh to include more that one object
This also may be a silly way of doing it - but hey, I’ve only been learning Python for a day
Can somebody help me out with calling multiple objects and changing a value on all of them?
I am still struggling with the problem but I have managed to figure some stuff out
I can Create an operator that toggles the restrict_view and add this to a button
but I still can’t figure out how to get this operator to change more than one object at a time
I did manage to solve changing a list of items all at ones - but I am working on being able to toggle the Retrict_view (the new learning point)
ie. make the operator change the value -
If it’s True then make it False
If it’s False then make it True
But would I need to make and if statement for each ob_name in the list
or is it possible to create one if statement that toggles all the objects in the list
This is an example of one if statement for each object (I don’t know if it would work, haven’t tested it yet - and it seems quite cumbersome if there are several more objects in the list)
list_of_objects_names = []
list_of_objects_names.append("Obj_1")
list_of_objects_names.append("Obj_2")
for ob_name in list_of_object_names:
if bpy.data.objects["Obj_1"].restrict_view == True
bpy.data.objects["Obj_1"].restrict_view = False
elsif bpy.data.objects["Obj_1"].restrict_view == False
bpy.data.objects["Obj_1"].restrict_view = True
if bpy.data.objects["Obj_2"].restrict_view == True
bpy.data.objects["Obj_2"].restrict_view = False
elsif bpy.data.objects["Obj_2"].restrict_view == False
bpy.data.objects["Obj_2"].restrict_view = True
The must be a better way than this
I will adapt this simple code to my situation and see if it actually works in an operator
import bpy
import re
#This class draws the Panel in the 3D view (the n properties)
class VisibilityPanel(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "Visibility"
def poll(self, context):
try:
ob = context.active_object
return (ob.name == "the_name_of_your_Object")
except AttributeError:
return 0
#this draws the layout and puts the operator in it
def draw(self, context):
layout = self.layout
col = layout.column()
row = col.row(align=True)
row.operator("vsb_Parts", text="Head")
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
#This operator toggles the visibility property of all the Meshes in the list of objects
class OBJECT_OT_Visib_Parts(bpy.types.Operator):
bl_label = "Parts"
bl_idname = "vsb_Parts"
def invoke(self, context, event):
for mesh in ['obj_1', 'obj_2','obj_3']:
bpy.data.objects[mesh].restrict_view = not(bpy.data.objects[mesh].restrict_view)
bpy.data.objects[mesh].restrict_render = not(bpy.data.objects[mesh].restrict_render)
return{'FINISHED'}
bpy.types.register(OBJECT_OT_Visib_Parts)
bpy.types.register(VisibilityPanel)
What is it good for you ask?
well if you have a character rig that you want the hide different body parts you can
(just as long as the body parts are separate objects you can easily toggle them on and off out of the way
It could also be adapted to toggle/change or display other properties in the side panel