Can we get more information on the Exception?

image

It is difficult to identify what causes an error. Even debugging info in the IDE isn’t much of a help.

Thanks

I try to return appropriate error messages when possible. If you can share the script that gives this generic message, I’ll see what can be done

Do you mean to create custom exception message?

This is the code, I’m experimenting with global dictionary of a sort:

import ghhops_server as hs
import rhino3dm

hops = hs.Hops()

gdict = {}

@hops.component(
    "/comp_name",
    name="comp_title",
    nickname="comp_shortname",
    description="Component's description",
    inputs=[
        hs.HopsNumber("A", "a", "One"),
        hs.HopsString("B", "b", "Two"),
        hs.HopsPoint("C", "c", "Three"),
        hs.HopsBoolean("D", "d", "Four"),
        hs.HopsBrep("E", "e", "Five"),
        hs.HopsCurve("F", "f", "Six"),
        hs.HopsInteger("G", "g", "Seven"),
        hs.HopsLine("H", "h", "Eight"),
        hs.HopsMesh("I", "i", "Nine"),
        hs.HopsSubD("J", "j", "Ten"),
        hs.HopsSurface("K" ,"k", "Eleven"),
        hs.HopsVector("L", "l", "Twelve")
    ],
    outputs=None  #[hs.HopsNumber("Sum", "S", "A + B")]
)
def comp_name(a, b, c, d, e, f, g, h, i, j, k, l):
    global gdict
    gdict["a"] = a
    gdict["b"] = b
    gdict["c"] = c
    gdict["d"] = d
    gdict["e"] = e
    gdict["f"] = f
    gdict["g"] = g
    gdict["h"] = h
    gdict["i"] = i
    gdict["j"] = j
    gdict["k"] = k
    gdict["l"] = l
    return None


@hops.component(
    "/dict_data",
    name="dict_data_title",
    nickname="dict_data_shortname",
    description="Component's description",
    inputs=None,
    outputs=[hs.HopsNumber("A", "a", "One"),
             hs.HopsString("B", "b", "Two"),
             hs.HopsPoint("C", "c", "Three"),
             hs.HopsBoolean("D", "d", "Four"),
             hs.HopsBrep("E", "e", "Five"),
             hs.HopsCurve("F", "f", "Six"),
             hs.HopsInteger("G", "g", "Seven"),
             hs.HopsLine("H", "h", "Eight"),
             hs.HopsMesh("I", "i", "Nine"),
             hs.HopsSubD("J", "j", "Ten"),
             hs.HopsSurface("K" ,"k", "Eleven"),
             hs.HopsVector("L", "l", "Twelve")
             ]
)
def dict_data():
    global gdict
    a = gdict["a"]
    b = gdict["b"]
    c = gdict["c"]
    d = gdict["d"]
    e = gdict["e"]
    f = gdict["f"]
    g = gdict["g"]
    h = gdict["h"]
    i = gdict["i"]
    j = gdict["j"]
    k = gdict["k"]
    l = gdict["l"]

    return [a, b, c, d, e, f, g, h, i, j, k, l]


if __name__ == "__main__":
    hops.start(debug=False)

This is a simpler example that also doesn’t work right if you try to change the values of the inputs of the first component but it may be an issue related to the reconnection of the components to the server. I can’t tell.

import ghhops_server as hs
import rhino3dm

hops = hs.Hops()

gdict = {}


@hops.component(
    "/dictwrite_string",
    name="dict write string",
    nickname="dw_string",
    description="write a string variable in a global dictionary",
    inputs=[
        hs.HopsString("Key", "k", "Key"),
        hs.HopsString("Value", "v", "Value"),
    ],
    outputs=None
)
def dictwrite_string(k, v):
    global gdict
    gdict[k] = v
    return None

@hops.component(
    "/dictread_string",
    name="dict read string",
    nickname="dr_string",
    description="read a string variable in a global dictionary",
    inputs=[
        hs.HopsString("Key", "k", "Key"),
    ],
    outputs=[hs.HopsString("Value", "v", "Value")]
)
def dictread_string(k):
    global gdict
    v = gdict[k]
    return v



if __name__ == "__main__":
    hops.start(debug=True)

From cursory glance: you’re assuming your dictionary has been initialized properly. This can go wrong when reading your dictionary. Protect dictionary access.

v = None
if k in d:
    # access d only if key k exists
    # otherwise you'll get a NameError exception
    v = d[k]
return v

In your snippets your dictionaries are not initialized properly before being potentially accessed for reading.

1 Like

Valid point, but irrelevant to the issue in scope.

I had the same issue, because the two caching options of the Hops component are turned on by default.
Additionally, you also need to attach a Trigger to the Hops component that you want to constantly update. They don’t seem to update by themselves.

In dictread_string(k) you could do something like this to make it more watertight:

def dictread_string(k):
    global gdict
    try:
        return gdict[k]
    except KeyError as e:
        raise e

Check your other thread, where I’ve posted a working example.

1 Like

I tried running these scripts but am not seeing any error message balloons in Hops.