Python : 'NoneType' object has no attribute 'Geometry'

Hello !!

I have successfully been working with a simple python script exporting STL files for months. It was part of a much bigger python script etc.

It suddenly stopped working and I cannot even get my very first downloaded (?) script to work. I did not update anything, kept working with Rhino 6, same Python, same everything. I know this is the usual newby beginner statement. hahaha

I get the following error:
‘NoneType’ object has no attribute ‘Geometry’

Component inputs and settings are the same (Type Hint + List Access). This is the same gh file that was working before.
I also removed the “cache” just in case even though I do not think that is the problem.

What did change ? Why my coercerhinoobject cannot retrieve the geometry etc ?

THANK YOU !!

bake_into_rhinov3.gh (7.7 KB)

It is happening in BatchExportSTLByObject:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import subprocess

def GetSTLSettings():
    e_str = "_ExportFileAs=_Binary "
    e_str+= "_ExportUnfinishedObjects=_Yes "
    e_str+= "_UseSimpleDialog=_Yes "
    e_str+= "_UseSimpleParameters=_Yes "
    e_str+= "_Enter _Enter"
    return e_str

def BatchExportSTLByObject():

    filepath=rs.DocumentPath()
    stl_sett = GetSTLSettings()

    if active:
    for i in range(len(geo)):

        e_file_name = "{}-{}.stl".format(filename, str(i))
        geo_id = geo[i]
        doc_object = rs.coercerhinoobject(geo_id)

        geometry = doc_object.Geometry
        attributes = doc_object.Attributes

        # -----> we change the scriptcontext
        sc.doc = Rhino.RhinoDoc.ActiveDoc

        #we add both the geometry and the attributes to the Rhino doc
        rhino_line = sc.doc.Objects.Add(geometry, attributes)

        rs.SelectObject(rhino_line)
        # <----- we put back the original Grasshopper document as default
        sc.doc = ghdoc

        rs.Command("-_Export " + filepath + e_file_name + " " + stl_sett, False)

        # -----> we change the scriptcontext
        sc.doc = Rhino.RhinoDoc.ActiveDoc
        rs.DeleteObject(rhino_line)
        # <----- we put back the original Grasshopper document as default
        sc.doc = ghdoc

BatchExportSTLByObject()
sc.doc = Rhino.RhinoDoc.ActiveDoc

return_code = subprocess.call("echo Hello World", shell=True)
print(return_code)

Perhaps you may change the type hint to Guid.

1 Like

Hello !

Thanks !
Yes, I did that; from GHDoc Object to Mesh.
I does not work neither.

Ummm, reading your code, I think you cannot use Grasshopper objects as the input.
Just change the type hint to Guid, and then reference geometries placed in a Rhino document.

Thanks !

How would you do this ?

And do you know why it was working like a charm before… :slight_smile:
Before what is the question… I feel something happened outside of the patch.

Using a type hint as Mesh would be great though.

Hi, to the best of my knowledge, geometries in a Grasshopper document do not have attributes at all.
So, if your script is attempting to access the object attributes, it means it was referencing geometries placed in a Rhino document (or rhinoscriptsyntaxcontext) before.

I see…
You mean baked geometries ?
When I bake those two meshes and select them into rhino, I still get the error. Probably meaning Rhino and GH have no object id in common after baking.

In any case, I wanted to get the meshes attribute without baking them into rhino.

You are super helpful because I am a bit desperate.
I have a theory: I was maybe testing on some cached baked hidden files in the past without knowing it. I changed the current folder name this morning and lost those baked files. That showed that my code did actually never worked. My 0.00002 cent

I made it work.
I have to run now but I will come back here ASAP !!

I replaced all the stuff concerning “GHDoc Object” into Mesh type. And it works.

I still wonder if I was not confused for months because of a deleted “cache” or change of path. I saw there were some things “cached” in Rhino but I do not know what.

Anyway, a big thank you mikity_kogekoge !!

I think this is where your script came from.

And it seems like you need one more sc.doc=ghdoc somewhere very beginning.

Yes indeed !!! :slight_smile:
This ghdoc is super great…