Open theoryshaw opened 2 years ago
answer here: https://community.osarch.org/discussion/comment/12806/#Comment_12806
Not sure if blender_vscode wants to accommodate for this, or not.
I just ran into this myself. I thought my install was broken somehow, but I was just running all of my code underneath an
if __name__ == "__main__":
I have no preference if this should be supported, it would be nice, but it is a pitfall currently. I'm not sure if something in the vs code landing page should mention this. The blender script window supports this but vscode won't since it's communicating through a local server.
There is a solution for this 😊
As mentioned in the doc:
How can I use the extension with my existing addon? The extension only supports addons that have a folder structure. If your addon is a single .py file, you have to convert it first. To do this, move the file into a new empty folder and rename it to init.py. To use the extension with your addon, just load the addon folder into Visual Studio Code. Then execute the Blender: Start command.
The doc seems to be missing a reminder that you need to add the bl_info dictionary at the top of your __init__.py
For example:
bl_info = {
"name": "DRAGGABLEPROP_OT_subscribe",
"description": "DRAGGABLEPROP_OT_subscribe",
"author": "Your Name",
"version": (0, 1, 1),
"blender": (2, 80, 0),
"category": "Development",
}
I have a fix for the original code if you want to run it with the
if __name__ == "__main__":
in my experimental fork of this extension
https://marketplace.visualstudio.com/items?itemName=CGPython.blender-development-experimental-fork
It supports scripts with if __name__ == "__main__":
I should create a PR for this...
here is a video showing the fix https://youtu.be/wtkLw3-NBdM
Thanks for pointing that out. My naive understanding was that part of the doc wasn't for me since I wasn't developing an extension. I'm using a script outside and the blender python api to generate diagrams and figures. I didn't have an intention of using it from within blender so I didn't structure things as an add on. That all makes sense now.
The following code doesn't work with blender_vscode, but it does work with Blender's native text editor.
The script runs in blender_vscode, and there are no errors, but the panel doesn't show up.
Any ideas what I'm missing?