blender
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| blender [2022/02/07 13:29] – external edit 127.0.0.1 | blender [2023/05/17 09:27] (current) – ssm2017 | ||
|---|---|---|---|
| Line 550: | Line 550: | ||
| </ | </ | ||
| the object needs to dont have any “transformation” | the object needs to dont have any “transformation” | ||
| + | |||
| + | ==== inventory ==== | ||
| + | <sxh python> | ||
| + | import bpy | ||
| + | import csv | ||
| + | |||
| + | def displayLine(title, | ||
| + | print(title+ " : "+ str(qty)+ " | ||
| + | |||
| + | def cherche(): | ||
| + | # get selection | ||
| + | selected_objects = bpy.context.selected_objects | ||
| + | |||
| + | inventory = { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | # solives | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | # lambourdes | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | # profil de descente | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | # plots | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | # lames (7 par m² donc a 90€ le m² ça fait 12.85 la lame) | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | # scotch | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | |||
| + | # do the job | ||
| + | for o in selected_objects: | ||
| + | if o.type != ' | ||
| + | # get the object' | ||
| + | object_name = o.name | ||
| + | |||
| + | for item, details in inventory.items(): | ||
| + | if object_name.__contains__(item): | ||
| + | details[" | ||
| + | # longueur bande adhesive | ||
| + | if object_name.__contains__(" | ||
| + | inventory[" | ||
| + | if object_name.__contains__(" | ||
| + | inventory[" | ||
| + | if object_name.__contains__(" | ||
| + | inventory[" | ||
| + | if object_name.__contains__(" | ||
| + | inventory[" | ||
| + | # longueur lambourde a decouper | ||
| + | if object_name.__contains__(" | ||
| + | inventory[" | ||
| + | if object_name.__contains__(" | ||
| + | inventory[" | ||
| + | # longueur profil de descente | ||
| + | if object_name.__contains__(" | ||
| + | inventory[" | ||
| + | return inventory | ||
| + | |||
| + | def montre(inventory): | ||
| + | total_price = 0 | ||
| + | for item, value in inventory.items(): | ||
| + | if not item.__contains__(" | ||
| + | and not item.__contains__(" | ||
| + | and not item.__contains__(" | ||
| + | and not item.__contains__(" | ||
| + | if value[" | ||
| + | print(item) | ||
| + | print(" | ||
| + | print(" | ||
| + | price = value[" | ||
| + | total_price += price | ||
| + | print(" | ||
| + | print(" | ||
| + | print(" | ||
| + | |||
| + | def writeCSV(inventory): | ||
| + | total_price = 0 | ||
| + | rows = [[' | ||
| + | for item, value in inventory.items(): | ||
| + | if not item.__contains__(" | ||
| + | and not item.__contains__(" | ||
| + | and not item.__contains__(" | ||
| + | and not item.__contains__(" | ||
| + | if value[" | ||
| + | price = value[" | ||
| + | rows.append([item, | ||
| + | |||
| + | with open(bpy.path.abspath("//" | ||
| + | writer = csv.writer(file, | ||
| + | writer.writerows(rows) | ||
| + | | ||
| + | print(" | ||
| + | bpy.ops.object.select_all(action=' | ||
| + | # get collection | ||
| + | col = bpy.data.collections[" | ||
| + | |||
| + | # get all children collections recursively | ||
| + | for subcol in col.children_recursive: | ||
| + | for obj in col.all_objects: | ||
| + | obj.select_set(True) | ||
| + | |||
| + | |||
| + | inventory = cherche() | ||
| + | montre(inventory) | ||
| + | writeCSV(inventory) | ||
| + | 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.1644236959.txt.gz · Last modified: by 127.0.0.1
