diff options
author | NBurn <7nburn@gmail.com> | 2019-01-29 18:54:49 +0300 |
---|---|---|
committer | NBurn <7nburn@gmail.com> | 2019-01-29 18:54:49 +0300 |
commit | d609009748a604c1df2d8babfa4098260666d01a (patch) | |
tree | 98150e04df48252889e2fc8e049c13115e0afe72 /add_advanced_objects_menu | |
parent | 5c994fde52196dfe8a7e0db03b6935bac001d353 (diff) |
addons: objects.link/unlink syntax update
Changed objects.link and objects.unlink from scene to collection
Diffstat (limited to 'add_advanced_objects_menu')
-rw-r--r-- | add_advanced_objects_menu/add_light_template.py | 6 | ||||
-rw-r--r-- | add_advanced_objects_menu/arrange_on_curve.py | 6 | ||||
-rw-r--r-- | add_advanced_objects_menu/copy2.py | 26 | ||||
-rw-r--r-- | add_advanced_objects_menu/cubester.py | 4 | ||||
-rw-r--r-- | add_advanced_objects_menu/make_struts.py | 2 | ||||
-rw-r--r-- | add_advanced_objects_menu/oscurart_chain_maker.py | 6 | ||||
-rw-r--r-- | add_advanced_objects_menu/random_box_structure.py | 2 | ||||
-rw-r--r-- | add_advanced_objects_menu/trilighting.py | 9 |
8 files changed, 31 insertions, 30 deletions
diff --git a/add_advanced_objects_menu/add_light_template.py b/add_advanced_objects_menu/add_light_template.py index 2ca87c3b..3d6d880e 100644 --- a/add_advanced_objects_menu/add_light_template.py +++ b/add_advanced_objects_menu/add_light_template.py @@ -19,7 +19,7 @@ def add_lights(self, context): constraint.track_axis = 'TRACK_NEGATIVE_Z' constraint.up_axis = 'UP_X' constraint.owner_space = 'LOCAL' - bpy.context.scene.objects.link(ob) + bpy.context.collection.objects.link(ob) ob.rotation_euler[2] = -0.785398 if self.bFillLight: @@ -34,7 +34,7 @@ def add_lights(self, context): constraint.track_axis = 'TRACK_NEGATIVE_Z' constraint.up_axis = 'UP_X' constraint.owner_space = 'LOCAL' - bpy.context.scene.objects.link(ob) + bpy.context.collection.objects.link(ob) ob.rotation_euler[2] = 0.785398 ob.data.energy = 0.3 @@ -50,7 +50,7 @@ def add_lights(self, context): constraint.track_axis = 'TRACK_NEGATIVE_Z' constraint.up_axis = 'UP_X' constraint.owner_space = 'LOCAL' - bpy.context.scene.objects.link(ob) + bpy.context.collection.objects.link(ob) ob.rotation_euler[2] = 3.14159 ob.data.energy = 0.2 diff --git a/add_advanced_objects_menu/arrange_on_curve.py b/add_advanced_objects_menu/arrange_on_curve.py index 2e1ff4bd..38fbb92a 100644 --- a/add_advanced_objects_menu/arrange_on_curve.py +++ b/add_advanced_objects_menu/arrange_on_curve.py @@ -266,7 +266,7 @@ class DupliCurve(Operator): j += 1 dx -= dist # Calculating the remaining length of the section obj = object.copy() - context.scene.objects.link(obj) + context.collection.objects.link(obj) obj.matrix_world = quat * yawMatrix * pitchMatrix * rollMatrix # Placing in the correct position obj.matrix_world.translation = point - v_norm * dx @@ -296,7 +296,7 @@ class DupliCurve(Operator): j += 1 dx -= dist # Calculating the remaining length of the section obj = object.copy() - context.scene.objects.link(obj) + context.collection.objects.link(obj) obj.matrix_world = quat * yawMatrix * pitchMatrix * rollMatrix # Placing in the correct position obj.matrix_world.translation = point - v_norm * dx @@ -332,7 +332,7 @@ class DupliCurve(Operator): object = G_Objeto[j % len(G_Objeto)] j += 1 obj = object.copy() - context.scene.objects.link(obj) + context.collection.objects.link(obj) obj.matrix_world = quat * yawMatrix * pitchMatrix * rollMatrix # Placing in the correct position obj.matrix_world.translation = point - v_norm * dx diff --git a/add_advanced_objects_menu/copy2.py b/add_advanced_objects_menu/copy2.py index 0492a089..5b1bceb1 100644 --- a/add_advanced_objects_menu/copy2.py +++ b/add_advanced_objects_menu/copy2.py @@ -139,7 +139,7 @@ class Copy2(Operator): return {"CANCELLED"} try: copy_to_from( - context.scene, + context.collection, copy_to_object, copy_from_object, self.copytype, @@ -162,18 +162,18 @@ class Copy2(Operator): return {"FINISHED"} -def copy_to_from(scene, to_obj, from_obj, copymode, axes, edgescale, scale): +def copy_to_from(collection, to_obj, from_obj, copymode, axes, edgescale, scale): if copymode == 'V': - vertex_copy(scene, to_obj, from_obj, axes) + vertex_copy(collection, to_obj, from_obj, axes) if copymode == 'E': # don't pass edgescalling to object types that cannot be scaled if from_obj.type in ["CAMERA", "LIGHT", "EMPTY", "ARMATURE", "SPEAKER", "META"]: edgescale = False - edge_copy(scene, to_obj, from_obj, axes, edgescale, scale) + edge_copy(collection, to_obj, from_obj, axes, edgescale, scale) if copymode == 'F': - face_copy(scene, to_obj, from_obj, axes) + face_copy(collection, to_obj, from_obj, axes) axes_dict = {'XY': (1, 2, 0), @@ -184,13 +184,13 @@ axes_dict = {'XY': (1, 2, 0), 'ZY': (1, 0, 2)} -def copyto(scene, source_obj, pos, xdir, zdir, axes, scale=None): +def copyto(collection, source_obj, pos, xdir, zdir, axes, scale=None): """ copy the source_obj to pos, so its primary axis points in zdir and its secondary axis points in xdir """ copy_obj = source_obj.copy() - scene.objects.link(copy_obj) + collection.objects.link(copy_obj) xdir = xdir.normalized() zdir = zdir.normalized() @@ -219,7 +219,7 @@ def copyto(scene, source_obj, pos, xdir, zdir, axes, scale=None): return copy_obj -def vertex_copy(scene, obj, source_obj, axes): +def vertex_copy(collection, obj, source_obj, axes): # vertex select mode sel_verts = [] copy_list = [] @@ -249,7 +249,7 @@ def vertex_copy(scene, obj, source_obj, axes): xdir = edir - edir.dot(zdir) * zdir xdir = -xdir.normalized() - copy = copyto(scene, source_obj, pos, xdir, zdir, axes) + copy = copyto(collection, source_obj, pos, xdir, zdir, axes) copy_list.append(copy) # select all copied objects @@ -258,7 +258,7 @@ def vertex_copy(scene, obj, source_obj, axes): obj.select_set(False) -def edge_copy(scene, obj, source_obj, axes, es, scale): +def edge_copy(collection, obj, source_obj, axes, es, scale): # edge select mode sel_edges = [] copy_list = [] @@ -292,7 +292,7 @@ def edge_copy(scene, obj, source_obj, axes, es, scale): i = list('XYZ').index(axes[1]) escale[i] = scale * xlen / source_obj.dimensions[i] - copy = copyto(scene, source_obj, pos, xdir, zdir, axes, scale=escale) + copy = copyto(collection, source_obj, pos, xdir, zdir, axes, scale=escale) copy_list.append(copy) # select all copied objects @@ -301,7 +301,7 @@ def edge_copy(scene, obj, source_obj, axes, es, scale): obj.select_set(False) -def face_copy(scene, obj, source_obj, axes): +def face_copy(collection, obj, source_obj, axes): # face select mode sel_faces = [] copy_list = [] @@ -318,7 +318,7 @@ def face_copy(scene, obj, source_obj, axes): fn = (f.center + f.normal) * obj.matrix_world.transposed() - fco fn = fn.normalized() - copy = copyto(scene, source_obj, fco, vco - fco, fn, axes) + copy = copyto(collection, source_obj, fco, vco - fco, fn, axes) copy_list.append(copy) # select all copied objects diff --git a/add_advanced_objects_menu/cubester.py b/add_advanced_objects_menu/cubester.py index 20ebb2aa..8925171a 100644 --- a/add_advanced_objects_menu/cubester.py +++ b/add_advanced_objects_menu/cubester.py @@ -199,7 +199,7 @@ def create_mesh_from_audio(self, context, verts, faces): mesh = bpy.data.meshes.new("cubed") mesh.from_pydata(verts, [], faces) ob = bpy.data.objects.new("cubed", mesh) - bpy.context.scene.objects.link(ob) + bpy.context.collection.objects.link(ob) bpy.context.view_layer.objects.active = ob ob.select_set(True) @@ -414,7 +414,7 @@ def create_mesh_from_image(self, scene, verts, faces): mesh = bpy.data.meshes.new("cubed") mesh.from_pydata(verts, [], faces) ob = bpy.data.objects.new("cubed", mesh) - context.scene.objects.link(ob) + context.collection.objects.link(ob) context.view_layer.objects.active = ob ob.select_set(True) diff --git a/add_advanced_objects_menu/make_struts.py b/add_advanced_objects_menu/make_struts.py index 57cede0a..547fb2f5 100644 --- a/add_advanced_objects_menu/make_struts.py +++ b/add_advanced_objects_menu/make_struts.py @@ -491,7 +491,7 @@ def create_struts(self, context, ind, od, segments, solid, loops, manifold): mesh = bpy.data.meshes.new("Struts") mesh.from_pydata(verts, [], faces) obj = bpy.data.objects.new("Struts", mesh) - bpy.context.scene.objects.link(obj) + bpy.context.collection.objects.link(obj) obj.select_set(True) obj.location = truss_obj.location bpy.context.view_layer.objects.active = obj diff --git a/add_advanced_objects_menu/oscurart_chain_maker.py b/add_advanced_objects_menu/oscurart_chain_maker.py index b6fca005..a553ae48 100644 --- a/add_advanced_objects_menu/oscurart_chain_maker.py +++ b/add_advanced_objects_menu/oscurart_chain_maker.py @@ -90,7 +90,7 @@ def makeChain(self, context, mult, curverig): (23, 22, 19, 18), (21, 17, 14, 20), (15, 23, 18, 12)] ) mesh.validate() - bpy.context.scene.objects.link(object) + bpy.context.collection.objects.link(object) # scale to the bone bpy.data.objects["HardLink" + str(hueso.name)].scale = (hueso.length * mult, hueso.length * mult, @@ -142,7 +142,7 @@ def makeChain(self, context, mult, curverig): (22, 21, 20, 19), (23, 22, 19, 18), (21, 17, 14, 20), (15, 23, 18, 12)] ) mesh.validate() - bpy.context.scene.objects.link(object) + bpy.context.collection.objects.link(object) # scale to the bone bpy.data.objects["NewLink" + str(hueso.name)].scale = (hueso.length * mult, hueso.length * mult, @@ -171,7 +171,7 @@ def makeChain(self, context, mult, curverig): # create data and link the object to the scene crv = bpy.data.curves.new("CurvaCable", "CURVE") obCable = bpy.data.objects.new("Cable", crv) - bpy.context.scene.objects.link(obCable) + bpy.context.collection.objects.link(obCable) # set the attributes crv.dimensions = "3D" diff --git a/add_advanced_objects_menu/random_box_structure.py b/add_advanced_objects_menu/random_box_structure.py index dfa151cf..9de32146 100644 --- a/add_advanced_objects_menu/random_box_structure.py +++ b/add_advanced_objects_menu/random_box_structure.py @@ -184,7 +184,7 @@ class makestructure(Operator): bpy.context.view_layer.objects.active = select if self.dc is True: - bpy.context.scene.objects.unlink(obj) + bpy.context.collection.objects.unlink(obj) return {'FINISHED'} diff --git a/add_advanced_objects_menu/trilighting.py b/add_advanced_objects_menu/trilighting.py index 0a6c0ce4..8fee580b 100644 --- a/add_advanced_objects_menu/trilighting.py +++ b/add_advanced_objects_menu/trilighting.py @@ -113,6 +113,7 @@ class TriLighting(Operator): def execute(self, context): try: + collection = context.collection scene = context.scene view = context.space_data if view.type == 'VIEW_3D' and not view.lock_camera_and_layers: @@ -123,7 +124,7 @@ class TriLighting(Operator): if (camera is None): cam_data = bpy.data.cameras.new(name='Camera') cam_obj = bpy.data.objects.new(name='Camera', object_data=cam_data) - scene.objects.link(cam_obj) + collection.objects.link(cam_obj) scene.camera = cam_obj bpy.ops.view3d.camera_to_view() camera = cam_obj @@ -177,7 +178,7 @@ class TriLighting(Operator): backData.energy = backEnergy backLamp = bpy.data.objects.new(name="TriLamp-Back", object_data=backData) - scene.objects.link(backLamp) + collection.objects.link(backLamp) backLamp.location = (backx, backy, self.height) trackToBack = backLamp.constraints.new(type="TRACK_TO") @@ -199,7 +200,7 @@ class TriLighting(Operator): rightData = bpy.data.lights.new(name="TriLamp-Fill", type=self.secondarytype) rightData.energy = fillEnergy rightLamp = bpy.data.objects.new(name="TriLamp-Fill", object_data=rightData) - scene.objects.link(rightLamp) + collection.objects.link(rightLamp) rightLamp.location = (rightx, righty, self.height) trackToRight = rightLamp.constraints.new(type="TRACK_TO") trackToRight.target = obj @@ -219,7 +220,7 @@ class TriLighting(Operator): leftData.energy = keyEnergy leftLamp = bpy.data.objects.new(name="TriLamp-Key", object_data=leftData) - scene.objects.link(leftLamp) + collection.objects.link(leftLamp) leftLamp.location = (leftx, lefty, self.height) trackToLeft = leftLamp.constraints.new(type="TRACK_TO") trackToLeft.target = obj |