4
$\begingroup$

I've been coding a simple script to add an object to the `Add Panel'. But every time I click the run script button in the text editor it adds a new listing for the object. How can I can delete these unwanted listings so there's only one?

Screenshot of the New objects Here is my script:

bl_info = {
    "name": "Add Polysphere",
    "author": "Johnson Martin",
    "version": (1, 0),
    "blender": (2, 74, 0),
    "location": "View3D > Add > Mesh > New Polysphere",
    "description": "Adds a new Polysphere",
    "warning": "",
    "wiki_url": "",
    "category": "Add Mesh"}

import bpy
from bpy.types import Operator
from bpy.props import FloatVectorProperty
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector


def add_polysphere (self, context):
    scale_x = self.scale.x
    scale_y = self.scale.y

    verts = [(-0.8942768573760986, 0.0, 0.0), (-0.8221502304077148, 0.0, 0.3518523871898651), (-0.8221502304077148, 0.3518523871898651, 0.0), (-0.8221502304077148, 0.0, -0.3518523871898651), (-0.8221502304077148, -0.3518523871898651, 0.0), (-0.7653955817222595, -0.3270326554775238, 0.3270326554775238), (-0.7653955817222595, 0.3270326554775238, 0.3270326554775238), (-0.7653955817222595, 0.3270326554775238, -0.3270326554775238), (-0.7653955817222595, -0.3270326554775238, -0.3270326554775238), (0.0, 0.8942768573760986, 0.0), (0.0, 0.8221502304077148, 0.3518523871898651), (0.3518523871898651, 0.8221502304077148, 0.0), (0.0, 0.8221502304077148, -0.3518523871898651), (-0.3518523871898651, 0.8221502304077148, 0.0), (-0.3270326554775238, 0.7653955817222595, 0.3270326554775238), (0.3270326554775238, 0.7653955817222595, 0.3270326554775238), (0.3270326554775238, 0.7653955817222595, -0.3270326554775238), (-0.3270326554775238, 0.7653955817222595, -0.3270326554775238), (0.8942768573760986, 0.0, 0.0), (0.8221502304077148, 0.0, 0.3518523871898651), (0.8221502304077148, -0.3518523871898651, 0.0), (0.8221502304077148, 0.0, -0.3518523871898651), (0.8221502304077148, 0.3518523871898651, 0.0), (0.7653955817222595, 0.3270326554775238, 0.3270326554775238), (0.7653955817222595, -0.3270326554775238, 0.3270326554775238), (0.7653955817222595, -0.3270326554775238, -0.3270326554775238), (0.7653955817222595, 0.3270326554775238, -0.3270326554775238), (0.0, -0.8942768573760986, 0.0), (0.0, -0.8221502304077148, 0.3518523871898651), (-0.3518523871898651, -0.8221502304077148, 0.0), (0.0, -0.8221502304077148, -0.3518523871898651), (0.3518523871898651, -0.8221502304077148, 0.0), (0.3270326554775238, -0.7653955817222595, 0.3270326554775238), (-0.3270326554775238, -0.7653955817222595, 0.3270326554775238), (-0.3270326554775238, -0.7653955817222595, -0.3270326554775238), (0.3270326554775238, -0.7653955817222595, -0.3270326554775238), (0.0, 0.0, -0.8942768573760986), (-0.3518523871898651, 0.0, -0.8221502304077148), (0.0, 0.3518523871898651, -0.8221502304077148), (0.3518523871898651, 0.0, -0.8221502304077148), (0.0, -0.3518523871898651, -0.8221502304077148), (-0.3270326554775238, -0.3270326554775238, -0.7653955817222595), (-0.3270326554775238, 0.3270326554775238, -0.7653955817222595), (0.3270326554775238, 0.3270326554775238, -0.7653955817222595), (0.3270326554775238, -0.3270326554775238, -0.7653955817222595), (0.0, 0.0, 0.8942768573760986), (0.3518523871898651, 0.0, 0.8221502304077148), (0.0, 0.3518523871898651, 0.8221502304077148), (-0.3518523871898651, 0.0, 0.8221502304077148), (0.0, -0.3518523871898651, 0.8221502304077148), (0.3270326554775238, -0.3270326554775238, 0.7653955817222595), (0.3270326554775238, 0.3270326554775238, 0.7653955817222595), (-0.3270326554775238, 0.3270326554775238, 0.7653955817222595), (-0.3270326554775238, -0.3270326554775238, 0.7653955817222595), (-0.5956068634986877, -0.5956068634986877, -0.30039307475090027), (-0.6323491930961609, -0.6323491930961609, 0.0), (-0.5956068634986877, -0.5956068634986877, 0.30039307475090027), (-0.5956068634986877, -0.30039307475090027, 0.5956068634986877), (-0.6323491930961609, 0.0, 0.6323491930961609), (-0.5956068634986877, 0.30039307475090027, 0.5956068634986877), (-0.5956068634986877, 0.5956068634986877, 0.30039307475090027), (-0.6323491930961609, 0.6323491930961609, 0.0), (-0.5956068634986877, 0.5956068634986877, -0.30039307475090027), (-0.5956068634986877, 0.30039307475090027, -0.5956068634986877), (-0.6323491930961609, 0.0, -0.6323491930961609), (-0.5956068634986877, -0.30039307475090027, -0.5956068634986877), (-0.30039307475090027, 0.5956068634986877, 0.5956068634986877), (0.0, 0.6323491930961609, 0.6323491930961609), (0.30039307475090027, 0.5956068634986877, 0.5956068634986877), (0.5956068634986877, 0.5956068634986877, 0.30039307475090027), (0.6323491930961609, 0.6323491930961609, 0.0), (0.5956068634986877, 0.5956068634986877, -0.30039307475090027), (0.30039307475090027, 0.5956068634986877, -0.5956068634986877), (0.0, 0.6323491930961609, -0.6323491930961609), (-0.30039307475090027, 0.5956068634986877, -0.5956068634986877), (0.5956068634986877, 0.30039307475090027, 0.5956068634986877), (0.6323491930961609, 0.0, 0.6323491930961609), (0.5956068634986877, -0.30039307475090027, 0.5956068634986877), (0.5956068634986877, -0.5956068634986877, 0.30039307475090027), (0.6323491930961609, -0.6323491930961609, 0.0), (0.5956068634986877, -0.5956068634986877, -0.30039307475090027), (0.5956068634986877, -0.30039307475090027, -0.5956068634986877), (0.6323491930961609, 0.0, -0.6323491930961609), (0.5956068634986877, 0.30039307475090027, -0.5956068634986877), (0.30039307475090027, -0.5956068634986877, 0.5956068634986877), (0.0, -0.6323491930961609, 0.6323491930961609), (-0.30039307475090027, -0.5956068634986877, 0.5956068634986877), (-0.30039307475090027, -0.5956068634986877, -0.5956068634986877), (0.0, -0.6323491930961609, -0.6323491930961609), (0.30039307475090027, -0.5956068634986877, -0.5956068634986877), (-0.5163109302520752, -0.5163109302520752, -0.5163109302520752), (-0.5163109302520752, -0.5163109302520752, 0.5163109302520752), (-0.5163109302520752, 0.5163109302520752, -0.5163109302520752), (-0.5163109302520752, 0.5163109302520752, 0.5163109302520752), (0.5163109302520752, -0.5163109302520752, -0.5163109302520752), (0.5163109302520752, -0.5163109302520752, 0.5163109302520752), (0.5163109302520752, 0.5163109302520752, -0.5163109302520752), (0.5163109302520752, 0.5163109302520752, 0.5163109302520752)]
    edges = []
    faces = [(0, 4, 5, 1), (1, 5, 57, 58), (4, 55, 56, 5), (5, 56, 91, 57), (0, 1, 6, 2), (2, 6, 60, 61), (1, 58, 59, 6), (6, 59, 93, 60), (0, 2, 7, 3), (3, 7, 63, 64), (2, 61, 62, 7), (7, 62, 92, 63), (0, 3, 8, 4), (4, 8, 54, 55), (3, 64, 65, 8), (8, 65, 90, 54), (9, 13, 14, 10), (10, 14, 66, 67), (13, 61, 60, 14), (14, 60, 93, 66), (9, 10, 15, 11), (11, 15, 69, 70), (10, 67, 68, 15), (15, 68, 97, 69), (9, 11, 16, 12), (12, 16, 72, 73), (11, 70, 71, 16), (16, 71, 96, 72), (9, 12, 17, 13), (13, 17, 62, 61), (12, 73, 74, 17), (17, 74, 92, 62), (18, 22, 23, 19), (19, 23, 75, 76), (22, 70, 69, 23), (23, 69, 97, 75), (18, 19, 24, 20), (20, 24, 78, 79), (19, 76, 77, 24), (24, 77, 95, 78), (18, 20, 25, 21), (21, 25, 81, 82), (20, 79, 80, 25), (25, 80, 94, 81), (18, 21, 26, 22), (22, 26, 71, 70), (21, 82, 83, 26), (26, 83, 96, 71), (27, 31, 32, 28), (28, 32, 84, 85), (31, 79, 78, 32), (32, 78, 95, 84), (27, 28, 33, 29), (29, 33, 56, 55), (28, 85, 86, 33), (33, 86, 91, 56), (27, 29, 34, 30), (30, 34, 87, 88), (29, 55, 54, 34), (34, 54, 90, 87), (27, 30, 35, 31), (31, 35, 80, 79), (30, 88, 89, 35), (35, 89, 94, 80), (36, 40, 41, 37), (37, 41, 65, 64), (40, 88, 87, 41), (41, 87, 90, 65), (36, 37, 42, 38), (38, 42, 74, 73), (37, 64, 63, 42), (42, 63, 92, 74), (36, 38, 43, 39), (39, 43, 83, 82), (38, 73, 72, 43), (43, 72, 96, 83), (36, 39, 44, 40), (40, 44, 89, 88), (39, 82, 81, 44), (44, 81, 94, 89), (45, 49, 50, 46), (46, 50, 77, 76), (49, 85, 84, 50), (50, 84, 95, 77), (45, 46, 51, 47), (47, 51, 68, 67), (46, 76, 75, 51), (51, 75, 97, 68), (45, 47, 52, 48), (48, 52, 59, 58), (47, 67, 66, 52), (52, 66, 93, 59), (45, 48, 53, 49), (49, 53, 86, 85), (48, 58, 57, 53), (53, 57, 91, 86)]

    mesh = bpy.data.meshes.new(name="New Polysphere")
    mesh.from_pydata(verts, edges, faces)
    # useful for development when the mesh may be invalid.
    # mesh.validate(verbose=True)
    object_data_add(context, mesh, operator=self)


class OBJECT_OT_add_polysphere(Operator, AddObjectHelper):
    """Create a new Polysphere"""
    bl_idname = "mesh.add_polysphere"
    bl_label = "Add New Polysphere"
    bl_options = {'REGISTER', 'UNDO'}

    scale = FloatVectorProperty(
            name="scale",
            default=(1.0, 1.0, 1.0),
            subtype='TRANSLATION',
            description="scaling",
            )

    def execute(self, context):

        add_polysphere(self, context)

        return {'FINISHED'}


# Registration

def add_object_button(self, context):
    self.layout.operator(OBJECT_OT_add_polysphere.bl_idname,text="Add Polysphere",icon='MESH_UVSPHERE')

def register():
    bpy.utils.register_class(OBJECT_OT_add_polysphere)
    bpy.types.INFO_MT_mesh_add.append(add_object_button)


def unregister():
    bpy.utils.unregister_class(OBJECT_OT_add_polysphere)
    bpy.types.INFO_MT_mesh_add.remove(add_object_button)


if __name__ == "__main__":
    register()
$\endgroup$
  • $\begingroup$ I think you need to run the unregister function you made somehow.... $\endgroup$ – GiantCowFilms May 4 '15 at 17:30
  • $\begingroup$ @GiantCowFilms How Would I do that? I'm pretty new to Python. :P $\endgroup$ – Johnson Martin May 4 '15 at 17:32
  • $\begingroup$ I've never used it either $\endgroup$ – GiantCowFilms May 4 '15 at 17:48
4
$\begingroup$

Yeah, just hit F8 in this case that will refresh the python environment.

enter image description here

$\endgroup$
  • $\begingroup$ Ah, Thank you! I figured it was something like that. $\endgroup$ – Johnson Martin May 4 '15 at 17:35

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.