I wonder if anyone has a good workaround for something like the following situation:
In a custom python component in GH I’d like to have an input that can accept either numbers OR geometry, and IF it is geometry passed in, to then go and get any UserText values in the Rhino scene for that geometry?
The trouble I’m having is that I can do one or the other just fine, but not both: it seems that I have to set the ‘Type Hint’ to ‘GUID’ on the GH component in order to successfully access the Rhino scene UserText, but if I do that then the input can’t accept numeric inputs.
Is there any way that I can keep the ‘Type Hint’ on the component set to ‘No Type Hint’ and yet still get access to the Rhino scene object and its UserText values?
just a quick example of the kind of thing I mean would look like:
import Rhino import scriptcontext as sc from contextlib import contextmanager import rhinoscriptsyntax as rs @contextmanager def rhDoc(): try: sc.doc = Rhino.RhinoDoc.ActiveDoc yield finally: sc.doc = ghdoc with rhDoc(): area = 0 for srfcArea in _srfcAreas: try: area += float(srfcArea) print 'Area = ', area except: srfcBrep = rs.coercesurface(srfcArea) print 'Area = ', Rhino.Geometry.AreaMassProperties.Compute(srfcBrep).Area print 'UserText = ', rs.GetUserText(srfcArea, 'my_key')
I can get it to work if I pass the input geom through an ‘ID’ component first, but I don’t like that and would rather that it work without having to have that extra component:
has anyone ever figured out a workaround or method to allow for this kind of thing? Is there a code equivalent to the ‘ID’ component that I could use inline in the script somehow?
any advice is much appreciated! thanks,