first of all hi to everyone first post ! I've recently (10 days ago) started to learn Python specifically for Blender. Obviously I got eager to try something out and I cant (for obvious reason) find a solution to this problem. I am an absolute beginner in programming and I don't have the right jargon so please be patient with me if I said something wrong :).

What I want to achieve is having a custom panel for some extra settings under the Render Tab. I was able to do so and convert it to an Add-on (so I can have it loaded at startup) but my custom operator (that contains 2 actions) doesn't load up together with the Add-on.. I have to manually run the script but in this way I have to do it every time I log in.

I am super sure the problem is with my custom operator since in order to make this script I've basically just dug around other people/template scripts to see how they work.. without knowledge of what I am doing (I just go too excited)

all the help will be highly appreciated

bl_info = {
"name": "HTML Render Combo",
"author": "Virgil Sisoe",
"version": (1, 0),
"blender": (2, 79, 0),
"location": "Properties > Render",
"description": "Quick panel to export Documen HTML",
"warning": "",
"wiki_url": "",
"category": "Render",
}

import bpy
#DEFINE CUSTOM OPERATOR FOR HTML EXPORT
def main(context):
# WANT IM TRYING IS TO HAVE A SINGLE BUTTON DOING RENDER AND EXPORT DOCUMEN
bpy.ops.render.render()
#DOCUMEN HTML IS AN ADDON I HAVE
bpy.ops.scene.export_documen_html()

#CREATING CLASS
class SimpleOperator(bpy.types.Operator):
"""Export HTML"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"

# JUST COPIED AND PASTED FROM ANOTHER RENDER SOURCE IT IS COMPLETLY WRONG
@classmethod
def poll(cls, context):
scene = context.scene
return scene

def draw(self, context):
layout = self.layout
return {'FINISHED'}

def register():
bpy.utils.register_class(SimpleOperator)

def unregister():
bpy.utils.unregister_class(SimpleOperator)

if __name__ == "__main__":
register()

# test call
bpy.ops.object.simple_operator()

#DEFINE CUSTOM PANEL FOR EXPORT
def draw(self, context):
layout = self.layout

# ROW COLUMN LAYOUT
row = layout.row()
col = row.column(align = True)
col.scale_y = 3
row.operator("object.simple_operator", text="Render + HTML", icon='RENDER_STILL')
row.operator("scene.export_documen_html", text="HTML", icon='FILE')

# LAYOUT EXPORT PATH
scene = context.scene
box = layout.box()
row = box.row()
row.prop(scene, "documen_folderpath", text="Export Path")
row.prop(scene, "buttons.directory_browse")

#render tab path
def register():
bpy.types.RENDER_PT_render.append(draw)

def unregister():
bpy.types.RENDER_PT_render.re.remove(draw)

if __name__ == "__main__":
register()


custom_export.py file

• I can't get it to work with the way it is formatted right now, and I tried fixing indentions and still got confused about the last section. Can you fix it to look like what is working on your end? – Craig D Jones Feb 11 '18 at 5:16
• if i copy and pasted it wont work for me either... I tried to follow the instruction for posting the code spacing it 4 times but I must have done something wrong. I've included the link for the .py file at the bottom of the post – Virgil Sisoe Feb 11 '18 at 5:47
• Right off the bat, take a look at your register and unregister - you only need to combine them into one set of register and unregister at the bottom - the one that is in the middle is most likely stopping the script from reading further. – Craig D Jones Feb 11 '18 at 5:54

There are two register and unregistered functions. When running the script both are registered as the __name__ == "__main__" evaluates to True and use the version of those functions that are defined upon that time

When running as an add-on the full module is loaded and blender will handle the calls to register and unregister functions. After loading the module only the latest version of the register and unregister functions are known. Hence only the custom draw function is registered.

This can be fixed my merging the two register functions and the two unregister functions.

bl_info = {
"name": "HTML Render Combo",
"author": "Virgil Sisoe",
"version": (1, 0),
"blender": (2, 79, 0),
"location": "Properties > Render",
"description": "Quick panel to export Documen HTML",
"warning": "",
"wiki_url": "",
"category": "Render",
}

import bpy
#DEFINE CUSTOM OPERATOR FOR HTML EXPORT
def main(context):
"""for ob in context.scene.objects:
print(ob)"""
bpy.ops.render.render()
bpy.ops.scene.export_documen_html()

#CREATING CLASS
class SimpleOperator(bpy.types.Operator):
"""Export HTML"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
#CHECK
@classmethod
def poll(cls, context):
return context.active_object is not None

def execute(self, context):
main(context)
return {'FINISHED'}

#DEFINE CUSTOM PANEL FOR EXPORT
def draw(self, context):
layout = self.layout

# write the layout code below here
row = layout.row()
col = row.column(align = True)
col.scale_y = 3
#row.operator("render.render", text="Render", icon='RENDER_STILL')
row.operator("object.simple_operator", text="Render + HTML", icon='RENDER_STILL')
row.operator("scene.export_documen_html", text="HTML", icon='FILE')

scene = context.scene
box = layout.box()
row = box.row()
row.prop(scene, "documen_folderpath", text="Export Path")
row.prop(scene, "buttons.directory_browse")

#render panel path
def register():
bpy.utils.register_class(SimpleOperator)
bpy.types.RENDER_PT_render.append(draw)

def unregister():
bpy.types.RENDER_PT_render.remove(draw)
bpy.utils.unregister_class(SimpleOperator)

if __name__ == "__main__":
register()


There are other stuff missing from the file like the "scene.export_documen_html" operator.

• I'd suggest noting that when loaded as a module (ie the addon is enabled), blender calls custom_export.register() When run from the text editor (a case where __name__ == "__main__") will use register method defined at time of call, explains why it seemingly works in text editor and not when enabled as an addon. – batFINGER Feb 11 '18 at 10:45
• you absolutely right this has solve it and now it starts up properly when i log. funny enough I've tried to take away everything BUT that... . thank you very much – Virgil Sisoe Feb 11 '18 at 18:08