def unique_libload(file_path): '''Loads a unique instance of a blend. INPUTS: - file_path - path to the blend file OUTPUTS: - added_objects, the object that were added ''' scene = logic.getCurrentScene() old_objects = scene.objects + scene.objectsInactive f = open(file_path, 'rb').read() identifier = file_path.split('.')[0] + "_lib" + str(.0) while identifier in logic.LibList(): id = identifier.split('.') identifier = id[0] + '.' + str(int(id[1])+1) logic.LibLoad(identifier, 'Scene', f) all_obj = scene.objects + scene.objectsInactive added_objects = [] for o in all_obj: if o not in old_objects: added_objects.append(o) return added_objects
def remove_lib(file_path): if Loadmap.isBlend(file_path): print("removing lib %s" % Loadmap.makeLibName(file_path)) if (Loadmap.makeLibName(file_path) in logic.LibList()): logic.LibFree(Loadmap.makeLibName(file_path)) else: print("lib was not loaded")
def load_blender_file(self, file_name): # Locate the file file_path = self._locate_resource(file_name) if not file_path: print('Failure loading "{}":'.format(file_name)) print(' File not found') return loaded = g.LibList() print(loaded) if file_path in loaded: return # Load it g.LibLoad(file_path, 'Scene', load_actions=True, verbose=True, load_scripts=True) loaded = g.LibList() print(loaded)
def main(): # Just shortening names here keyboard = logic.keyboard JUST_ACTIVATED = logic.KX_INPUT_JUST_ACTIVATED if keyboard.events[events.UKEY] == JUST_ACTIVATED: addedObjects = unique_libload('notEmpty.blend') #for a in addedObjects: # moveObject(a) print("libList",logic.LibList()) print("functions",functions) scene = logic.getCurrentScene() print("scene Objects",scene.objects) print("global dict",logic.globalDict) print("object count", len(scene.objects))
def load_blender_file(self, file_name): """ Loads a blender file. @param file_name An absolute path to the file, or if a relative path such that the file will be looked for in the mission folder, in the user home resources folder, in the execution folder, or finally in the installation folder. @remarks Full scene will be loaded by default. """ # Locate the file file_path = self._locate_resource(file_name) if not file_path: return # Load it if file_path in g.LibList(): return status = g.LibLoad(file_path, 'Scene', load_actions=True, verbose=True, load_scripts=True)