blender
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| blender [2023/05/16 15:17] – ssm2017 | blender [2023/05/17 09:27] (current) – ssm2017 | ||
|---|---|---|---|
| Line 759: | Line 759: | ||
| bpy.data.collections.remove(coll) | 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) | ||
| + | |||
| </ | </ | ||
| Line 765: | Line 783: | ||
| import bpy | import bpy | ||
| - | # deselect all | + | def duplicate_collection_by_name(collection_name): |
| - | bpy.ops.object.select_all(action='DESELECT') | + | |
| - | # get collection | + | |
| - | col = bpy.data.collections["tdg"] | + | if original_collection is None: |
| + | print(f" | ||
| + | | ||
| + | |||
| + | new_collection | ||
| + | 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) | ||
| + | </ | ||
| - | for window in bpy.context.window_manager.windows: | + | ==== delete empty collection ==== |
| - | screen | + | <sxh python> |
| + | import bpy | ||
| - | | + | def delete_empty_collections(): |
| - | if area.type == ' | + | collections = bpy.data.collections |
| - | override = {' | + | |
| - | bpy.ops.outliner.collection_duplicate(override) | + | |
| - | break | + | if len(collection.objects) |
| - | + | bpy.data.collections.remove(collection, do_unlink=True) | |
| - | # bpy.ops.outliner.item_activate(deselect_all=True) | + | |
| - | # bpy.ops.outliner.delete(hierarchy=True) | + | </ |
| + | |||
| + | ==== delete | ||
| + | <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.1684243078.txt.gz · Last modified: by ssm2017
