# GhPython compiled components Hints issue

**URL:** <https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219>\
**Category:** Developer\
**Created:** [June 22, 2017, 10:10am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219 "2017-06-22T10:10:33Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bianchi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/bianchi/32/54765_2.png) [@Bianchi](https://discourse.mcneel.com/u/Bianchi)\
**Post date:** [June 22, 2017, 10:10am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/1 "2017-06-22T10:10:33Z")

</div>

@piac

This tutorial was very helpful! I’ve succeeded in making one component, but unfortunately, I’ve run into a bit of a roadblock. ☹

I’ve tried using the first method (Compile) to create a component that has type hints ‘List Access’ and ‘Guid’. It seems that when I try to use the compiled component, my type hints are not maintained, i.e. it works when my component is just a Python script but raises an error regarding the input type when I’ve turned it into a component. So say I set the type hint as ‘Guid’, it ends up expecting ‘UInt32’ as a compiled component.

What could I possibly be overlooking in the steps? Would it be resolved if I used the second compiling method instead?

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [June 22, 2017, 10:41am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/2 "2017-06-22T10:41:20Z")

</div>

Hi @Bianchi

I split the other topic into a new topic.  
Do you have a small sample you could send me to test this?

## Giulio

Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

---

<div class="post-metadata">

**Author:** ![Bianchi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/bianchi/32/54765_2.png) [@Bianchi](https://discourse.mcneel.com/u/Bianchi)\
**Post date:** [June 23, 2017, 5:20am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/3 "2017-06-23T05:20:41Z")

</div>

Hi @piac

Thanks for the reply. This sample has the Python script component before compilation as well as the compiled component:

[sample.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/b/3b38ad1a33c65151e38883a3ed4330c036c7171a.gh) (13.1 KB)

While this script component has large amounts of code reliant on an outside package, I did not remove them as otherwise it would be difficult to illustrate what the components are trying to do.

The issue crops up with the inputs ‘lhs’ and ‘rhs’. They are supposed to take geometry as inputs, with the type hint set to Guid with List Access. So in the scripted component this works, but this is not maintained in the compiled component.

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [June 27, 2017, 1:33pm UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/4 "2017-06-27T13:33:43Z")

</div>

Hi @Bianchi

I fixed this issue. This week’s WIP should contain the relevant commit:  
[https://mcneel.myjetbrains.com/youtrack/issue/RH-40117](https://mcneel.myjetbrains.com/youtrack/issue/RH-40117)

You can also just compile the code yourself using clr.CompileModules(). You will need to change just a few lines from:

```auto
        p = Grasshopper.Kernel.Parameters.Param_GenericObject()

```

to

```auto
        p = Grasshopper.Kernel.Parameters.Param_Guid()

```

## Giulio

Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

---

<div class="post-metadata">

**Author:** ![Bianchi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/bianchi/32/54765_2.png) [@Bianchi](https://discourse.mcneel.com/u/Bianchi)\
**Post date:** [June 30, 2017, 3:26am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/5 "2017-06-30T03:26:45Z")

</div>

HI @piac,

Just an update: still encountering the same issue with the newest WIP. Is it still being tested?

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [June 30, 2017, 5:01am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/6 "2017-06-30T05:01:12Z")

</div>

Hi @Bianchi

I compiled your sample in Rhino WIP `(6.0.17180.4221, 06/29/2017)`  
It seems I get the compiled Guid hints as Grasshopper-native Guid Params:

 ![](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/7/376edac4b96b2acf2c71277c03b5fa06522d4d59.png)

However, in the currently released WIP, `6.0.17178.4271, 06/27/2017`, the fix is not yet present. This means it will be there in next week’s WIP or any WIP after the 17180 one.

You might need to use manual compilation and manually tweak the result if you need this before. Does it help?

I will be on vacation till next Thursday. I’ll make sure to check this topic again after that.

## Giulio

Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

---

<div class="post-metadata">

**Author:** ![Bianchi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/bianchi/32/54765_2.png) [@Bianchi](https://discourse.mcneel.com/u/Bianchi)\
**Post date:** [June 30, 2017, 7:40am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/7 "2017-06-30T07:40:51Z")

</div>

Thanks for the reply, I’ll tinker around with the suggestions you gave for the time being. Looking forward to the update!

---

<div class="post-metadata">

**Author:** ![Bianchi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/bianchi/32/54765_2.png) [@Bianchi](https://discourse.mcneel.com/u/Bianchi)\
**Post date:** [July 12, 2017, 5:23am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/8 "2017-07-12T05:23:39Z")

</div>

Hi @piac,

The newest update has solved most of my component compiling issues, but one of them appears to be causing me some trouble.

I’ve tried compiling it manually, i.e. with the clr method. For this particular component, I could not compile it with the automated method because I was getting the ‘illegal characters’ error. I was able to make a ghpy file of the component, i.e. compile the ‘main.py’ script; however, it causes Rhino WIP to crash, and whenever I try to restart Grasshopper after opening Rhino again, it continues to cause the program to crash. After deleting the component made using clr methods, Grasshopper has stopped crashing, so it appears to be the cause.

I’ve attached the files I tried to compile to make the component (called ‘shape\_to\_geometry’) here. I think the issue may be with the main.py file, or that I lack certain imports in the ‘shape\_to\_geom.py’ file.

[main.py](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/f/e/feeb367a6680252210779e4d1311757dd3aec164.py) (83 Bytes)  
[shape\_to\_geom.py](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/2/c2397af534a94fd929906752db68de46c0cce888.py) (10.8 KB)

Here is the compiled component, if it helps to better illustrate what’s happening.  
[shape\_to\_geom.p2.7.5.0.ghpy](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/1/d/1dff285f1262f70fd7773b223316e6c4a63114b2.ghpy) (51 KB)

What am I missing in my code such that it causes Grasshopper to crash when trying to import the component? Also, is there a way I can adapt the component code itself so that I can use the automated method of compiling instead? It would be good to get some feedback. Thanks!

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [July 12, 2017, 8:59am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/9 "2017-07-12T08:59:36Z")

</div>

Hi @Bianchi

in order to test this better, would it be possible to also have the .GH file?  
I have a few suggestions based on this, but I’d like to see the Grasshopper file before going into details.

## Giulio

Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

---

<div class="post-metadata">

**Author:** ![Bianchi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/bianchi/32/54765_2.png) [@Bianchi](https://discourse.mcneel.com/u/Bianchi)\
**Post date:** [July 12, 2017, 9:47am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/11 "2017-07-12T09:47:33Z")

</div>

Hi @piac,

Here’s the gh file with the scripted components on their own.  
[components\_to\_be\_compiled.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/b/3bd0b28740de11d20ca7b7fb7943d4f6e93cdb53.gh) (27.0 KB)

I assume you just need to see the code itself, not necessarily run it fully. The component in question that’s giving me trouble is the input S output G component.

![](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/7/37469c00ce1870fe7a5614ca050a0369ac07f948.png)

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [July 13, 2017, 9:04am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/12 "2017-07-13T09:04:24Z")

</div>

When I attempt to load the .GHPY file, I get this exception:

 ![](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/7/9/7956875dd25f1c076b101d3a1be07c10296d802e.png)

How did you create it? Did you create it using the \_EditPythonScript editor in Rhino WIP?

Especially, this makes it looks like the generator was a 32-bit program, and therefore this cannot be loaded in a 64-bit program such a Rhino WIP.

---

<div class="post-metadata">

**Author:** ![Bianchi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/bianchi/32/54765_2.png) [@Bianchi](https://discourse.mcneel.com/u/Bianchi)\
**Post date:** [July 13, 2017, 10:21am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/13 "2017-07-13T10:21:09Z")

</div>

Yes, that’s correct, I edited the scripts using the EditPythonScript editor. Should I be creating them in an outside editor instead?

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [July 13, 2017, 10:55am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/14 "2017-07-13T10:55:15Z")

</div>

For some reason your code does not create a valid assembly. I am investigating.[quote=“Bianchi, post:13, topic:45219”]  
Should I be creating them in an outside editor instead?  
[/quote]

No this is not required and worse for troubleshooting now.

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [July 13, 2017, 5:24pm UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/15 "2017-07-13T17:24:03Z")

</div>

Hi @Bianchi

OK, so I am here reporting back from testing your setup carefully (for the part that can be tested, which is all except `sortal`).

- I tried going through the automatic single-component test and it was not successful. There was a bug in the path-constructing code that was preventing it from running. This will be fixed in next week’s WIP.
- I then used the manual “Copy compilable code” option. Please note, that you should include, in the compilation arguments, also your `sortal.py` module, if you want it to work on other machines.
  - I got the file that is saved as `testrefpoint.py` in the attachement ZIP.
  - Then there was a minor need of modification of main.py. I just changed the reference to `testrefpoint.py`. You also need to add `sortal.py` to it if you want the compiled code to actually do something!
  - After running main.py in the EditPythonScript editor, I got the `shape_to_geom.p2.7.5.0.ghpy` that you can find in the ZIP file. This is a valid .Net assembly and can be used by the IronPython interpreter. Grasshopper loads it immediately.

Please let me know if you have other questions regarding these steps, then we can see any additional problems.  
Thanks, kind regards,

## Giulio

Giulio Piacentino  
for Robert McNeel & Associates  
[giulio@mcneel.com](mailto:giulio@mcneel.com)

[Bianchi\_forum.zip](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/d/7/d78b2bc451afaa07d7081c4c425b975ee60bf059.zip) (20.1 KB)

---

<div class="post-metadata">

**Author:** ![Bianchi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/bianchi/32/54765_2.png) [@Bianchi](https://discourse.mcneel.com/u/Bianchi)\
**Post date:** [July 14, 2017, 4:39am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/16 "2017-07-14T04:39:18Z")

</div>

Sortal is a package of scripts (it’s a folder, not just a single .py script), so I’m wondering how I should include it in the compilation arguments and in which file. Where should I add in the ‘sortal’ compilation argument and in what way? I.e. Should it be included as a docstring in the script to be compiled (example in the picture) or in another form?

 ![](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/9/1/91e7689593c5eece6dcd57a5fecaa546167726f4.png)

---

<div class="post-metadata">

**Author:** ![piac](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piac/32/673006_2.png) [@piac](https://discourse.mcneel.com/u/piac)\
**Post date:** [July 14, 2017, 10:19am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/17 "2017-07-14T10:19:09Z")

</div>

You need to add **all** files of the sortal package to the [main.py](http://main.py) line with `clr.CompileModules(...)` for compilation.

If sortal is your package (or even if it’s not, if possible) I’d suggest to simplify its structure and put all code into a single module (a single file). However, I do not think that clr.CompileModules() as restrictions _per se_.

You can read about clr.CompileModules, for example, on this post:

> **[Static Compilation of IronPython scripts](https://blogs.msdn.microsoft.com/srivatsn/2008/08/06/static-compilation-of-ironpython-scripts/)**
>
> The ability to compile IronPython scripts into .NET IL and to save them to disk existed in IronPython 1.0 but has been missing in 2.0 so far. With IronPython 2.0 Beta4 this has been added back. Why would I compile dynamic language scripts? There are...

---

<div class="post-metadata">

**Author:** ![Bianchi](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/bianchi/32/54765_2.png) [@Bianchi](https://discourse.mcneel.com/u/Bianchi)\
**Post date:** [July 17, 2017, 1:43am UTC](https://discourse.mcneel.com/t/ghpython-compiled-components-hints-issue/45219/18 "2017-07-17T01:43:23Z")

</div>

Thanks for the help. At this point, I don’t think it’s best to do that with the sortal package (i.e. put it all into a single module) given that it’s thousands of files and many of them import from each other, so I’ll just tinker around with clr.CompileModules for the time being.
