Forum Discussion
9 years ago
"IngeJones;899528" wrote:
Is the following function referring to the object Tuning IDs? And if so, please could you give me an example of use since the existing decompiled scripts don't seem to use it at all.
def get_objects_of_def_id_gen(self, *definition_ids): - defines function "Get all objects within ID list definition_ids"
for obj in self._objects.values() - Loops the loaded resource array for the manager.
while any(obj.definition.id == d_id for d_id in definition_ids): - While definition.id of obj in array matches any id in list definition_ids, (you can change this to an if statement if you wish)
yield obj - yield object (The output of the function will be the array of object instances with matching definition ids)
Just loop the output and do whatever you desire with the instance array.
There are many ways to get these lists and instances however it would be easier to use the object and instance managers if you already have the definition ids and you can create your own array. You should test the resource lists if you want to understand the managers and how to fully utilize them.
The simpler equivalent of the above would be the following:
obj_manager = services.object_manager()
definition_ids =
obj_list = []
loaded_obj_list = obj_manager.get_all()
for obj in loaded_obj_list:
for definition_id in definition_ids:
if obj.definition.id == definition_id:
obj_list.append(obj)
return obj_list
If you only want to work with tuning then the following will be the equivalent however you will need to instantiate the objects:
instance_manager = services.get_instance_manager(resource_type)
tuning_instance_ids =
tuning_list = []
for tuning_instance_id in tuning_instance_ids:
tuned_instance = instance_manager.get(tuning_instance_id)
if tuned_instance:
tuning_list.append(tuned_instance)
else:
output("The manager did not return a tuning instance for id " + repr(tuning_instance_id))
return tuning_list