Object Expired During a Solution

I’m trying to write a python component that imports geometry from one or more Rhino files. It mostly works, except before completing, the component throws a series of “Object Expired During a Solution” errors. Once I close all the error boxes, the import succeeds as expected. I attached the user object and screenshots of a few of the errors here. There are no infinite loops in my code, as far as I can tell. Does anyone know why this is happening?

Batch Import.ghuser (3.1 KB)

This doesn’t require an infinite loop, it just means you modified some objects from inside a solution (where your script code runs).

The usual fix here is to schedule another solution using GH_Document.ScheduleSolution(callback), and then make your changes from within the callback.

Another approach might be handling the SolutionStart event and making changes there.

1 Like

Hmm… I don’t think I understand. I’m not sure where objects are being modified, so I tried simplifying the component to just import Rhino files into a new Rhino file (the geometry does not enter the grasshopper script space):

    def importRhinoFile(self, fileNames, sourcePath):
        #file import
        for fn in fileNames:
            thisFilePath = os.path.join(sourcePath,fn)
            importCommandString = '_-Import "' + thisFilePath + '" _Enter'
            imported = rs.Command(importCommandString, echo=False)
            if not imported:
                print "there was a problem with file: " + fn

As I understand it, I’m modifying objects in the Rhino document space but not the grasshopper space. Unfortunately, the same error(s) still pop up. I’m not sure where I would put GH_Document.SolutionStart() to fix the error. Any pointers?