Python component: object not set to an instance until we hit test button

Hi all,

I have a few python components following the MyComponent class setup. However sometimes they fail on their first run, and enabling/disabling the component does not fix it. However, opening the script editor and hitting the test/run buttons fix it. Any clues?

python

python2

Hi
Can you share what is the exact error is?
I had the same situation with my compiled component, Expiring the component after init helped me.

Error was
the error is object not set to an instance

But i can’t get line number and i can’t debug, because as soon as i run it with the test button in the editor, the error disappears. Clue of missing line numbers if the error is in overwrite methods, or in classes not part of the MyComponent class.

Your comment on init got me to look new places in my componet.
I have a RhinoRoom class in here which had a init that required a dictionary in the constructor.

I might have fixed it by changed the below. I changed:

class RhinoRoom:
    Geometry = None
    Name = "RhinoRoom"
    Values = {}
    Points = []
    
    
    def __init__(self, dict):
        self.Values = dict
        if dict.ContainsKey("Name") and dict["Name"] != None:
            self.Name = dict["Name"]
        

to

class RhinoRoom:
    Geometry = None
    Name = "RhinoRoom"
    Values = {}
    Points = []
    
    
    def __init__(self, dict = None):
        if dict is not None:
            self.Values = dict
            if dict.ContainsKey("Name") and dict["Name"] != None:
                self.Name = dict["Name"]
        else:
            self.Values = {}
1 Like

Not sure if this will fix (the error message is not very specific unfortunately), try changing your variable name from ‘dict’ to something else. dict is a reserved keyword.

Also I would move the static variable Values into the init.

def __init__(self, values={}):
    self.Values = values
    self.Name = self.Values.get('Name', 'RhinoRoom')
1 Like

ah yeah, thanks!

“someone” forced me out of c# comfort zone and into dangerous unsafe python environment and thus a minefield of new keywords to avoid.

The above fix that I wrote about did it though, even with the wrong usage of dict keyword (i might have been lucky).

2 Likes

This might also be relevant here (and just in general):

1 Like