Python "TypeError: Parameter must be a Guid"

Hi,

Before last update of Rhino a python component in grasshopper containing this snippet worked, but not any more.

“”"
import rhinoscriptsyntax as rs

for i in x:
print (rs.Area(i))
“”"

Now it raises “TypeError: Parameter must be a Guid or string representing a Guid”
The problem is that I havn’t changed anything.
x = a bounch of surfaces and hit is set to ghdoc object.

Have anything changed i the latest release reguarding this??

I don’t know what is causing the issue, but something like this might work as a workaround.

for i in x:
    a = rs.coerceguid(i)
    print (rs.Area(a))

Hi,
That was my thought as well, but it gives me the same result.

Traceback (most recent call last):
File “rhinocode:///grasshopper/1/d71b58ee-0172-4f91-9ee3-43a2ab7f4f43/7abdee76-b16c-472b-96e4-c68fe4a9df94”, line 5, in
File “C:\Users\sonny.bergenholtz.rhinocode\py39-rh8\site-rhinopython\rhinoscript\geometry.py”, line 301, in Area
rhobj = rhutil.coercerhinoobject(object_id, True, True)
File “C:\Users\sonny.bergenholtz.rhinocode\py39-rh8\site-rhinopython\rhinoscript\utility.py”, line 1043, in coercerhinoobject
object_id = coerceguid(object_id, raise_if_bad_input)
File “C:\Users\sonny.bergenholtz.rhinocode\py39-rh8\site-rhinopython\rhinoscript\utility.py”, line 871, in coerceguid
if raise_exception: raise TypeError(“Parameter must be a Guid or string representing a Guid”)
TypeError: Parameter must be a Guid or string representing a Guid

Try setting the x Param to list mode, on the Python component itself within Grasshopper.

That is already done with the same result as shown above.
To sort out my settings hopefully this picture does (Yoda) :slight_smile:

Great. Double check what a is, from the return of rs.coerceguid. The code assumes the call was successful, but a lot of those functions can return None.

Finally, I’m not sure whether you have Rhino or Grasshopper geometry in Srf. Try right clicking it and embedding it to get Grasshopper geometry.

If you’ve got an actual Rhino guid / shape, and possibly an ephemeral Grasshopper reference/guid to a Rhino object, the above won’t work. If it’s a true Rhino guid, then you can play around with:

import Rhino
import scriptcontext as sc

sc.doc = Rhino.RhinoDoc.ActiveDoc

I wrote a helper function that attempts to handle strings, guids, grasshopper Geom, Rhino geom, and ephemeral GH references to Rhino objects (if it refers to a Rhino Obj from a param, but the guids change every time the GH canvas is recomputed):


# MIT License

# Copyright (c) [2021] [Cardiff University]

import System

import Rhino

def get_geom_and_source_else_leave(obj):
    #type(type[any])-> type[any], type[any]
    """ Leaves Geometric objects and non-guid strings alone.
        Otherwise searches Rhino doc and ghdoc with obj as guid.
    """
    if hasattr(Rhino.Geometry, type(obj).__name__):
        return obj, 'SOURCE_IS_ALREADY_GEOM'
        # So that we can call it on curves and it will leave them alone

    if isinstance(obj, basestring):
        # To leave legend tags, group names and layer names alone
        try:
            obj = System.Guid(obj)
        except: # (TypeError, ValueError):
            return obj, 'SOURCE_IS_STRING'

    for source in (Rhino.RhinoDoc.ActiveDoc, ghdoc):
        geom = source.Objects.FindGeometry(obj)
        if geom is not None:
            return geom, source
    else:
        msg = 'Type: %s, val: %s, not supported by get_geom_and_source_else_leave' 
        msg %= (type(obj), obj)
        raise NotImplementedError(msg)

Calling that to get geom, source, allows source to be tested, and then perhaps do sc.doc = source and then use rs to manipulate geom

This will do it. By adding the element to a scriptcontext creates a Guiid:

import rhinoscriptsyntax as rs
import scriptcontext as sc

for i in x:
    id = sc.doc.Objects.Add(i)
    a = rs.Area(id)

print(a)

There is a lot of theories on this:

Thanks for the help.

But can someone explain why this is happening in Grasshopper for Rhino 8 and not in Grasshopper for Rhino 7?

And how will this effect all .gh files that were made in GH for Rhino 7 when I start using them in GH Rhino 8?

Doesn’t anyone at Mcneel have an explanation on why this happens?
Is it a bug or is the intension that this is how it is suppose to be?
I have written many functions based on this concept so if there will be a fix for this I gladly wait and not have to rewrite everything. :slight_smile:
@DavidRutten ?

Many thanks in advance

just for info, the “old” GHPython component from R7 does not give me that error on Version 8 SR7
(8.7.24107.13001, 2024-04-16)

Old_GHPy_in_R8_SR7_24107_13001.gh (4.3 KB)

[just as clarification, my post is in relation to this image of yours]

1 Like

I think the one you refer to is Ironpython 1 from Rhino 7 which seems to work fine.
The component called IPy2 in my picture is Ironpython 2 and from that I get the same result as the Py3 component.
Other then that I think we have came to the same conclusion. :slight_smile:

1 Like

@piac : Sorry for calling you out, could you please shred me some light on this?
I can’t get this to work, and the problem is probably that I don’t understand rather than there is a fault.

@sonny.bergenholtz This is definitely a regression and I am working on a fix. Which Rhino version are you running?

RH-81624 GH component regression in marshalling guids on inputs

Okay pushed a fix for this in next 8.7 and added more tests to my unit tests so this doesn’t happen again

2 Likes

Hi,
Grate, thanks!

(8.7.24101.10001, 2024-04-10)

1 Like

Hi Ehsan,
In what release will it be implemented?
Best regards

@sonny.bergenholtz It’s added to the next 8.7 RC that will be released (tomorrow if we are on schedule and there are no other big bugs)

RH-81624 is fixed in Rhino 8 Service Release 7 Release Candidate