I’m trying to make a simple Python script run automatically whenever I run Blender, so the one function it adds will be easily available to me when I’m working. (In other words, I don’t have to remember to load and run the script whenever I need it.) I’ve used the Add-on Tutorial to create an addon.
I am using some different directories for my scripts and I’ve changed the preferences in Blender to handle that. I’m on a Mac and I’m using /Users/<myname>/Documents/3DGraphics/Blender/Scripts under Script Directories. I use it for storing scripts I want to use regularly (and that aren’t under development). I’ve read that scripts in the script directories are started automatically - I’m not so sure about that. It appends an entry on the object menu and that doesn’t show up.
As for addons, I’ve specified /users/<myname>/Documents/3DGraphics/Blender/Add-Ons under “Add-Ons” in my Asset Library. (I use computers in 2 locations for my 3D work and using folders in my Documents folder makes it a lot easier to sync my settings for a number of programs.)
When I go into Preferences and try to add my script as an addon, I get this message:
So it’s copying my script (which has been tested and works fine) into the default addon directory. But I don’t see it under the list of addons in Preferences. It copies the file but doesn’t use it.
This leaves me with several questions:
- Is making a script an addon the only way to make it run when I start Blender?
- If 'No" on #1, where do I put a script to make it auto-run when I start Blender?
- Is the addon directory I added to my Asset Library not used as the default addon directory at all? In other words, is the addon directory going to be in
/Users/<myname/Library/Application Support/Blender/<version>/scripts/addonsno matter what I do? - What do I need to do to get my script to run on start?
Here’s the script, which I’ve also posted in 2 other topics where I’m having other issues:
import bpy
class ShrinkageScaler(bpy.types.Operator):
bl_idname = "object.dialog_operator"
bl_label = "Shrinkage Scaler"
shrink_rate: bpy.props.IntProperty(name="Clay Shrink Rate",
description="Shrinkage rate for clay body",
default=10, min=0, max=90)
def execute(self, context):
expand = 100 / (100 - self.shrink_rate)
message = "Using shrinkage rate of %s and expansion rate of %s" % (self.shrink_rate, expand)
self.report({'INFO'}, message)
sel_objs = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
# bpy.ops.object.select_all(action='DESELECT')
for obj in sel_objs:
s = obj.scale
obj.scale = (s[0] * expand, s[1] * expand, s[2] * expand)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
# Only needed if you want to add into a dynamic menu.
def menu_func(self, context):
self.layout.operator(ShrinkageScaler.bl_idname, text=ShrinkageScaler.bl_label)
def register():
bpy.utils.register_class(ShrinkageScaler)
bpy.types.VIEW3D_MT_object.append(menu_func)
# bpy.types.VIEW3D_MT_object_context_menu.append(menu_func)
def unregister():
bpy.utils.unregister_class(ShrinkageScaler)
bpy.types.VIEW3D_MT_object.remove(menu_func)
# bpy.types.VIEW3D_MT_object_context_menu.remove(menu_func)
if __name__ == "__main__":
register()
# unregister()