πŸ‡ΊπŸ‡¦ We stand with Ukraine! πŸ‡ΊπŸ‡¦

[Plugin] PrettyGcode viewer

I load the bed volume in onTabChange via printerProfiles.currentProfileData. Perhaps that can happen too early for the currentProfile to be set.

                var bedVolume = undefined;
                var viewInitialized = false;
                self.onTabChange = function (current, previous) {
        
                    if (current == "#tab_plugin_prettygcode") {
                        if (!viewInitialized) {
                            viewInitialized = true;
        
                            //get printer build volume.
                            //console.log(["self.printerProfiles",self.printerProfiles.currentProfileData()]);
                            var volume = self.printerProfiles.currentProfileData().volume;
                            if(typeof volume.custom_box ==="function")//check for custom bounds.
                            {
                                bedVolume={
                                    width:volume.width(),
                                    height:volume.height(),
                                    depth:volume.depth(),
                                    origin:volume.origin(),
                                    formFactor:volume.formFactor(),
                                }
                            }else{
                                //console.log(["volume.custom_box",volume.custom_box]);
                                bedVolume={
                                    width:volume.custom_box.x_max()-volume.custom_box.x_min(),
                                    height:volume.custom_box.z_max()-volume.custom_box.z_min(),
                                    depth:volume.custom_box.y_max()-volume.custom_box.y_min(),
                                    origin:volume.origin(),
                                    formFactor:volume.formFactor(),
                                }
                            }
        

I think the dimensions were just coincidental to what I was printing. You may want to consider switching to onAfterTabChange maybe?

I tried afterTabChange and it did the same. It looks to me like the behavior or execution order of the printerProfileViewModel changed. It used to be I could get a valid volume in onTabChange, but now I get the default 200x200.

I either need to find a new event to trigger the 3d view init (I use the build volume for quite a bit of setup) or rewrite it to allow the build volume to change more gracefully. The second option is probably the right thing to do. But I don't know when I will get the time for that.

Maybe use a promise request using the javascript client embedded in OctoPrint?

OctoPrint.printerprofiles.get('_default').done(function(data){console.log(data)});

Edit: After a little testing, it does seem like this is a binding related issue on the knockout side or something relative to scope in your javascript side possibly. Another option to consider is initialization based on a subscription to the observable currentProfileData. A quick test by adding this line just below self.printerProfiles declaration does trigger the console.log after your bedVolume log line and does show the correct dimensions.

self.printerProfiles.currentProfileData.subscribe(function(){console.log(['updated',ko.mapping.toJS(self.printerProfiles.currentProfileData().volume)]);});

Another option might be to use a ko.computed observable that returns your bedVolume object instead of declaring it but haven't dug into that yet.

1 Like

this plugin is awesome, hope it'll reach stable soon, good work!

I think it is stable. That's part of the problem. :slight_smile: To release it I apparently have to port it to Python3 and I am afraid that would make it unstable. And I am I am actively using it daily right now.

I do have an update that fixes the bed volume problem under 1.4. I might release that this weekend.

I can't seem to find this using the normal get plugin process, does that mean it's dead and if so what a pity.

As the thread title says, this is a Work In Progress. You may have to use the link in the first post.

Sorry, I didn't realize the significance of "Work in Progress".

Hi. This plugin is pretty much finished, but I missed the deadline to submit it to the plugin depot. And now I have to port to Python 3 before I can release it. I have been trying to find the time to do that but been able to yet.

@Kragrathea, I just looked at your python code, you can probably just add the compatibility flag. Most of your stuff is client side code because it runs in JavaScript, so I don't think you're going to have any problems. I'll test it right now in my dev environment and report back.

Seems to work fine as is, I sent a PR with the necessary changes.

1 Like

Cool!! Thanks Jneilliii! I will check it out ASAP. It would be really nice to get this released.

I put up a new version that (I guess) is Python 3 compatible and fixes the grid size bug. If someone can verify it works I look into publishing it.

I just tried it, but it installs as V0.3.

2020-05-10 08:35:21,317 > Running setup.py install for OctoPrint-PrettyGCode: finished with status 'done'
2020-05-10 08:35:21,319 > Successfully installed OctoPrint-PrettyGCode-0.3

Also the zip file is as large as the V0.3.

Thanks Ewald. It looks like there were comments on the GitHub page and I didn't get notified.

I have put up a new release that hopefully fixes the version problem. And I will keep and eye on GitHub from now on.

1 Like

I am getting ready to finally publish this plugin in the official plugins repository. Can anyone verify that it is still working for them?

And have there been any changes to the submission process in the last 6 months or so?

Here is the markup for the page I plan to submit.

It needs the compatibility flags for python 3, only python 3 plugins are accepted now. Images need to be included under /assets/ images/ plugins/prettygcode/ with your pr and the md file updated to link to those using a relative path rather than linking to github.

I added plugin_pythoncompat = ">=2.7,<4" to the init.py file. Do I need to add compatibility info to .md as well? It should work on any OS/Version.

Also, the plugin apparently works fine on Python 2.7 and above. Do I need to limit it to only Python 3? What if there are users still on older versions of Octoprint?

hmm..adding the version info to the .md is not needed anymore, because it is now read from the python-code during the repository-page build: https://github.com/OctoPrint/plugins.octoprint.org/blob/fb3cb90e31478518aa3f46fd8adeb2c55c95f2c7/.github/scripts/populate_additional_metadata.py#L333

A limit to only 3 is not needed. So, your mentioned __plugin_pythoncompat__ = ">=2.7,<4" is exactly what is needed.

Btw. really nice plugin!!!!