Тёмный

How to Remote Debug Blender with VS Code 

Alan's Art Log
Подписаться 4,1 тыс.
Просмотров 19 тыс.
50% 1

In this video I'll show you how to setup everything so you can remote debug Blender from VS Code to make it easier to develop and debug addons and the source code by adding breakpoints and stepping through your code.
UPDATE: ptvsd no longer needs to be 3.0.0 in newer VS Code versions! so you can just pip install ptvsd
LINKS
Python: www.python.org/
Blender Debugger for VS Code Addon + Documentation: github.com/ala...
Website: alansartlog.com...
Patreon: / alansartlog
Instagram: / alansartlog
Twitter: / alansartlog
Facebook: / alansartlog
Instructables: www.instructabl...
~-~~-~~~-~~-~
Checkout my Latest Video: "How to Scan Objects into 3D Models II - Settings and Setup Comparisons"
• How to Scan Objects in...
~-~~-~~~-~~-~

Опубликовано:

 

6 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии    
@VEGETADTX
@VEGETADTX 3 года назад
How this hasn't gotten more attention and how this has not been adopted by the Blender itself is beyond me...
@SinestesiaCo
@SinestesiaCo 6 лет назад
Hey, thanks! This video and the addon are awesome. One gotcha I found is that if I start the debugger with breakpoints already defined it will make Blender freeze (until detached). However it works great if you start the debugger blank and then add breakpoints.
@alansartlog
@alansartlog 6 лет назад
Well this can happen depending on where you're attaching your breakpoints. But it shouldn't happen all the time, like if a breakpoint is attached at a function that never gets called. Something might be wrong if it does.
@theohallenius8882
@theohallenius8882 6 лет назад
Thanks, that is really helpful. I used to make plugins for blender old fashioned way, inside of blender itself, now I feel like making plugins again :)
@alansartlog
@alansartlog 6 лет назад
Awesome! Anything interesting you've worked/are working on?
@theohallenius8882
@theohallenius8882 6 лет назад
Not really, was mostly making utilities for personal use (like distributed rendering, level exporters) but nothing serious. Since I use blender for game development, I will probably make some plugins to make exporting easier, like synchronizing animations directly to godot engine. Now with ability to debug properly I feel like it's worth getting into plugins again.
@alansartlog
@alansartlog 6 лет назад
Oh, well then I'm glad you found it helpful :)
@marcoesposito8651
@marcoesposito8651 6 лет назад
That's great! For some reason (on mac) Blender keeps on using the folder "~/Library/Application Support/Blender/2.79/scripts", instead of the one I assigned in the preferences, but it was enough to open vs code in that folder and it worked fine! Thanks a lot, it will surely be much useful.
@alansartlog
@alansartlog 6 лет назад
Did you save the user preferences after changing it?
@marcoesposito8651
@marcoesposito8651 6 лет назад
Yes, I did... By clicking on the folder-icon on the right Blender opens the right folder, but for some reason it ignores it :/
@alansartlog
@alansartlog 6 лет назад
Seems like a bug with blender. I'd try backing up your settings manually and resetting Blender to factory defaults to see if that fixes it, and check you're on the latest version, otherwise it's likely it's a bug.
@marcoesposito8651
@marcoesposito8651 6 лет назад
I will try, thanks for your suggestions :)
@marcoesposito8651
@marcoesposito8651 6 лет назад
I confirm it worked. Thanks again!
@TopSpeedKertus
@TopSpeedKertus Год назад
You fucking legend! Thank you so much. Everything worked almost as described on the git page, but I had to manually set the debugpy path and I had to manually write in the debug configuration. I don't use Windows often, but needed to use a Blender plugin for some design work and spent hours trying to blindly debug some old Koch snowflake addon. Once the debugger was attached, it took a matter of minutes for me to fix the addon. I don't often use Blender, but I'm subbing just for the hell of it :)
@simsod
@simsod 6 лет назад
Great video! You´ve just lowered the bar for putting together an addon by _a lot_ :)
@alansartlog
@alansartlog 6 лет назад
Thanks, I'm glad :)
@danielelebash3781
@danielelebash3781 4 года назад
Break points not hit. Please see Tales Costa's comment about changing vscode debug mapping config from "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "."}] to " "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "${workspaceFolder}"}] this worked for me. Can anyone else verify and if so Alan can you add this to the documentation. Thanks for this awesome plugin!
@alansartlog
@alansartlog 4 года назад
Sorry, I'm not sure what comment you're referring to, also you just posted the same config twice? If you're experiencing any issues, please check the latest documentation (there's also a troubleshooting section) at the repo. If you're still having problems, don't hesitate to file an issue. :)
@danielelebash3781
@danielelebash3781 4 года назад
@@alansartlog Thanks I updated comment with correct info and will post to repo issues
@soyunbonus
@soyunbonus 2 года назад
I can't get this to work. Maybe something changed after a couple of years? most of the tutorials I find, even if they're not that old, are outdated in current Blender version 😥
@alansartlog
@alansartlog 2 года назад
Please file an issue at the repo and I'll try to take a look when I have some time. I've not used it in a while, but I've tried to keep it working though nobody has filed an issue lately so I thought it still was, though I see 2.9 came out, so it might just be a matter of upping the version. Sometimes even though the APIs I used stay the same, Blender won't run plugins that state an older version.
@alexandrepv
@alexandrepv 5 лет назад
I can't find these preferences and file options on blender release 2.8... which version are you using? Could you make an updated tutorial please? :(
@alansartlog
@alansartlog 5 лет назад
The addon (as it's published now in the link) won't work with 2.8. I do have a branch that does though: github.com/AlansCodeLog/blender-debugger-for-vscode/tree/update-to-2.8. It should work but I haven't had time to publish a release properly. The tutorial is still 99% the same though, the only thing that's changed is the shortcut to the search and some minor things that have changed for both versions (2.79 and 2.8) for the VS Code config. If it doesn't work for some reason or something is confusing feel free to file an issue in the repo.
@UHStudio
@UHStudio 6 лет назад
This is great! Thank you! I have been looking for something along these lines for a long time since i wanted to settle on using a modern editor like atom or VS code, but couldn't really debug well. Now, just wondering how easy it may be to add autocomplete that dynamically loads all the available classes incl, from installed addons, etc?
@alansartlog
@alansartlog 6 лет назад
Yes, that's the next thing I was going to look into, as I was always having to use the online Blender API reference because the build in API explorer isn't very good imo. Anyways, it seems possible, but I haven't had time to do it yet. First if intellisense isn't working with normal python stuff then in VS Code you have to edit the settings for the workspace and specify the path to python. See code.visualstudio.com/docs/python/environments. Now intellisense gets the autosuggestions based on what packages are installed at that path at site-packages. So for example once that's done, you should see the intellisense for ptvsd. So the trick should be to install blender as a python module as described here: wiki.blender.org/index.php/User:Ideasman42/BlenderAsPyModule. But bear with me I've never built Blender, let alone like that, still quite new to all this. Once I figure it out I'll add it to the documentation on github :) I don't know about it detecting addon classes though, might be possible as well. PS: I used atom for quite some time. I was hesitant to switch to VS Code because I would have to re-configure everything but it's was so much faster even with 20+ extensions installed that after a few days I never touched atom again. It's so good I can't believe it sometimes.
@bartoszstyperek6306
@bartoszstyperek6306 6 лет назад
I have setup autocomplete for bpy.xxx by these steps: a)Get PYREFDEF from pitiwazu video description: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RuCqqy6gLwA.html b)put bpy.py to -> C:\Users\\AppData\Local\Programs\Python\Python36\Lib That is it, now autocomplete will work for bpy.xxx. But vs_code pylinter will complain about not being able to load bpy ("Unable to import bpy"). If you want to silence pylinter create folder: named "pylintrc" in root folder of your scripts and then put .pylintrc file inside (eg. from: www.dropbox.com/s/hpwndxqkl4fol3y/.pylintrc?dl=0). So in my case file is located in: 'C:\Users\\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\pylintrc\.pylintrc' You can edit .pylintrc in notepad if you want to modify path to bpy.py installed in step b). Thing is auto-completion will work for bpy.xxx, but I'm not sure how to make it work for 'context.xxx' (without using bpy.context.xxx) - it is argument pased to 90% of blender python operators, and it seems JacquesLucke made it work in his blender autocomplete addon... Not sure how he has done it.
@alansartlog
@alansartlog 6 лет назад
Awesome! I'll look into it when I have some time. I want to see how hard it is building Blender as a module first. If it's too hard this is a nice alternative. The only thing is that from what I understand, to get the proper api definitions, the pypredef should be generated from the Blender version you want to develop with. For now the file you linked to will work, but in the future, some parts of the api might change. It will still work for the majority of people, but I would like to be thorough, document how to generate it, etc.
@alansartlog
@alansartlog 6 лет назад
For updates on the autocomplete issue, I'm in the process of comparing the different options, check for updates here: github.com/AlansCodeLog/blender-debugger-for-vscode/issues/5. I haven't gotten around to checking fake-bpy-module and similar solutions, but I did eventually manage to build Blender as a module and... let's just say it was a headache on Windows to do this just for spellcheck. I'm hoping other options will work better but I haven't had time to try them (if they work well and it's possible I'd like to incorporate the generator script into the addon to make the process easier).
@alansartlog
@alansartlog 6 лет назад
Yes, was not fun downloading 5gb of Visual Studio C++ build tools over my slow internet. I'm not 100% sure but I think they are both doing the exact same thing, creating python stubs for all the functions, but there are different ways to do this, so one might be better than another (fake-bpy probably because it was more recently updated).
@Tettoffensive
@Tettoffensive 2 года назад
I'm a little confused about how to setup my own addon (an import/exporter) for this. I unchecked the addon and added the development version to the File Paths->Scripts. How do I actually run my addon such that it will trigger the debugger?
@alansartlog
@alansartlog 2 года назад
Is your addon showing up in blender? Once you set the scripts path correctly and restart blender it should now be in the addons list. You then need to set a breakpoint in vscode, run the debugger, then do some action in blender that will trigger it. Please see github.com/AlansCodeLog/blender-debugger-for-vscode for detailed up to date setup instructions just in case. If you have any issues still feel free to file an issue there (I usually reply there faster).
@abrahamnightingale2267
@abrahamnightingale2267 6 лет назад
Will this also cover the Visual Studio or only Visual Code?
@alansartlog
@alansartlog 6 лет назад
Well I've never used Visual Studio itself, but from what I understand ptvsd was initially build for Visual Studio so it should work, in fact it should work with versions after 3.0, because that requirement is just for VS Code.
@tylergubala7355
@tylergubala7355 6 лет назад
Hey man that's awesome. Would be worth its own extension in VS Code. Do you have any plans for such an extension which would set up the environment for you?
@alansartlog
@alansartlog 6 лет назад
There isn't much to set up on the VS Code side though? What would you want it to set up?
@tylergubala7355
@tylergubala7355 6 лет назад
Sorry, let me clarify. It's not that the setup is particularly intense; I was able to follow your video and make a few modifications of my own for the Blender + OpenCV & Keras build I set up, but it's more that you have to go get the Git distribution, install the Blender Addon, install ptvsd, etc etc. The installation isn't bad but just a little fragmented. (Opinion) I think that it could benefit from an easy-install script, either in VSCode itself or on pip. The workflow would be like this: - pyvsd==3.0.0 is a requirement and is therefore installed automatically through the package manager - GitPython is a requirement and is used to grab your repo - (The part I'm unsure about) Automatic installation of the Blender Addon into the user's environment should be fairly straightforward, I'll read up more on it to make sure that there are no unintended consequences - If it is a Visual Studio Extension, you could have the option to set up a venv local to the project with the autocompletion features described by Bartosz below My thought is more that this module isn't "searchable" or "self-install" but it could be an VSCode has a pretty good marketplace for putting such an extension. I'll try and make a proof of concept tomarro.
@alansartlog
@alansartlog 6 лет назад
Well, technically you don't need git to install the add-on. The main problem is ptvsd, for which we need pip. Blender doesn't come with pip or any sort of way to manage dependencies as far as I know. From a quick search it seems possible to install pip alongside Blender's bundled python but the user needs admin privileges. It's Blender that needs ptvsd though, not VS Code, so that's why I was confused. I think if Python is installed, VS Code can use pip and install ptvsd, but then how to let Blender know where ptvsd is? Also you say it would be easy to automate the install of the Blender add-on, but I have no idea how that could be done, and you'd probably need admin privileges as well to let VS Code do it. I'm open to suggestions/pull requests though. Feel free to submit an issue at the repo so we can more easily discuss it. PS: Although this add-on supports Visual Studio (because ptvsd does), I have never used it. I'm only familiar with VS Code.
@nffcsean3239
@nffcsean3239 4 года назад
I don’t have command prompt
@seanmurray170
@seanmurray170 Год назад
Is it possible to use this or a similar setup to set breakpoints in Blender's C/C++ source code and step through that? I'm trying to learn about Blender's internals to fix a couple bugs I think I found.
@alansartlog
@alansartlog Год назад
No, this is specifically for addons. To debug Blender you will need to build it. It's pretty straighforward these days, used to be a bit more confusing. Search for building/debugging blender. There's also the devtalk forums if you need help.
@theowenator2006
@theowenator2006 6 лет назад
I have followed everything to the letter but for some reason, every time I try adding a breakpoint in VS Code 1.25.1, it becomes greyed out and says "Unverified Breakpoint" when I hover over it.
@alansartlog
@alansartlog 6 лет назад
Okay, but up to what point is it working? Does the debugger get attached? If the confirmation listener isn't timed out, both VS Code (in the Debug Console) and Blender should print that it was attached. If that's not happening than the problem is that it's not getting attached (there might be several reasons why). If it is attaching, can you confirm that you added the folder holding the addon (with the correct structure) to Blender's preferences, that they saved, and that your addon gets automatically loaded.
@talesfc
@talesfc 4 года назад
Had similar problem, breakpoints were not activated. Solved by changing changing debug configuration on vscode to: "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "${workspaceFolder}"}] Before it was : "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "."}]
@SoulGuitarMetal
@SoulGuitarMetal 6 лет назад
Can't you use F8 to reload addons instead to disabling and enabling?
@alansartlog
@alansartlog 6 лет назад
Yes, but that reloads all addons and it can cause problems because other addons might error when they restart and they can crash the debug server, see: github.com/AlansCodeLog/blender-debugger-for-vscode/issues/6 for details and possible ways around this. You can still use it though, just know it can cause weird problems.
@hui2975
@hui2975 5 лет назад
It can work, my debugger for vs code script install in C:\Users\xxx\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons, so in 3:50 need same path: C:\Users\xxx\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons
@alansartlog
@alansartlog 5 лет назад
Blender loads addons from there by default, you don't have to specify that path as far as I know. You can just develop your addon in AppData, it should load. If you specify a path it's telling blender to ALSO load files from there. Usually this is more comfortable since most developers keep their projects in one place. Also imo it's a bit weird to be keeping files in AppData. But then again it's up to you. Both seem to function identically (e.g. if you remove your addon from Blender, regardless of where it is, Blender will attempt to delete the folder).
@ShadeedKelly329
@ShadeedKelly329 6 лет назад
Hey, man. I have a question. Now will THIS also straighten out the errors as far as adding .svg files in Blender?
@alansartlog
@alansartlog 6 лет назад
I'm not sure what you mean?
@ShadeedKelly329
@ShadeedKelly329 6 лет назад
What I mean is, I'm trying to import .svg files in Blender but I got an error that's preventing the file from getting imported. It worked when I updated to 2.79 and like the next day, the error report pops up.
@alansartlog
@alansartlog 6 лет назад
Okay, but not sure what this has to do with the video. I mean technically you could try to debug the error but I would only do that if I knew it was truly a bug which it probably isn't (svg imports are working fine for me). Have you: - Looked up the error you're getting. - Checked it's not a reported issue. - Tried resetting Blender to factory defaults (if this doesn't work I start suspecting a real bug). - Reinstalling and resetting to factory defaults. You can also try getting help at the blender artists forum. PS: 90% of problems I find end up being file specific. For example I had this weird problem once where trying to smooth in sculpt mode changed my brush size to 1px and resetting my startup file fixed it. Idk why.
@KeinZantezuken
@KeinZantezuken 3 года назад
Your addon does not even installs into Blender
@alansartlog
@alansartlog 3 года назад
If you're using 2.9 you must turn on developer extras. See github.com/AlansCodeLog/blender-debugger-for-vscode#setting-up-this-addon. If you're still having problems please file an issue at the repo.
@davehayward9628
@davehayward9628 6 лет назад
Great tool and great video! Now, if only I could get it to work. Having faithfully followed the video, pausing t complete each step, I could not get the VS Code debugger to connect to Blender. I get an immediate 'Debug adapter process has terminated unexpectedly.' message in VS Code and no indication of an attempt to connect in Blender. I've verified that python, pip and ptvsd are all installed correctly. Is there anything else I can look at?
@alansartlog
@alansartlog 6 лет назад
You got ptvsd version 3.0.0? Anything above won't work and gives that error.
@davehayward9628
@davehayward9628 6 лет назад
I double checked (and even re-installed) and the version is 3.0.0 AND the add-on found the correct install folder. Hmmm.
@alansartlog
@alansartlog 6 лет назад
Hmm, that's really weird. Apart from what I've covered, which was mostly found through trial and error, there isn't much documentation on all this. I put links to everything that helped me figure it out in the documentation. The only other thing I can think of is maybe something is using the port? I didn't run into that problem, but it's possible that might give that error message? In Windows you can check this in the Resource Monitor > Network Tab > Listening Ports. Check blender.exe is using 3000 and nothing else. Also to eliminate Blender as a factor and help narrow down the problem. Try downloading/copying this script gist.github.com/AlansCodeLog/ff1b246a8e31938e1c3dbfdcbb90522f then from a command prompt run it: "python test.py" and click attach in VS Code. It should attach and print connected and the version. If it doesn't we know the problem is something with VS Code.
@davehayward9628
@davehayward9628 6 лет назад
Well, just to make things more interesting. I ran the script and it displays 'Waiting' and then doesn't seem to attach (i.e. never prints 'Connected').
@alansartlog
@alansartlog 6 лет назад
And VS Code, what does it do? Same error?
@29Aios
@29Aios 6 лет назад
7:09 There is an error dialog in VS Code - "Unknown command", what it can be ?
@alansartlog
@alansartlog 6 лет назад
A dialog? or in the debugger output?
@alansartlog
@alansartlog 6 лет назад
A dialog? or in the debugger output?
@29Aios
@29Aios 6 лет назад
@@alansartlog Yes, there was an error dialog modal box, same as if you write wrong port number. Btw. My VS Code make it 5678 as default, changing to 3000 helps. The error "Unknown command" disappeared after i've restarted Windows 10, restarting Code nor Blender wouldn't help
@29Aios
@29Aios 6 лет назад
@@alansartlog If you are here, how can i debug a script from the Blender Text Editor ?
@alansartlog
@alansartlog 6 лет назад
So you managed to get it working? Unfortunately there is no easy way to debug a script. Although it's possible to connect, it won't actually pause correctly. There is a workaround, see github.com/AlansCodeLog/blender-debugger-for-vscode/issues/4, but I haven't gotten around to investigating how to add this functionality to the addon. My suggestion for now is to just turn the script into an addon.
Далее
5 Steps to setup VSCode for Blender Python (on macOS)
13:04
КОТЯТА НАУЧИЛИСЬ ГОВОРИТЬ#cat
00:13
Bforartists - Forking for a custom GUI
42:14
Просмотров 5 тыс.
Introducing: EasyBPY! (Easy Python for Blender)
12:19
5 Steps to setup VSCode for Blender Python (on Linux)
19:05
Blender 2.9 Python Addon Programming Tutorial
10:22
Просмотров 31 тыс.
How to use VS Code with Godot and GDScript?
10:20
Просмотров 3,7 тыс.
3 Hours vs. 3 Years of Blender
17:44
Просмотров 5 млн