blender
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| blender [2023/05/10 14:21] – ssm2017 | blender [2023/05/17 09:27] (current) – ssm2017 | ||
|---|---|---|---|
| Line 728: | Line 728: | ||
| writeCSV(inventory) | writeCSV(inventory) | ||
| print(" | print(" | ||
| + | </ | ||
| + | |||
| + | ==== script as module ==== | ||
| + | <sxh python> | ||
| + | import bpy | ||
| + | my_module = bpy.data.texts[" | ||
| + | |||
| + | my_module.toto() | ||
| + | </ | ||
| + | |||
| + | ==== delete collection ==== | ||
| + | <sxh python> | ||
| + | # source : https:// | ||
| + | |||
| + | import bpy | ||
| + | #from bpy import context | ||
| + | |||
| + | |||
| + | name = " | ||
| + | remove_collection_objects = True | ||
| + | |||
| + | #coll = context.collection # | ||
| + | coll = bpy.data.collections.get(name) | ||
| + | |||
| + | if coll: | ||
| + | if remove_collection_objects: | ||
| + | obs = [o for o in coll.objects if o.users == 1] | ||
| + | while obs: | ||
| + | bpy.data.objects.remove(obs.pop()) | ||
| + | |||
| + | bpy.data.collections.remove(coll) | ||
| + | </ | ||
| + | |||
| + | ==== duplicate collection linked ==== | ||
| + | <sxh python> | ||
| + | import bpy | ||
| + | |||
| + | def duplicate_collection_by_name(collection_name): | ||
| + | original_collection = bpy.data.collections.get(collection_name) | ||
| + | | ||
| + | if original_collection is None: | ||
| + | print(f" | ||
| + | return | ||
| + | | ||
| + | new_collection = original_collection.copy() | ||
| + | new_collection.name = f" | ||
| + | | ||
| + | bpy.context.scene.collection.children.link(new_collection) | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== duplicate collection ==== | ||
| + | <sxh python> | ||
| + | import bpy | ||
| + | |||
| + | def duplicate_collection_by_name(collection_name): | ||
| + | original_collection = bpy.data.collections.get(collection_name) | ||
| + | | ||
| + | if original_collection is None: | ||
| + | print(f" | ||
| + | return | ||
| + | | ||
| + | new_collection = bpy.data.collections.new(f" | ||
| + | bpy.context.scene.collection.children.link(new_collection) | ||
| + | | ||
| + | for obj in original_collection.objects: | ||
| + | new_object = obj.copy() | ||
| + | new_object.data = obj.data.copy() | ||
| + | new_collection.objects.link(new_object) | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== delete empty collection ==== | ||
| + | <sxh python> | ||
| + | import bpy | ||
| + | |||
| + | def delete_empty_collections(): | ||
| + | collections = bpy.data.collections | ||
| + | | ||
| + | for collection in collections: | ||
| + | if len(collection.objects) == 0: | ||
| + | bpy.data.collections.remove(collection, | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== delete collection and its content ==== | ||
| + | <sxh python> | ||
| + | import bpy | ||
| + | |||
| + | def delete_collection_by_name(collection_name): | ||
| + | collection = bpy.data.collections.get(collection_name) | ||
| + | | ||
| + | if collection is not None: | ||
| + | bpy.data.collections.remove(collection, | ||
| + | else: | ||
| + | print(f" | ||
| </ | </ | ||
| {{tag> | {{tag> | ||
blender.1683721272.txt.gz · Last modified: by ssm2017
