Source code for liatool.utils

import bpy

[docs] def addObjectToCollection(object, collectionName): createCollection = True for collection in bpy.data.collections: if collection.name == collectionName: createCollection = False break myCollection = None if createCollection: myCollection = bpy.data.collections.new(collectionName) bpy.context.scene.collection.children.link(myCollection) else: myCollection = bpy.data.collections[collectionName] for collection in object.users_collection: collection.objects.unlink(object) myCollection.objects.link(object)
[docs] def copyProperties(source, target): if not hasattr(source, "__annotations__"): return for prop_name in source.__annotations__.keys(): try: if prop_name == 'set_default_params': continue setattr(target, prop_name, getattr(source, prop_name)) except (AttributeError, TypeError): for source_item in getattr(source, prop_name): target_item = getattr(target, prop_name).add() for prop_name in source_item.__annotations__.keys(): if prop_name == 'set_default_params': continue setattr(target_item, prop_name, getattr(source_item, prop_name))
[docs] def completeDeselect(): if bpy.context.mode != 'EDIT': try: bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='DESELECT') except Exception: pass if bpy.context.mode != 'OBJECT': try: bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.select_all(action='DESELECT') except Exception: pass
[docs] def selectOnlyObj(obj): bpy.context.view_layer.objects.active = obj completeDeselect() if bpy.context.mode != 'OBJECT': bpy.ops.object.mode_set(mode='OBJECT') obj.select_set(True) bpy.context.view_layer.objects.active = obj
[docs] def updateDomainsState(): invalid = True while invalid: invalid = False idx = 0 for domain in bpy.context.scene.ilsp_iLspDomains: if domain.domain_object is None: bpy.context.scene.ilsp_iLspDomains.remove(idx) invalid = True break idx += 1
[docs] def initDomainsState(): invalid = True while invalid: invalid = False idx = 0 for domain in bpy.context.scene.ilsp_iLspDomains: if domain.domain_object is None: bpy.context.scene.ilsp_iLspDomains.remove(idx) invalid = True break idx += 1
[docs] def domainsExists(): try: if len(bpy.context.scene.ilsp_iLspDomains) > 0: return True except Exception: pass return False
[docs] def getDomainByDomainObj(domainObject): updateDomainsState() for domain in bpy.context.scene.ilsp_iLspDomains: if domainObject == domain.domain_object: return domain return None
[docs] def switchToMaterialMode(): for window in bpy.context.window_manager.windows: for area in window.screen.areas: # iterate through areas in current screen if area.type == 'VIEW_3D': for space in area.spaces: # iterate through spaces in current VIEW_3D area if space.type == 'VIEW_3D': # check if space is a 3D view space.shading.type = 'MATERIAL'