Addon Creation for Blender 2.8

python
addons

#1

Hi, I want to create an Addon for blender 2.8 and I use the sample: “Addon Add Object”.
I want to understand what is it the “AddObjectHelper”.
Do you have a suggestion for me where I can find the documentation because I have searched with google without results. I want a guide for plug-in development for blender 2.8


#2

Here is how I do it.

Go into the addons/addons-contrib folder and do full text search in for the keywords.

You can also download as many addons as possible, put them in a git repo or something then regularly search for what you are looking for. Most likely someone else already used what you are looking for so you can see how they did it.

There is also this introduction


#3

Hi, I see the video, and with your idea I create this code:
bl_info = {
“name”: “Simple Add-on Template”,
“author”: “Marco Mameli”,
“location”: “View3D > Add > Mesh > Generate”,
“version”: (1, 0, 0),
“blender”: (2, 80, 0),
“description”: “Starting point for new add-ons.”,
“category”: “Add Mesh”
}
import bpy
import bmesh
from bpy.types import Operator
from bpy.types import Panel

def add_pointcloud(self, context, naming):
    # qui scrivo i miei calcoli
    obj = context.active_object
    mycollection = bpy.data.collections.new("MyPointCloudCollection")
    bpy.context.scene.collection.children.link(mycollection)
    me = obj.data
    bm = bmesh.new()
    bm.from_mesh(me)
    bmFaces = []

    for face in bm.faces:
        faceLocation = face.calc_center_median()
        print(faceLocation)
        bmFaces.append(obj.matrix_world @ faceLocation) # la @ è il prodotto vettoriale
    for vertex in bm.verts:
        print(vertex.co)
        bmFaces.append(obj.matrix_world @ vertex.co)

    me = bpy.data.meshes.new(obj.name + 'Mesh' + naming)
    ob = bpy.data.objects.new(obj.name + '_PointCloud_' + naming, me)
    ob.show_name = True
    bpy.data.collections['MyPointCloudCollection'].objects.link(ob)
    me.from_pydata(bmFaces, [], [])
    me.update()
    ob.select_set(True)
    
class OBJECT_OT_add_PointCloud_with_noise(Operator):
    """ Create a Point Cloud """
    bl_idname = "object.add_mesh_pointcloud_with_noise"
    bl_label = "Add Mesh object that represent a Point Cloud"
    bl_options = {'REGISTER', 'UNDO'}
    
    def execute(self,context): # operazioni da eseguire
        # MAI METTERE IL CODICE QUI DENTRO DIRETTAMENTE
        print("Sono in with noise")
        add_pointcloud(self, context, "with_noise")
        
        return {'FINISHED'}

class OBJECT_OT_add_PointCloud(Operator):
    """ Create a Point Cloud """
    bl_idname = "object.add_mesh_pointcloud"
    bl_label = "Add Mesh object that represent a Point Cloud"
    bl_options = {'REGISTER', 'UNDO'}
    
    def execute(self,context): # operazioni da eseguire
        # MAI METTERE IL CODICE QUI DENTRO DIRETTAMENTE
        print("sono in no noise")
        add_pointcloud(self, context, "no_noise")
        
        return {'FINISHED'}
    
    def draw(self,context):
        layout = self.layout
        
        scene = context.scene
        
        layout.label(text="Pointcloud option")
        
        row = layout.row()
        row.prop(scene, "frame_star")
        
        layout.label(text="Big Button:")
        row = layout.row()
        row.scale_y = 1.0
        row.operator("object.add_mesh_pointcloud_with_noise")
    
# creo il bottone da aggiungere al menu di blender
def add_pointcloud_button(self, context):
        self.layout.operator(OBJECT_OT_add_PointCloud.bl_idname, text="Generate Point Cloud",
        icon='PLUGIN')
    
# creo il link al manuale
def add_pointcloud_manual_map():
        url_manual_prefix=""
        url_manual_mapping = (("bpy.ops.mesh.add_pointcloud", "editors/edview/object"),)
        return url_manual_prefix, url_manual_mapping

# Options panel for addon
class OBJECT_PT_add_PointCloud_properties(Panel):
    bl_label = "Properties Layout"
    bl_idname = "SCENE_PT_layout_PointCloud_properties"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"
    
    def draw(self,context):
        layout = self.layout
        
        scene = context.scene
        
        layout.label(text="Pointcloud option")
        
        row = layout.row()
        row.prop(scene, "frame_star")
        
        layout.label(text="Big Button:")
        row = layout.row()
        row.scale_y = 3.0
        row.operator("render.render")
   
   
classes = [OBJECT_OT_add_PointCloud, OBJECT_PT_add_PointCloud_properties, OBJECT_OT_add_PointCloud_with_noise]        
def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.utils.register_manual_map(add_pointcloud_manual_map)
    bpy.types.VIEW3D_MT_mesh_add.append(add_pointcloud_button) 


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)
    bpy.utils.register_manual_map(add_pointcloud_manual_map)
    bpy.types.VIEW3D_MT_mesh_add.remove(add_pointcloud_button)
    

if __name__ == "__main__":
    register()

But my panel is not show if I don’t put the draw function in the operator and the first operator is not registered.
How can I fix this?