3
$\begingroup$

How do I include a new 'Realistic Stone' item in the Add menu, Mesh submenu in this script?

bl_info = {
    "name": "Realistic Stone",
    "author": "",
    "version": (0, 0, 1),
    "blender": (2, 79, 0),
    "location": "VIEW3D > ADD > Mesh",
    "description": "Realistic Stone",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Add Mesh"}

# Imports
import bpy
from bpy import context
import bmesh

class RealisticStoneStone(bpy.types.Operator):

    def execute(self, context):

        """Realistic Stone"""
        bl_idname = "mesh.realistic_stone_add"
        bl_label = "Realistic Stone"
        bl_options = {'REGISTER', 'UNDO', 'PRESET'}

        # Mesh - Create Cubic
        bpy.ops.mesh.primitive_cube_add(location=(0.00, 0.00, 1.00))
        bpy.context.object.scale = (1, 1, 1)
        bpy.ops.object.select_all(action='TOGGLE')
        Cube = bpy.context.object
        Cube.name = 'RealisticStone'
        Object = Cube.name = 'RealisticStone'
        bpy.context.object.data.name = "RealisticStone"

        # Modifier - Multiresolution
        bpy.ops.object.modifier_add(type='MULTIRES')
        bpy.ops.object.multires_subdivide(modifier="Multires")
        bpy.ops.object.multires_subdivide(modifier="Multires")
        bpy.ops.object.multires_subdivide(modifier="Multires")
        bpy.ops.object.multires_subdivide(modifier="Multires")
        bpy.context.object.modifiers["Multires"].show_expanded = False

        # Modifier - Displace 1
        bpy.ops.object.modifier_add(type='DISPLACE')
        bpy.context.object.modifiers["Displace"].strength = 0.5
        bpy.ops.texture.new()
        bpy.data.textures["Texture.001"].type = 'VORONOI'
        bpy.data.textures["Texture.001"].noise_scale = 1
        bpy.context.object.modifiers["Displace"].show_expanded = False

        # Modifier - Displace 2
        bpy.ops.object.modifier_add(type='DISPLACE')
        bpy.context.object.modifiers["Displace"].strength = 0.25
        bpy.ops.texture.new()
        bpy.data.textures["Texture.002"].type = 'CLOUDS'
        bpy.data.textures["Texture.002"].noise_depth = 7
        bpy.context.object.modifiers["Displace.001"].show_expanded = False

        # Modifier - Displace 3
        bpy.ops.object.modifier_add(type='DISPLACE')
        bpy.context.object.modifiers["Displace"].strength = 0.01
        bpy.ops.texture.new()
        bpy.data.textures["Texture.003"].type = 'NOISE'
        bpy.context.object.modifiers["Displace.002"].show_expanded = False

    def invoke(self, context, event):
        return self.execute(context)

def draw_item(self, context):
    self.layout.operator_context = 'INVOKE_DEFAULT'
    self.layout.operator(RealisticStone.bl_idname, text="Realistic Stone", icon="PLUGIN")

def register():
    bpy.utils.register_module(__name__)
    bpy.types.INFO_MT_mesh_add.append(draw_item)

def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.INFO_MT_mesh_add.remove(draw_item)

if __name__ == '__main__':
    register()
$\endgroup$
  • 2
    $\begingroup$ Have you compared your script to the generic Add Mesh Object template script that ships with Blender? You might find your answer there. $\endgroup$ – Craig D Jones Nov 8 '17 at 19:43
  • $\begingroup$ Perhaps post the part that made it work as an answer for others that come here then. And you are welcome! $\endgroup$ – Craig D Jones Nov 8 '17 at 21:49
2
$\begingroup$
bl_info = {
    "name": "Realistic Stone",
    "author": "",
    "version": (0, 0, 1),
    "blender": (2, 79, 0),
    "location": "VIEW3D > ADD > Mesh > Add Realistic Stone",
    "description": "Realistic Stone",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Add Mesh"}

# Imports
import bpy
from bpy import context
import bmesh

class RealisticStoneStone(bpy.types.Operator):

    """Realistic Stone"""
    bl_idname = "mesh.realistic_stone_add"
    bl_label = "Realistic Stone"
    bl_options = {'REGISTER', 'UNDO', 'PRESET'}


    def execute(self, context):

        # Mesh - Create Cubic
        bpy.ops.mesh.primitive_cube_add(location=(0.00, 0.00, 1.00))
        bpy.context.object.scale = (1, 1, 1)
        bpy.ops.object.select_all(action='TOGGLE')
        Cube = bpy.context.object
        Cube.name = 'RealisticStone'
        Object = Cube.name = 'RealisticStone'
        bpy.context.object.data.name = "RealisticStone"

        # Modifier - Multiresolution
        bpy.ops.object.select_all(action='TOGGLE')
        bpy.ops.object.modifier_add(type='MULTIRES')
        bpy.ops.object.multires_subdivide(modifier="Multires")
        bpy.ops.object.multires_subdivide(modifier="Multires")
        bpy.ops.object.multires_subdivide(modifier="Multires")
        bpy.ops.object.multires_subdivide(modifier="Multires")
        bpy.context.object.modifiers["Multires"].show_expanded = False

        # Modifier - Displace 1
        bpy.ops.object.modifier_add(type='DISPLACE')
        bpy.context.object.modifiers["Displace"].strength = 0.5
        bpy.data.textures["Texture.001"].type = 'VORONOI'
        bpy.data.textures["Texture.001"].noise_scale = 1
        bpy.context.object.modifiers["Displace"].show_expanded = False

        # Modifier - Displace 2
        bpy.ops.object.modifier_add(type='DISPLACE')
        bpy.context.object.modifiers["Displace"].strength = 0.25
        bpy.data.textures["Texture.002"].type = 'CLOUDS'
        bpy.data.textures["Texture.002"].noise_depth = 7
        bpy.context.object.modifiers["Displace.001"].show_expanded = False

        # Modifier - Displace 3
        bpy.ops.object.modifier_add(type='DISPLACE')
        bpy.context.object.modifiers["Displace"].strength = 0.01
        bpy.data.textures["Texture.003"].type = 'NOISE'
        bpy.context.object.modifiers["Displace.002"].show_expanded = False

def invoke(self, context, event):
    return self.execute(context)

def draw_item(self, context):
    self.layout.operator("mesh.realistic_stone_add", icon="PLUGIN")

def register():
    bpy.utils.register_module(__name__)
    bpy.types.INFO_MT_mesh_add.append(draw_item)

def unregister():
    bpy.utils.unregister_module(__name__)
    bpy.types.INFO_MT_mesh_add.remove(draw_item)

if __name__ == '__main__':
    register()
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.