Autocompletion with PyCharm

Ok now it is working. That link cleared up some things. I guess the objects exposed by pythonnet aren’t known until interpret-time, so an IDE doesn’t have much of a chance to infer anything, at least not without some help. I was hoping for some further magic. Trying Pycharm here and it doesn’t know what is going on. However I am able to subclass Rhino.Geometry.Point3d and help it out, but it feels silly; there are probably more appropriate methods (not too sure about the super attributes):

import rhinoinside
import System
import Rhino



class RiPyPoint(Rhino.Geometry.Point3d):
    def __init__(self, x=0.0, y=0.0, z=0.0, from_point3d=None):
        if from_point3d:
            super().__init__(from_point3d.X, from_point3d.Y, from_point3d.Z)
        else:
            super().__init__(x, y, z)
        self.X = super().X
        self.Y = super().Y
        self.Z = super().Z

    def __add__(self, other):
        return RiPyPoint(from_point3d=self.Add(self, other))

    def __str__(self):
        return 'Subclassed Rhino.Geometry.Point3d({}, {}, {})'.format(self.X, self.Y, self.Z)


p = RiPyPoint(3.0, 2.0, 1.0)
p1 = RiPyPoint(1.0, 2.0, 3.0)

print(p, p1)

p.X = 30
p.Y = 20
p.Z = 10

print(p, p1)

new_point = p + p1

print('{} + {}, {} + {}, {} + {} = {}, {}, {}'.format(p.X,
                                                      p1.X,
                                                      p.Y,
                                                      p1.Y,
                                                      p.Z,
                                                      p1.Z,
                                                      new_point.X,
                                                      new_point.Y,
                                                      new_point.Z))

output:

Subclassed Rhino.Geometry.Point3d(3.0, 2.0, 1.0) Subclassed Rhino.Geometry.Point3d(1.0, 2.0, 3.0)
Subclassed Rhino.Geometry.Point3d(30.0, 20.0, 10.0) Subclassed Rhino.Geometry.Point3d(1.0, 2.0, 3.0)
30.0 + 1.0, 20.0 + 2.0, 10.0 + 3.0 = 31.0, 22.0, 13.0

I guess one could wrap needed rhinocommon objects, if one wanted intellisense.

Although certainly not intended to, I guess this won’t help in the quest for an in-doc, fully supported python IDE, or at least I don’t see any new opportunities yet. Probably more inline with the intent, as a bridge into the CPython ecosystem, this seems promising.

1 Like

Autocompletion and type hinting is a different project. I’ll hopefully have something to show in this area too soon.

1 Like

Good news. I didn’t know it was being worked on. I made a few attempts but always ran into a wall of some sort. Autocomplete for the Rhinocommon tree and imported/declared python objects would be a massive productivity boost.

Hi,
Have you tried this solution:

I’m not sure if I tried this recently. At one point I did try someones stub method for Pycharm, but this looks more automated. Stubs didn’t provide (at the time) any way to work with scripcontext, and execution was not a one button experience.

Following that thead:

https://marketplace.visualstudio.com/items?itemName=jingchengchen.rhinopython&fbclid=IwAR0dfCqUMsO-lx1RPuyjnLx4m8G6W88F_noO_CFTbHqXzmGU_fPbZLW-amI

Looks similar to an experiment I did with VS automation + ironpython, but more modern and probably a better implementation. I did a bunch of tricky imports and temp objects to emulate script context, then fixed those imports and sent the script to a listener script running in Rhino via socket for execution in Rhino. I’ll have to check it out.

Thanks!

No it has very little on scriptcontext but does better with Rhino and I found it reasonably easy to get going, though maybe I got lucky clicking a little randomly in PyCharm :slight_smile:

I am hoping to write a blog post up this week on the topic, but for now you can try to repeat what I do in this video to get autocomplete and type hinting to work in PyCharm

1 Like

Seems to work! I’ll wait for the blog post before asking questions.