VScode and JacquesLucke's blender_vscode
For those that use these, do you have to restart Blender every time you change your code?
I faintly remember long time ago, i didn't have to do this.
It gets old restarting blender every time. :\
For those that use these, do you have to restart Blender every time you change your code?
I faintly remember long time ago, i didn't have to do this.
It gets old restarting blender every time. :\
Comments
No, I use the

Blender > add-on:Reload On Save
, the add-on reloads each time after pressing alt+s in VS Codehmm....i have that setting, set, already. :\

Did you start Blender from VS Code with the add-on?
Yes, here's the steps...
https://www.dropbox.com/scl/fi/qyvpssadfes1tyecvvque/2023-08-27_12-12-47_NVIDIA_GeForce_Overlay_NVIDIA_Share.mp4?rlkey=e3helwvagcy346mvvl5hndnhw&dl=0
You already probaly tried to fix that bug your console is giving and pressed alt s again? Sometimes I have to press alt s twice before I get a succesful update add-on message in VS Code
Haven't used JacquesLucke's blender_vscode but just to put it out there - if it's using Blender Reload Scripts to update the addon in Blender without then there are problems with that , if it's unregistering and registering addon it could also lead to some unexpected consequences. For me personally fastest way to see the changes in code (given how fast Blender is restaring) is to close Blender and restart it with
⊞ Win + R
andblender --open-last
.If you want it to reload you have to have the root folder of your vs code workspace at src/blenderbim/blenderbim, so it can find out the
__init__.py
file with the relevant blender addon dictionary. But in my experience it's not feasible to use this feature with the BlenderBIM addon, the ifc link systematically gets corrupted in the process and I have to reload Blender. Plus since the panel refactoring a few weeks ago the missing SCENE_PT_scene panel throws an error on reload since it is un-registered by BBIM. That being said I think instead ofif getattr(bpy.types, "SCENE_PT_scene")
it should beif hasattr(bpy.types, "SCENE_PT_scene")
to avoid throwing a AttributeError when the panel has been unregistered there.Was able to patch a few things together.
Via this post, if you change
os.remove(link_path)
toos.rmdir(link_path)
,in the following file, it fixes thePermissionError: [WinError 5]
problem.%USERPROFILE%\.vscode-oss\extensions\jacqueslucke.blender-development-0.0.18\pythonFiles\include\blender_vscode\load_addons.py
...
Thanks to @Andrej730's suggestion, I figured if you add the following to
%USERPROFILE%\.vscode-oss\extensions\jacqueslucke.blender-development-0.0.18\out\blender_executable.js
, it will open the last file....
I'm still not able to reload the plugin, via blender_vscode's typical approach, as I get this error, which I think @Gorgious was hinting at. Not sure how to fix, if possible.
Recently I wrote some snippet that can be used to reload Blender operator without restarting Blender - typically I have it in Text Editor and run it every time I make some change in the operator code and want to test it. Perhaps it can be useful for someone too.
I've just used it and it's very helpful! Thanks @Andrej730
@Andrej730 Love this script as well!
You know the next step is to automatically add to
reregister_classes
, those Classes you're working on, and running this in the VScode background, when the file is saved. ;)That would be dangerous for me! ? When I save file in VS Code it doesn't mean I'm sure there won't be any errors and I'd want to register it right away. Reregistering should be some separate deliberate process, imo.
Tracking exact modules to reload automatically I guess would be possible with some custom VS Code extension. But not sure if it's necessary since typically you're working simultaneously only on couple modules you need to test.
To simplify the existing script a bit more you can search module elements with something like
import inspect; inspect.getmembers(module)
and reload all the classes of the certain Blender types like operators, panels, etc. That way you won't need to provide the exact classes, just modules.Found a very simple way to attach VS Code python debugger to Blender - https://github.com/hextantstudios/hextant_python_debugger
The debugger is working just fine ! Thank you !
I tried your snippet, i run it inside blender text. But i don't see it working. For example i replace "demo panel" by "demonstration panel" inside the demo plugin, i run the script but it doesn't seem to change anything. I have to reload the all blender to see my changes. Do i do something wrong here ? I don't see my changes even if i deactivate/reactivate bbim from plugin panel. Might be something in cache somewhere ?
@bdamay are you sure you edited the snippet and added the classes and modules you need to reload?
No, you're right. i squizzed this part. :-)
For the record i did this - for demo panel:
And it works as expected, thank you.
I also look forward to achieve this:,
do you think it is something that could be done with automatic detection of files and classes that have recent changes or changes compared to the last commit, may be ?
sure, it may get tricky but I think it's possible
I'm gonna give it a try in a separate add-on, may be.
That might be a good exercise for me, getting familiar with blender dev ecosystem.
I'll let you know
@Andrej730 said:
I finally did something in that spirit to reregister module Classes without having to type the exact name of it.
Something like this
I also tried a bit further with a recursive reload attempt that can reload module an submodules at once for exemple demo module
you can find it here https://github.com/bdamay/bbim-reload-addon/blob/main/bbim-reload-addon/bbim_reload_recursive.py
I was willing to use this to reload from the entire blenderbim.module but i actually i run into errors i don't quite understand well.
The repository contains a blender add-on script of this attempt, but it's not quite satisfying as it is.
Hi everyone, i went a bit further on the reloading feature matter.
It's for me a good starting point to exercise myself on blender add-on developpement... I took a swim into it this morning, followed one or two tutorials and read demo module comments carefully (these are very good).
Well, then, i developped my brand first blender add-on that actually do something, as it reloads the submodule you are working on from a custom panel instead of the text editor.
OK, that's not much... but it's my first one and i would be grateful to anyone experienced or not that might take a look and leave me some comment and remarks about it, even the bad ones that might help me improve.
It's here https://github.com/bdamay/bbim-reload-addon
Thank you for your work, glad that snippet can grow into something even more useful 👍
Tested the addon, not sure if I'm missing something but I've tried to change operator
class CreateProject(bpy.types.Operator)
and provided "modules" in the panelproject.operator
and it didn't reregisterCreateProject
- noticed from trying to running and from the console output below.Also, how can I provide tool modules to reload (e.g.
blenderbim.tool.Model
) as operators often depend on them or maybe reload other non-bbim modules (e.g.ifcopenshell.api
andifcopenshell.api.geometry.edit_object_placement
)?Hi @Andrej730 , Thank you very much for your interest in that little addon.
I have to confess i had some issues using it and didn't dig much into these. I don't think i fully understand how register unregister process really work in Blender.
But i will take a closer look in the next days and try it on your usecase, i'll let you know if i manage to make it work as it should.
In the mean time, i recommend not using the addon as it is not safe, sorry
OK i think i might have a beginning of an answer to your first question

Actually the script does this to limit reregistering to classes that are in bpy.types classes. It appears that LoadProject isn't , only BIM_OT... operators are.
FYI i use this test to check what's to be unregistered
classes = [c for c, o in inspect.getmembers(module, inspect.isclass) if hasattr(bpy.types, c)]
Here i'm assuming Classes that are registered are those present in bpy.types. I'm not quite sure of that part, and how we can get a list or registered classes in Blender otherwise. You may have a hint to point to me about this ? It appears CreateProject doesn't show up with this filter.
I also noted that even with this filter, for some reason, in some submodules, the script fails to reregister what have been unregistered. That is indeed much unwanted.
I guess you were right saying it might be safer to choose carefully and individually classes that are needed to be registered than to try to automate this kind or recursion. I might go for something like this if there is no way to do better.
Because Blender may register classes by other names based on it's internal format. E.g. "CreateProject" is registered as "bpy.types.BIM_OT_create_project" though it still is the same class:
Each class also have

is_registered
attribute and this will be a more straightforward way to check if it needs to be unregistered.Hi @Andrej730 ,
Thank you very much for your help. I suspected something like this but didn't have time to dig further, (and i'm not yet very much familiar with blender api). What you say is insightful.
I already made a try with the is_registered attribute but still have errors i have to investigate. (I guess it's because i'm unregistering the class, not blender name ?)
If i may summarize the way i understand it:
What i may not be sure is that if i call bpy.utils.unregister_class(class_obj) with a reference to the "python" class, will the api unregister the class properly ? or ** is there a way for me to get to the "Blender" name coming from "python" Class name** ?
(bl_name may be?
I can't test this right away, as i'm not home, and don't have blender, but hopefully i'll do it tonight )
Either way if you do
unregister(blenderbim.CreateProject)
orunregister(bpy.types.BlenderPostProcesedName)
it will do exactly the same asblenderbim.CreateProject
is the same class object asbpy.types.BlenderPostProcesedName
, just stored in different modules - one inblenderbim
and other inbpy.types
.Hi @Andrej730 , i took a look on the reload script feature. I still have issues on certain classes, that i appear to unregister right but can't register again. with a '**missing bl_rna attribute... **' message. (see below)
That, i don't know what to do with, as it makes the all script really unsafe (as in the end Classes are not available anymore at all).
I surely misunderstand something, but may be you have a clue on what's happening here ?
The code i run is this one:
Can you please narrow it down to some simple way to reproduce the issue? Something like this:
I ran this in console and i don't get no error on BIMDemoProperties class, but i have on PropertyGroup one
gives
OK i think i get it . I shouldn't try to reregister PropertyGroup - i will investigate why i get this class from inspecting submodule