0

I'm trying to create a class with several list attributes and a method inside in Revit API.

This class is to check some shared parameters that indicate the template version of a model and collect the relevant parameters.

I guess my main question is about how to append items from the method to the list attributes of the class.

Advice would be much appreciated!

class TemplateChecker(object):
    def __init__(self):
        self.version_old = []
        self.version_new = []
        self.version_unknown = []
        self.sp_collection = lib.get_shared_parameters()

    def is_new_template(self):
        found_parameter = False

        for parameter in self.sp_collection:
            if parameter.Name == "TemplateVersion-New":
                self.version_new.append(parameter)
                found_parameter = True
            elif parameter.Name == "TemplateVersion-Old":
                self.version_old.append(parameter)
                found_parameter = False
            elif "template" in parameter.Name.lower():
                self.version_unknown.append(parameter)
                found_parameter = False

        return found_parameter
Yongjoon Kim
  • 107
  • 1
  • 8
  • The same way you append to any list, in this case, for example, `self.version_new.append(parameter)`, exactly as you are doing. – juanpa.arrivillaga Feb 04 '20 at 00:54
  • Terminology note, this isn't a "class object". A "call object" in python refers to an object *which is a class*, since in Python, **everything** is an object, including classes. You are trying to append to and object which is an *instance* of a class. Normally, you just say "object" in Python. – juanpa.arrivillaga Feb 04 '20 at 00:57
  • 1
    Side comment: your found_paramater variable will depend only on the last parameter in sp_collection. I guess that's not what you're intending to do. From your method name, I sense that you want to check if there is a new parameter, is that right? In that case you may need to break after you've found your parameter or not set it to false in the other two branches. – Nagabhushan S N Feb 04 '20 at 02:08
  • I don't understand what is the meaning of `found_parameter` , but that `for` loop will return the state of the last `parameter`, is that you want? – Andrex Feb 04 '20 at 02:09
  • And maybe you can construct your lists parameters at the init, and not defining as empty lists. – Andrex Feb 04 '20 at 02:10
  • It’s not directly related to your question, but I would recommend reexamining whether or not a class is the best choice for this. – AMC Feb 04 '20 at 04:31

0 Answers0