Fixing Create Hole Addon

Hello everyone,

please could someone make a Blender 2.8 Version from this wonderful little script.

Exception in module register(): C:\Blender\scripts\addons\Create_Hole.py
Traceback (most recent call last):
File “C:\Blender\2.80\scripts\modules\addon_utils.py”, line 384, in enable mod.register()
File “C:\Blender\scripts\addons\Create_Hole.py”, line 59, in register bpy.utils.register_class(PanelCreateHole)
RuntimeError: Error: Registering panel class: ‘OBJECT_PT_Create_hole’ has category ‘Tools’

bl_info = {
    "name": "Addon Create Hole",
    "author": "Cédric Lepiller",
    "version": (0, 1),
    "blender": (2, 71, 0),
    "location": "View3D > Tools",
    "description": "This Operator create a hole on a selection",
    "warning": "",
    "wiki_url": "",
    "category": "Tools"}

import bpy


#Create Hole
class CreateHole(bpy.types.Operator):
    """This Operator create a hole on a selection"""
    bl_idname = "object.createhole"
    bl_label = "Create Hole"


    @classmethod
    def poll(cls, context):
        return context.active_object is not None


    def execute(self, context):

        bpy.ops.mesh.extrude_region_move()
        bpy.ops.transform.resize(value=(0.6, 0.6, 0.6))
        bpy.ops.mesh.looptools_circle()
        bpy.ops.mesh.extrude_region_move()
        bpy.ops.transform.resize(value=(0.8, 0.8, 0.8))
        bpy.ops.mesh.delete(type='FACE')
        return {'FINISHED'}

##################################


#Class Panel
class PanelCreateHole(bpy.types.Panel):
    bl_label = "Create Hole"
    bl_idname = "OBJECT_PT_Create_hole"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_category = "Tools"


    def draw(self, context):
        layout = self.layout


        layout.operator("object.createhole")




def register():
    bpy.utils.register_class(PanelCreateHole)
    bpy.utils.register_class(CreateHole)


def unregister():
    bpy.utils.unregister_class(PanelCreateHole)
    bpy.utils.unregister_class(CreateHole)


if __name__ == "__main__":
    register()

Hi,

my changes:

  1. LINE 5: “blender”: (2, 80, 0),
  2. LINE 46: # bl_category = ‘Tools’
  3. Install Looptools AddOn
  4. Install the Script
  5. go to edit mode
  6. select a face
  7. Press ‘Create Hole’

Enjoy…

2 Likes

This is so great!

Many thanks blulog!

1 Like

‘bl_category’ is already ‘Tools’ – Did you mean to say to change :

bl_region_type = ‘TOOLS’ to bl_region_type = ‘UI’ (this is needed)

Anyways, here is a proper port for you for this quick ops addon including the Addon Preferences category change function, so you can change to any tool tab you want.

Here is the updated addon code :

# ***** BEGIN GPL LICENSE BLOCK *****
#
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ***** END GPL LICENCE BLOCK *****

bl_info = {
    "name": "Create Hole",
    "author": "Cédric Lepiller, DaremoK3 (B2.80 port)",
    "version": (0, 2, 1),
    "blender": (2, 80, 0),
    "location": "View3D > Sidebar > Tools",
    "description": "This Operator create a hole on a selection",
    "warning": "",
    "wiki_url": "",
    "category": "Tools"
    }

import bpy
from bpy.types import Operator, Panel, AddonPreferences
from bpy.props import StringProperty

#Create Hole
class OBJECT_OT_create_hole(Operator):
    """This Operator create a hole on a selection"""
    bl_idname = "object.create_hole"
    bl_label = "Create Hole"
    bl_options = {'REGISTER', 'UNDO'}

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):

        bpy.ops.mesh.extrude_region_move()
        bpy.ops.transform.resize(value=(0.6, 0.6, 0.6))
        bpy.ops.mesh.looptools_circle()
        bpy.ops.mesh.extrude_region_move()
        bpy.ops.transform.resize(value=(0.8, 0.8, 0.8))
        bpy.ops.mesh.delete(type='FACE')

        return {'FINISHED'}


##################################

#Class Panel
class PANEL_PT_create_hole(Panel):
    bl_label = "Create Hole"  # changed for 0.2.1 -- dk3
    bl_idname = "PANEL_PT_create_hole"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Tools"
    bl_context = "mesh_edit"  # allow Edit Mode usage only

    def draw(self, context):
        layout = self.layout

        layout.operator("object.create_hole")


# Add-ons Preferences Update Panel

# Define Panel classes for updating
panels = (
        PANEL_PT_create_hole,
        )


def update_panel(self, context):
    message = ": Updating Panel locations has failed"
    try:
        for panel in panels:
            if "bl_rna" in panel.__dict__:
                bpy.utils.unregister_class(panel)

        for panel in panels:
            panel.bl_category = context.preferences.addons[__name__].preferences.category
            bpy.utils.register_class(panel)

    except Exception as e:
        print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
        pass


class CreateHoleAddonPreferences(AddonPreferences):
    # this must match the addon name, use '__package__'
    # when defining this in a submodule of a python package.
    bl_idname = __name__

    category: StringProperty(
            name="Tab Category",
            description="Choose a name for the category of the panel",
            default="Tools",
            update=update_panel
            )

    def draw(self, context):
        layout = self.layout

        row = layout.row()
        col = row.column()
        col.label(text="Tab Category:")
        col.prop(self, "category", text="")


classes = (
    OBJECT_OT_create_hole,
    PANEL_PT_create_hole,
    CreateHoleAddonPreferences,
)


# Register
def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    update_panel(None, bpy.context)


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)


if __name__ == "__main__":
    register()

I just did this here on my Linux laptop, so I have not tested in B2.80, but the conventions are correct so it should work - please, let me know otherwise…

EDIT : I updated the Panel class code to only be available in Edit Mode.

1 Like

I just tested your script on B2.8 under Linux. Works perfectly.

Thank you, blulog, for testing - good to see it works.

While you are here, or if you get back to this later – I would love to try B2.80 on Linux, but I work in virtual environment from USB drive.

What version of Linux are you using?

I have a pre-installed B2.79b with my Ubuntu Studio (USB drive) – Do you think it is possible to add B2.80 there?

Official/buildbot are portable builds.

Extract the tar.bz2 file to a new folder. Enter to the folder an execute (double click) “blender” file there.

Thank you, YAFU, I will give it a shot, but I have been avoiding it because I do not seem to have Administer privileges with access to the program files.

I can’t copy into or out of the B2.79 main addons folder - only the outside user files where I created the addons_contrib file. So, I am not sure how to go about installing B2.80 - It doesn’t seem as cut-n-dry as with Windows, or even the right-click installs on my PuppyLinux (still waiting for them to create the install for 2.80 though).

blulog, re-copy the addon, and replace with previous one – I made a couple of changes in Edit – I dropped ‘Panel’ from name (forgot that is where would show up - from looking at your image), and made it Edit Mode contextual only (won’t show up in other modes).

That’s not a problem. Just try it. @YAFU has described it very well :slight_smile:

Just download the tar.bz2 file to your /home/YOUR_USER or where you have permissions.
Run blender as I had indicated and install the addon. Once you save the 2.8 user preferences, a folder with user configurations will be created in your /home/YOUR_USER/.config/blender/2.80
If your Linux distribution is not a very old version, it should work.

looks great!

Works great on Win 7.
Many thanks DaremoK3.

Thank you, YAFU, it worked great. I didn’t know it would be as easy as just adding a portable version like I use in Windows.

Now, I can lounge on the couch and work in 2.80…

You are welcome, NewVisitor.

Thank you, for the original script – I did not know it existed, and now have added it to my 2.79 build as well.