I am new to Blender and I find it hard to find a good structure to the addon I want to create, can you help me ?
Addon’s explanation :
Input is a mesh in edit mode (object name has to be “skull”).
I create a mesh named “topo_filling” and variables (integers) “X” and “Y” I need later.
Interactive thing (manipulating “topo_filling” mesh), two buttons in toolshelf :
Button “apply” : before clicking, user has to deplace one vertex only (how to check that?), I’ll name it “VERTEX_C”. When clicking apply button, lots of calculs are done (takes time), topo_filling mesh is modified and user gets to see the result.
Button “save” : if user is satisfied with the result seen with apply button, when clicking save button, vertex “VERTEX_C” is fixed meaning it cannot be deplaced anymore (how to?) and “X” and “Y” variables are changed (how to manipulate these variables in the script ? Global variables?)
I read tutorials so I know the basics (class operator, class panel, draw, register, invoke, execute, …) but I’m still lost in all this, which classes to create, where to create topo_filling mesh and variables X and Y, how to check if topo_filling is changed, …
Quite a complex project for a beginner if you want it exactly as described. Not sure if you really need the user to move a vertex around in viewport however. You may use the 3D cursor instead…
If I understand you right, it should work similar to the stock Mesh > Add operators: user runs the operator, can adjust the parameters in the Redo panel but not change them anymore once he/she performs another action.
You basically need an operator with bl_options = {‘REGISTER’, ‘UNDO’} to enable the Redo panel. Then add X and Y as properties to your operator. You don’t need any code to enable support for the Redo panel other than above option flags (Blender will simply undo the previous execution of the operator and re-run it with the new parameters).
import bpy
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
bl_options = {'REGISTER', 'UNDO'}
x = bpy.props.FloatProperty(
name="X",
soft_min=-1000,
soft_max=1000,
default=2
)
y = bpy.props.FloatProperty(
name="Y",
soft_min=-1000,
soft_max=1000,
default=0
)
def execute(self, context):
# use 3D cursor instead of a vertex the user needs to move
loc = context.scene.cursor_location.copy()
# do something with the 2nd parameter,
# but make sure it's a copy of the 3D cursor vector,
# or you will change the actual cursor!
loc.z += self.y
# your code to create your mesh here based on the given parameters goes here
bpy.ops.mesh.primitive_plane_add(location=loc, radius=self.x)
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
Hit apply button and see the result (well, I don’t have a picture but the mesh is modified). In the calculations, the coordinates of the vertex are used in a big linear system (explaining the calculations is irrelevant here, I already did it in my code) so it takes time. Meaning we can’t do this dynamically. So that is why I came up with two buttons “apply” and “save”.
Well, I can’t use 3D cursor because it is important which vertex is deplaced and his new coordinates.
For the parameters X and Y, they are not parameters for the user, they can’t be changed by him. It’s just for my code, some global variables I’ll be working with.
But yes, my addon goes to “Add->Mesh”. Thanks @CoDEmanX for the structure
Sorry for my bad english, that is why I can’t explain well my project
Maybe invoke_props_dialog() to show a popup before execution? It would contain an IntVector property to set up the vertex. But if the user is supposed to move an arbitrary vertex around, which was created by a former run of the filling operator, then something completely different is needed. Hm…
Well the thing is, after the user deplaced a vertex and saved the result, the user can deplace another vertex and so on (the vertices already deplaced are fixed and cannot be moved anymore). And the user move arbitrary vertices.
Or I create topo_filling mesh in invoke function and manage vertices’ deplacements in execute function ?