JacquesLucke / blender_vscode

Visual Studio Code extension for Blender development.
MIT License
572 stars 75 forks source link

Does not register macros #165

Closed Lateststeam27 closed 2 months ago

Lateststeam27 commented 3 months ago

So the problem is that when I run a macro nothing happens, but if I run the same script through blenders text editor it works!

Mateusz-Grzelinski commented 2 months ago

Can you share example? What kind of macro are you talking about?

Lateststeam27 commented 2 months ago

Thank you for the reply I appreciate it. From testing the register function and unregister don't do anything when its not inside of the blender text editor so it wasn't as much macros as the register function never happens, I'm not sure if there's a specific file setup to get it to work. But no matter the setup I tried the register function would never start for some reason so the macro wouldn't work, I started just having the same file opened in blender to run it since it works there. As for file setups if theres a correct setup for this to work I would really appreciate it I am also using blender 4.2 and 4.1 so it might just be a bug with the extension in newer versions

Mateusz-Grzelinski commented 2 months ago

I remember I had this problem once: you need to answer the question: who is responsible for calling register function.

Accoring to docs https://docs.blender.org/api/current/info_overview.html#module-registration

Blender modules loaded at startup require register() and unregister() functions. These are the only functions that Blender calls from your code, which is otherwise a regular Python module.

When using blender text editor to create addon you need to call registter manually, in addon blender does it for us.

So this is minimal addon that I could come up with:

# file name and location:
# %APPDATA%\Blender Foundation\Blender\4.2\scripts\addons\test\__init__.py
# note must be named __init__.py
bl_info = { "name": "test", }
import bpy

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Tool Name"

def register():
    bpy.utils.register_class(SimpleOperator)

def unregister():
    bpy.utils.unregister_class(SimpleOperator)

# if __name__ == "__main__": # no need, this is used only for interactive scritps
#     register()

image