Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. import bpy
  2. import os
  3. import datetime
  4.  
  5. #shortcuts
  6. context = bpy.context
  7. scene = context.scene
  8. A = context.object
  9. S = bpy.context.selected_objects
  10.  
  11. #Date name and .blend name
  12. time = datetime.datetime.now()
  13. date= time.strftime("__%Y-%m-%d_%HH%MM%S")
  14. datecol= time.strftime("%m-%d_%HH%MM%S")
  15. blend = bpy.path.basename(bpy.data.filepath)[:-6]
  16.  
  17. #Collection Copies
  18. def find_collection(context, item):
  19. collections = item.users_collection
  20. if len(collections) > 0:
  21. return collections[0]
  22. return context.scene.collection
  23.  
  24. def make_collection(collection_name, parent_collection):
  25. if collection_name in bpy.data.collections:
  26. return bpy.data.collections[collection_name]
  27. else:
  28. new_collection = bpy.data.collections.new(collection_name)
  29. parent_collection.children.link(new_collection)
  30. return new_collection
  31. name = "Copies"
  32.  
  33. #Collection Date
  34. def make_collection(collection_namme, parent_collection):
  35. if collection_namme in bpy.data.collections:
  36. return bpy.data.collections[collection_namme]
  37. else:
  38. new_collection = bpy.data.collections.new(collection_namme)
  39. parent_collection.children.link(new_collection)
  40. return new_collection
  41. namme = datecol
  42.  
  43. #Dupplicate selection and move it to scene master collection
  44. bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'})
  45. bpy.ops.object.move_to_collection(collection_index=0)
  46.  
  47. #move every object to new collection
  48. for C in bpy.context.selected_objects:
  49. C.name = C.name + " Copy"
  50.  
  51. C_collection = find_collection(bpy.context, C)
  52. new_collection = make_collection(name , C_collection)
  53. new_collection.objects.link(C)
  54. C_collection.objects.unlink(C)
  55.  
  56. bpy.data.collections["Copies"].hide_select = True
  57. bpy.data.collections["Copies"].hide_render = True
  58. bpy.data.collections["Copies"].hide_viewport = True
  59.  
  60. C_collection = find_collection(bpy.context, C)
  61. new_collection = make_collection(namme , C_collection)
  62. new_collection.objects.link(C)
  63. C_collection.objects.unlink(C)
  64.  
  65. bpy.data.collections[datecol].hide_select = True
  66. bpy.data.collections[datecol].hide_render = True
  67. bpy.data.collections[datecol].hide_viewport = True
  68.  
  69. bpy.context.view_layer.objects.active = A
  70. for ob in S:
  71. ob.select_set(state=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement