BlackStartx / PyCharm-Blender-Plugin

A PyCharm Plugin that simplify the development of Blender Add-On inside the PyCharm IDE.
MIT License
142 stars 13 forks source link

Reload on Save not working #5

Closed elamhut closed 2 years ago

elamhut commented 2 years ago

First of all, thanks a ton for making this plugin for PyCharm, I don't really enjoy my time with VS Code and I find that PyCharm is a much better IDE overall (for Python at least). The reason I didn't purchase PyCharm Professional was because of the lack of an addon like this in the first place, so I might end up purchasing it if the plugin ends up working :)

Currently on PyCharm Community 2021.2.1 I can manage to open a Blender 2.93 instance and load up my plugin, but it doesn't seem to be updating when I save, but if I press the Play button and open another Blender Instance the plugin is updated in this new Blender instance.

BlackStartx commented 2 years ago

Hi Elam~ ^-^

Thank you for your feedback too!

By the way, I have tried to replicate your issue but the plugin was updating on save correctly :c [Using Blender 2.93.0 and PyCharm Community 2021.2.3]

Do you get any error in the console when saving your plugin? And since PyCharm 2021.3 got released today, I'll soon upgrade my plugin and add some feature to track down the problem easily ^-^

Thanks again and sorry for the issue~ :c

elamhut commented 2 years ago

No, I don't think I'm getting errors anywhere other than PyCharm being super picky about my life choices (heh)

Here's a video of me trying to rename a button and not working: https://youtu.be/JZpVwyBsEW0

BlackStartx commented 2 years ago

Sorry for the late reply~

By the way, I've created a version with just a some small prompt to show what is happening when you save a file so I can understand better where the flaw is~ (I'll probably keep it and improve it on an official release)

May you try to use this version and send the console output?

Blend-Charm-2021.2 - Prompt.zip

You should see some text in the console when you save your file in PyCharm like this:

image

elamhut commented 2 years ago

Still not working, but now it prints stuff :)

https://youtu.be/zyc1ry_BQAE

"\"C:\Program Files\Blender Foundation\Blender 2.93\blender.exe\"" --python C:\Users\NZXT-D~1\AppData\Local\Temp\BlendCharm\pycharm_connector.py --
[On Save: VFS_CHANGE]
BlackStartx commented 2 years ago

Ok, I do think to understand what's the problem here. ^-^ I'll explain everything as well as why the plugin was updating only on new instances of Blender~

Why your plugin was not updating on save.

First of all, in order to have all the features of my plugin you have to define what is an addon in your PyCharm project, by marking the folder as an "Addon Folder".

My plugin support the developing of multiple addon within the same PyCharm workspace. Because of this any addon you're working on HAS TO BE A CHILD of the opened directory in PyCharm.

And that's not your case, since you have opened the root directory of your addon.

That could presumably mean that you should open in PyCharm the parent folder "GitProject"... but that's a terrible solution.

I would suggest you NOT to move your project but to create a new folder in the root of it and move all your files into that folder. (I suggest you to name it the exact same name of your project so that it match the one already in Blender)

From there you can mark that folder as an "Addon Folder" by right-clicking it and select:

New -> Blend-Charm -> Mark as Addon Folder

image

I do understand that's an annoying solution, but right now my plugin only support plugin as sub-folders of the opening directory of PyCharm.

I will definetly work on the ability to set the opened directory in PyCharm as THE addon folder itself, so that this problem could have been solved easily and without forcing you to change the structure of your project.

If you want you can leave the project as it is and I could start working on the feature today and maybe I can release a version today and you don't need to move anything.

P.S: Love that Xingqiu in the background~ ^-^

So may I ask you:

Why your plugin was updating only on new instances.

I think you have used the Jacques Lucke's tool for Visual Studio Code before.

His tool created a junction between your addon directory and the blender addon folder. This way, any change to you do to your script will be automatically reflected to the junction directory in the Blender Addon Folder.

Blender will load all the addons in the addon folder on start-up, thus he would load with the updated version of your addon.

elamhut commented 2 years ago

Oh, I'm totally confortable waiting for you to make this feature, please no need to rush it. Meanwhile I'll continue to use VS Code and Jaque's plugin to develop my addon :)

Once you have a new version that supports the main folder as the addon I'll be glad to test it out.

Oh, I also have a question, I'm using the following bit of code to find the path of my Addon Package (where my __init__.py is) so I can open a .json config file in the same folder. On Jaque's addon this works without an issue, but now when trying to open my Addon via your PyCharm Plugin it's giving me FileNotFoundError :/

    for mod in addon_utils.modules():
        if mod.bl_info['name'] == __package__:
            addon_path = Path(mod.__file__)

    projects_file_path = Path(addon_path.parent / 'registered_projects.json')

    if projects_file_path.is_file():
        with open('registered_projects.json', 'r') as projects:

Do you know why this happens and if there's a workaround for it?

PS: I was doing my dailies and farming hahaha I'm about to hit AR 50 so I was farming talent books for my Hu Tao with a friend :P

BlackStartx commented 2 years ago

I've developed a temporary solution for the reload-on-save issue~

Blend-Charm-2021.2-Project.zip

You can try use this version and you should be able to mark your project as a "Blender Addon" by right clicking the root of your project and go:

New -> Blend-Charm -> Mark as Addon Project

image

After that, the icon in your project should have changed and have a blender logo in the bottom right corner.

image

From now on the reload-on-save feature should work as intended.

But I'm still unsure why there is this the FileNotFoundError issue... there should be no differences from running Blender from PyCharm and running it from the exe (?)

By the way, since Community Edition cannot have the remote debugger feature, if you want to have feedback from the console I remind you that you should use the logging library instead of the built-in print function, otherwise notthing would be printed in the console ^-^

Thanks and sorry again for the inconvenience~

elamhut commented 2 years ago

THANKS A TON! It seems to be working fine now!

https://youtu.be/OMWEAzQVTgY

My FileNotFound bug was also gone when I tried this new version as well, so don't fret about that :D

I'm super happy that I can finally use PyCharm to develop with Blender :D

Thanks A TON! Hopefully you keep adding new features to this amazing plugin and put it on the Marketplace because this is a MUST NEED for Blender dev. I'll tell everyone about it :)

elamhut commented 2 years ago

Hey Black, could you publish a new release with those improvements for both Community and Professional? I got a hold of a PyCharm professional edition Trial and I want to give a try with debugger options.

Feel free to close the issue as well :)

BlackStartx commented 2 years ago

Hi Elam ^-^

Uhhh, that's cool!

By the way yes, I'll release an official release soon ^-^ I was cleaning stuff up since this project was originaly born for personal use only and it's full of junk code ahahah (I never created an IntelliJ Plugin and I was only interested in make it work and not to make it nice ahah)

I'll finish it today, meanwhile I'll add here 2 updated professional releases, one for 2021.2 and one for 2021.3 ^-^

Blend-Charm-2021.3 - Professional.zip

Blend-Charm-2021.2 - Professional.zip

I'll leave this issue open for another day in case of any problems~ ^-^

elamhut commented 2 years ago

Thanks a ton! Will try out 2021.3 and if there's any issues I'll let you know!

Again, thanks for the amazing work and good job!

elamhut commented 2 years ago

Ok so on 2021.3 Professional + the new .zip you sent me, I'm not receiving anything back from Python, I made a quick video showing the difference from console output of your addon and Jaque's, please let me know if I'm doing anything wrong, I've never run Pycharm in Debug.

So basically I'm not getting any Print functions nor regular blender Returns printed on my console, check it out:

https://youtu.be/ZIL8I6Sb_l4

BlackStartx commented 2 years ago

Hi Elam~ ^-^

Strange... I would suggest you to try with the official release or try using the logging library like this:

import logging

logging.log(logging.INFO, "Hello World!")

The print function was a little unpredictable for me as well, I'll fix it as soon as I understand where is the problem :c Tell me if the printing library work~ ^-^

elamhut commented 2 years ago
pycharm64_WG0kOhb1zD

By using the logging module I can definitely print stuff :)