import bpy
bpy.ops.object.select_by_type(extend=False, type='MESH') # select all mesh
selmesh = bpy.context.selected_objects # list all objects selected
cnt = 0
while cnt < len(selmesh[:]):
namem = selmesh[cnt].name
#ob = bpy.context.active_object #<-- get object active
bpy.ops.object.select_name(name=namem, extend=False) #<-- select by name
bpy.context.scene.objects.active = bpy.data.objects[namem] #<-- set object active
ob = bpy.context.active_object #<-- geting active object
bpy.ops.object.modifier_add(type='UV_PROJECT') #<-- apply the modifier
cnt += 1
and execute this, with this code
bl_info = {
"name": "My first addon test",
"description": "blablabla",
"author": "my name blabla",
"version": (0, 1),
"blender": (2, 61, 0),
"api": 31236,
"location": "View3D > Add > Mesh",
"warning": "", # used for warning icon and text in addons panel
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"
"Scripts/My_Script",
"tracker_url": "http://projects.blender.org/tracker/index.php?"
"func=detail&aid=<number>",
"category": "Add Mesh"}
import bpy
class ObjectPanel(bpy.types.Panel):
bl_label = "mio"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
def draw(self, context):
self.layout.operator("script.python_file_run", text="My button execute pyfile").filepath='/home/user/.blender/2.61/scripts/addons/algo.py'
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
if __name__ == "__main__":
register()
and dont work!!, but copy & paste in the text editor and run (in console too), works it well :S why?
I can group as many tasks into one button? Thank you.