since you can have an empty displaying a reference image in blender 2.58, i made a script (thanks to zeffii) that does this, but it would be alot easier to make it to an
add-on. on this picture you can see what i have in mind.
i watched blendercookies tutorial about add-ons, and read the add-ons part in the python snippets, but can’t get even the title to appear…
any tips are welcome
no that would be bad… well, i got that script opened, changed the title and some text, now it’s time to look into other add-ons for features i need
edit
it would be handy to look into blender itself. is there a way to navigate through the files i might need, because i see alot of files, and i just need 4 things…
another edit
an add-on in which an image is opened is fine to
zeffii
(zeffii)
July 5, 2011, 10:47am
3
Scripts/startup/bl_ui are the python files used to generate all the UI elements on the default blender.
if you look at Render->Dimensions->Time Remapping you’ll see something that you could rip out and use for the Offset value
Scripts/startup/bl_ui/properties_render.py
look at : class RENDER_PT_dimensions(RenderButtonsPanel, bpy.types.Panel): )
if you look at Render->Output->Compression
also : Scripts/startup/bl_ui/properties_render.py
look at : class RENDER_PT_output(RenderButtonsPanel, bpy.types.Panel):
i suggest pasting your code here, it will entice more people to offer advice/example code.
alright, transparanty is added, found the data in the
C:\Program Files (x86)\Blender Foundation\Blender 2.58a\2.58\scripts\startup\bl_ui\properties_data_empty.py
file, now see if the rest is there to
edit
that is easy, it’s all there, now make a button to create the empty, and set the type to image with 1 click
yay, a problem…
this line:
row.operator(“render.render”, text=“Image”, icon=‘RENDER_STILL’)
comes from the render panel data. but when i change it to
row.operator(“object.add(type = ‘EMPTY’)”, text=“Image”, icon=‘RENDER_STILL’)
it prints 'object.add(type = ‘EMPTY’). i think blender sees it as text…
help plz
also, 2 operators with one button doesn’t seem to work, looking for reference…
so making a class with all operators , so add empty and type = image and then call the class? also this is my code so far
import bpy
class OBJECT_PT_hello(bpy.types.Panel):
bl_label = "empty as reference image"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
# bl_context = "object"
def draw(self, context):
layout = self.layout
obj = context.object
box= layout.box
ob = context.object
## start
# row with text
row = layout.row()
row.label(text="select an image", icon='NONE')
row = layout.row(align=True)
row.operator("bpy.ops.Object.empty_draw_type = ' IMAGE'", text="Scale")
# row with image opener
row = layout.row(align=True)
layout.template_ID(ob, "data", open="image.open", unlink="image.unlink")
# row with offset
row = layout.row(align=True)
row.prop(ob, "empty_image_offset", text="Offset X", index=0)
row.prop(ob, "empty_image_offset", text="Offset Y", index=1)
row = layout.row(align=True)
# row with transparancy
row.prop(ob, "color", text="Transparency", index=3, slider=True)
# row with size
row = layout.row(align=True)
layout.prop(ob, "empty_draw_size", text="Size")
def register():
bpy.utils.register_class(OBJECT_PT_hello)
def unregister():
bpy.utils.unregister_class(OBJECT_PT_hello)
if __name__ == "__main__":
register()
zeffii
(zeffii)
July 5, 2011, 12:09pm
7
you should dig deeper into my second post , especially the cookbook for interface code.
anyting specific? i think the interface looks alright, i just need a button executing 2 operators…
zeffii
(zeffii)
July 5, 2011, 12:57pm
9
import bpy
class OBJECT_PT_hello(bpy.types.Panel):
bl_label = "empty as reference image"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
# bl_context = "object"
def draw(self, context):
layout = self.layout
obj = context.object
box= layout.box
ob = context.object
# row with text
row = layout.row()
row.label(text="select an image", icon='NONE')
row = layout.row(align=True)
#row.operator("bpy.ops.Object.empty_draw_type = ' IMAGE'", text="Scale")
row.operator("object.button1")
# row with image opener
row = layout.row(align=True)
layout.template_ID(ob, "data", open="image.open", unlink="image.unlink")
# row with offset
row = layout.row(align=True)
row.prop(ob, "empty_image_offset", text="Offset X", index=0)
row.prop(ob, "empty_image_offset", text="Offset Y", index=1)
row = layout.row(align=True)
# row with transparancy
row.prop(ob, "color", text="Transparency", index=3, slider=True)
# row with size
row = layout.row(align=True)
layout.prop(ob, "empty_draw_size", text="Size")
class OBJECT_OT_Button1(bpy.types.Operator):
bl_idname = "object.button1"
bl_label = "Add the damn thing"
def execute(self, context):
print("add the function call here")
# add empty
bpy.ops.object.add(type='EMPTY')
# do the special settings here
# the last added object becomes automatically selected
return('FINISHED')
def register():
bpy.utils.register_class(OBJECT_OT_Button1)
bpy.utils.register_class(OBJECT_PT_hello)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_Button1)
bpy.utils.unregister_class(OBJECT_PT_hello)
if __name__ == "__main__":
register()
zeffii
(zeffii)
July 5, 2011, 1:00pm
10
maybe replace the class OBJECT_OT_Button1 in the previous snippet with this one
class OBJECT_OT_Button1(bpy.types.Operator):
bl_idname = "object.button1"
bl_label = "Add the damn thing"
def execute(self, context):
print("add the function call here")
# add empty
bpy.ops.object.add(type='EMPTY')
mt = bpy.context.active_object
mt.empty_draw_type = 'IMAGE'
# the last added object becomes automatically selected
return('FINISHED')
pay close attention to the register and unregister functions…
somehow i get this, no button, just the text in a weird grey…
aah didn’t copy all of it , now there’s a button with a term of frustration
zeffii
(zeffii)
July 5, 2011, 1:06pm
12
Check my code. it does produce a button. Additionally, there is no function called ‘add’ in the namespace of ‘object’ . It’s slightly weird (i’m not even sure that i understand it…), but i’ll try to explain:
object in object.add refers to the namespace of the currently running script script.
so object.add_mega_function will refer to an operator called add_mega_function
yay, it works
link:
http://www.pasteall.org/22968/python
thanks alot zeffii, this’ll save me some time, although i spent a whole day on it
further improvements:
not displaying when object type is not an empty
zeffii
(zeffii)
July 5, 2011, 1:36pm
14
enjoy, you have some resources to exploit now
zeffii
(zeffii)
July 6, 2011, 1:23am
15
this detects the type of the currently active object :
import bpy
class OBJECT_PT_hello(bpy.types.Panel):
bl_label = "empty as reference image"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
# bl_context = "object"
def draw(self, context):
layout = self.layout
obj = context.object
box= layout.box
ob = context.object
# row with text
row = layout.row()
row.label(text="select an image", icon='NONE')
row = layout.row(align=True)
#row.operator("bpy.ops.Object.empty_draw_type = ' IMAGE'", text="Scale")
row.operator("object.button1")
if bpy.context.active_object.type == 'EMPTY':
# row with image opener
row = layout.row(align=True)
layout.template_ID(ob, "data", open="image.open", unlink="image.unlink")
# row with offset
row = layout.row(align=True)
row.prop(ob, "empty_image_offset", text="Offset X", index=0)
row.prop(ob, "empty_image_offset", text="Offset Y", index=1)
row = layout.row(align=True)
# row with transparancy
row.prop(ob, "color", text="Transparency", index=3, slider=True)
# row with size
row = layout.row(align=True)
layout.prop(ob, "empty_draw_size", text="Size")
class OBJECT_OT_Button1(bpy.types.Operator):
bl_idname = "object.button1"
bl_label = "Add the damn thing"
def execute(self, context):
print("add the function call here")
# add empty
bpy.ops.object.add(type='EMPTY')
mt = bpy.context.active_object
mt.empty_draw_type = 'IMAGE'
# the last added object becomes automatically selected
return('FINISHED')
def register():
bpy.utils.register_class(OBJECT_OT_Button1)
bpy.utils.register_class(OBJECT_PT_hello)
def unregister():
bpy.utils.unregister_class(OBJECT_OT_Button1)
bpy.utils.unregister_class(OBJECT_PT_hello)
if __name__ == "__main__":
register()
http://www.pasteall.org/22984/python
made an else option, so it shows ‘active object is not an empty’ if the active object isn’t an empty.
the text magicaly centered now i’ve set it to be beneath the object tools
everyone please try it and give feedback
zeffii
(zeffii)
July 6, 2011, 4:09am
17
i’ll let you struggle on that one, I have linked you to sufficient examples. if you want to develop a clean coding style don’t use masses of white-space before and after your if-statement…
link to add on
well i guess it’s finisht now. now also nothing get’s displayd if the empty draw type isn’t image
any tips appreciated though