Issues building ghpython


(IVELIN PEYCHEV) #1

I am trying to build ghpython with VisualStudio2017:

However I receive this error

Severity Code Description Project File Line Suppression State
Error CS0266 Cannot implicitly convert type ‘object’ to ‘System.Windows.Forms.Control’. An explicit conversion exists (are you missing a cast?) GhPython Path\ghpython\Component\ScriptingAncestorComponent.cs 586 Active
public Control CreateEditorControl(Action<string> helpCallback)
    {
      if (m_py == null) return null;
      var control = m_py.CreateTextEditorControl("", helpCallback);
      return control; //error comes up at this 'control'
    }

#2

Latest commit to this github is from 2014, so pretty outdated? Guess it is not compatible to Rhino 6…

In particular, according to the API https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Runtime_PythonScript_CreateTextEditorControl.htm returns type object, while in Rhino 5 it used to return a type Control. The method CreateEditorControl wants to return a type Control, thus the Error (would only work the other way round).

Technically I guess you can cast explicilty, and if you wrote “return (Control) control;” that error would probably disappear, but I’d assume this points to a larger problem,


(IVELIN PEYCHEV) #3

Thanks @dsonntag,

I wanted to build it to use it as a training while figuring out how it all works. Later on I want to add additional DLLs so I can call them from python without clr. I am not sure if this is the appropriate way, but I’ll try.

Update: It worked,
== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==


(IVELIN PEYCHEV) #4

One more question.

Do you know what should I rename ghpython_OBSOLETE in order to make the v6 one and my build of the old version to work together inside GH. Currently it’s asking me which one I wanna load.

I assume other way would be to change their GUIDs but there are several *Component.cs in ghpython project and they all have different guids.


(Giulio Piacentino) #5

Hello @dsonntag and @ivelin.peychev

yes, as it stands, you can build the GhPython source for V5 into V6 with that change. V6 looks explicitly for the new version, so you will have to bypass that (just rename the project and create new IDs and you will be good to go). Now GhPython is part of Grasshopper, and is bundled there in the same way. We no longer publish its source code for that reason. This obsolete source code is just kept there as a record.

The main changes introduced in V6 regard the editor, which is a facility which Rhino itself provides, the addition of the advanced scripting mode, the compilation of GHPYs, the iteration support (slightly faster iterations in V6). There’s also a change in the results of clicking the “Test” button: in V5 it used to keep all previous variables; in V6, user-defined variables are cleared. And a few more bug fixes and type supports (Guids, Planes etc).

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com


(IVELIN PEYCHEV) #6

Hi Giulio,
Thanks for clarifying this.

One more thing:

So you say from the old build I cannot compile to GHPY?
After making them both appear in my GH can I compile ghpython(obsolete)component using ghpython(v6)?

Thanks.


(IVELIN PEYCHEV) #7

And one more:
I can still use this one as training, but would you agree to add some libraries so that using clr.addreference is not needed?

Like MathNet.Numerics and some XML/JSON processing library


(Giulio Piacentino) #8

No that feature is new to Rhino 6.

I do not fully understand this question. You can compile a new GhPython (that you should call differently, let’s say “GhCobra” with another GUID). I do not really see many advantages in doing this, though. It’s just older and buggier code.

Adding them to where? GhPython? It could be done. Math.Numerics’ license is relatively open. I seem to remember that @DavidRutten wants to add it to Grasshopper 2.


(IVELIN PEYCHEV) #9

To clarify what I meant.

Let’s say I build(compile) this:

Now I have both the new ghpython component and the old one.

Can I use the compiling-sdk.gh from this thread:

In order to compile ghpython_old_component?

Reasons:

  1. I want to not have to use clr.addreference for
    • DotNetZip.dll
    • MathNet.Numerics.dll
    • System.Xml.ReaderWriter.dll
    • TensorFlowSharp
    • etc.
  2. I would like to make
import Grasshopper, GhPython

become this (as default)

import Grasshopper as gh
import GhPython
import scriptcontext as sc
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
  1. Another thing that I requested before is to make SDK mode as default, you said to make it another UserObject, could be done by simply changing the code.
  2. Another one, re-arranging the code automatically when you click SDK mode. You know moving all imports together and moving the description comment on top, these kind of things.

If all of the above are not possible due to incompatibility, are you planning on releasing the source of the new ghpython so I can try to make these changes myself?


(Giulio Piacentino) #10

You can do whatever you want if you change the source code. Directly after compiling nothing will work properly, though, because you will need to change 1. the name and 2. the ID of all components and of the assembly, as I already mentioned several times.

For this, just make a Grasshopper User Object with the normal GhPython component. It will remember whatever code is set at the moment you made the User Object (same for Hints and same for number of inputs, outputs, etc). You can set your own icon. Then you can just use that component from the tab.

This will likely follow McNeel’s decisions with Grasshopper 2.0. There is no incompatibility if you just change the name and the ID, as it’s essentially another add-on.