I have been coding in python in grasshopper for about 7 or 8 months now, so I there is plenty I still do not understand. One of the biggest problems I have is getting rhinoscriptsyntax functions (always imported as rs) to do the things they are supposed to do.
For example: I create a brep or a surface component in grasshopper as an input for geometry. I give it list access and type hint GUID.
Then, after making sure the GUID is readable in the script (I always double check, and I save the ID as both a string type and keep the GUID type) I try to use the guid in some rs function, lets say for example rs.GetUserText (to get a value from a key saved in the objects attributes) or rs.SurfaceArea. I input the GUID as I am supposed to, but now in Rhino 7 it returns the error that " âNoneTypeâ object has no attribute âGetUserStringâ, or rs.SurfaceArea simply returns âNoneâ (which means error). I double check the object type to make sure it isnt NoneType⌠it is always either GUID or str, so I donât know why rs is telling me it is NoneType.
Can somebody please shine some light on this situation? It has worked many times in the past for me, but all of a sudden doesnt work anymore.
Also, I do not want to program in C#, I would really like to use rhinoscriptsyntax (thats why it is there!)
Hi Brad - it matters whether the GH object is still a GH object or whether it has been baked into the document. It will not have a GUID if it has noit been baked.
The geometry was created in rhino and brought into the script as an input via an empty surface or brep component for which I set the multiple geometries.
Hi Brad - can you post a simple example Rhino and GH file? I am pretty sure this all works right so there must be something simple, Iâll see if I can spot it.
Hi Pascal, sorry for the late response, I was away for a while. I have posted the files here.
The objective of the script is to be able to take in a set of volumes (building rooms) which have one or more sides which are part of the facade. The script is to tell me which side is the facade (based on the object layer defines as fassade), and get me all the GUIDs of the surfaces which make the room enclosure behind that fassade.
Additionally, it should also give me the info of the Fassadenpegel (sound pressure level on the facade) which is saved in the attributes, so that I can do some math with the information and the geometric properties of the surfaces. Line 42 is where the script fails. You can ignore the stuff below line 47, thats just for later when things start working again.
If you can help me figure out what I am doing wrong, I will be so grateful. I keep coming across similar problems working with the GUIDs. Sometimes it works, sometimes it doesnt, and sometimes scripts that work on my PC donât work on my colleagues computer.
I Also have an issue with rhinoscrptsyntax not finding an object based on its guid. This is the code
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
sc.doc = Rhino.RhinoDoc.ActiveDoc
def get_geometry_of_id_from_rhino(obj_guid):
try:
sc.doc = Rhino.RhinoDoc.ActiveDoc
brep_list = []
for g in obj_guid:
if isinstance(g, str):
guid_obj = Guid.Parse(g)
else:
guid_obj = g
rhino_obj = sc.doc.Objects.FindId(guid_obj)
if rhino_obj is None:
print("Object with GUID", guid_obj, "not found.")
continue
geometry = rhino_obj.Geometry
if isinstance(geometry, Rhino.Geometry.Brep):
brep_list.append(geometry)
else:
print("Object with GUID", guid_obj, "is not a Brep; it is a", type(geometry))
print("Found", len(brep_list), "Brep geometries.")
finally:
sc.doc = ghdoc
On running the code, the objects arenât found (despite being baked in Rhino)
('Object with GUID', <System.Guid object at 0x00000000000000C0 [4579d8ab-21ca-4f68-8de8-d1b876e36b8a]>, 'not found.')
('Object with GUID', <System.Guid object at 0x00000000000000C1 [dd5f09d7-7e0e-4642-a126-24874ae69557]>, 'not found.')
('Object with GUID', <System.Guid object at 0x00000000000000C2 [3c7cf010-a5b3-41b1-aabd-14d2c568ae43]>, 'not found.')
('Object with GUID', <System.Guid object at 0x00000000000000C3 [969d1c53-e42f-47c0-b85d-d2e7bd865cd0]>, 'not found.')
('Found', 0, 'Brep geometries.')```
i wonât be able to post it as its from a large project from my job (non-disclosure thingy)
The idea is that guids are loaded from surfacePoints in grasshopper, so I was tasked in my job (iâm new to grasshopper) to be able to get the brep geometry using the guids supplied. i am unable to get the objects using their individual guids as i always get a None type (i dont know if it is due to the guids addresses constantly changing).
What does the guid belong to? surface points? or the main brep?! Possible to make a small Grasshopper test definition that replicates the problem? Itâs hard to assume where these input guids are coming from without having something to test.
The data inside the wire is geometry and not Guids. This geometry is in Grasshoppers memory and not the Rhino document
Note the Type hint: ghdoc Object...: This is a type hint that is specifically designed to recover actual Rhino objects by their id but it needs Guids as input and does not do anything with other data.
I would need to know the problem you are trying to solve in a larger context. What data do you have? How does the GH definition is working with this data? What is the expected end result.
Again without seeing and working with a small Grasshopper document that replicates this context, it is very hard to provide any suggestions
Ok, so in a larger context, the request of the task is to take any input geometry (like a cube or individual surfaces) and break it down into all its individual surfaces. For example, a cube would be divided into its 6 faces. Each of these surfaces should then be given its own unique identifier. Finally, regardless of whether the input included one cube and a couple of separate surfaces (making, say, 8 surfaces in total), all these surfaces should be gathered into one single, flat list.
Also, I wish I could replicate the project in a small grasshopper document however, its a very large project, and the surface points come from a nest of points that I am unable to replicate on a small document. Please bear with me on that.
Okay here is an example (open files below in Rhino and GH)
Box is a Rhino object
Box in Rhino is referenced by Brep parameter on Grasshopper canvas
The Brep (Box) is deconstructed to get the surfaces
(1) each surface is being passed into the script component. The surface input parameter has a Type Hint of ghdoc Object. So when the surface is being passed into the script component, the Type Hint grabs that surface and injects that into a temporary Rhino document that is only open in memory and not the UI. Then it replaces the value of surface with the Guid of that new surface object. Note that this temporary document is only in-memory and these surfaces are not added to the actual Rhino document.
The script assigns surface to output parameter a, passing the Guid to the output
(2) Normally on the way out, the output parameter a, the Guid is then looked up in the temporary document and the actual surface object is recovered and assigned to the output. However in this example I have turned on the âAvoid Marshalling Output Guidsâ to force the component to avoid the lookup, and just pass the Guids to the output.