diff --git a/add_advanced_objects_menu/add_light_template.py b/add_advanced_objects_menu/add_light_template.py index 2ca87c3bc7377f41b76ccfd9abe2df60b3b1cfd8..3d6d880e8c66325b12602506a9e045454e82e31a 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 2e1ff4bdf8e5e84285f2369057d4c9330221f233..38fbb92af4901c67ee2adbd0303ecb254c4837cc 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 0492a0891204427cbfe6d629e0b6373f64a9020c..5b1bceb1453f42887271f084e1b7ad9768ed2fa1 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 20ebb2aaec20f381b5a60ebe2bf71af862ef048c..8925171aa071c49a411b7cab34ca78f68a3c722b 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 57cede0a6726167c8a65e1cd2fdf293613b15f3a..547fb2f558cbd5d38359e3c913b893df43f49e81 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 b6fca0059f7e91347a6bc2824a04cc2e0a422cda..a553ae48b61eed325ae174de53834519ee3d326e 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 dfa151cfe2ff53927383bff124db199995485aba..9de32146c1efbd1053c1c91136856774f059a20e 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 0a6c0ce426ce36d0cdf0a12e2333d37ddc8e86d9..8fee580be5e9932c94a7d6f04c1dabf7d038cb7c 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 diff --git a/add_advanced_objects_panels/delaunay_voronoi.py b/add_advanced_objects_panels/delaunay_voronoi.py index ccbcac0ffaf9a542651bd6f666eb695a307f87fb..fdb54a1729dc157cd2d4ce0e81dc4b12af1e7883 100644 --- a/add_advanced_objects_panels/delaunay_voronoi.py +++ b/add_advanced_objects_panels/delaunay_voronoi.py @@ -148,7 +148,7 @@ class OBJECT_OT_TriangulateButton(Operator): mesh.from_pydata(points_3D, [], faces) mesh.update(calc_edges=True) my = bpy.data.objects.new("TIN", mesh) - context.scene.objects.link(my) + context.collection.objects.link(my) my.matrix_world = obj.matrix_world.copy() obj.select_set(False) my.select_set(True) @@ -210,7 +210,7 @@ class OBJECT_OT_TriangulateButton(Operator): tinObj.scale = s # Update scene - bpy.context.scene.objects.link(tinObj) # Link object to scene + bpy.context.collection.objects.link(tinObj) # Link object to collection bpy.context.view_layer.objects.active = tinObj tinObj.select_set(True) obj.select_set(False) @@ -313,7 +313,7 @@ class OBJECT_OT_VoronoiButton(Operator): voronoiObj.scale = s # update scene - bpy.context.scene.objects.link(voronoiObj) # Link object to scene + bpy.context.collection.objects.link(voronoiObj) # Link object to collection bpy.context.view_layer.objects.active = voronoiObj voronoiObj.select_set(True) obj.select_set(False) diff --git a/add_advanced_objects_panels/object_laplace_lightning.py b/add_advanced_objects_panels/object_laplace_lightning.py index 0670666497da85ebefda1d651a6a8f64daf0d4ba..ece0640dd44445d2d0247883bd11df3b33ebf9ce 100644 --- a/add_advanced_objects_panels/object_laplace_lightning.py +++ b/add_advanced_objects_panels/object_laplace_lightning.py @@ -335,7 +335,7 @@ def writeArrayToCubes(arr, gridBU, orig, cBOOL=False, jBOOL=True): if a[3] > 0: col = (0.0, 0.0, a[3], 1.0) ob.color = col - bpy.context.scene.objects.link(ob) + bpy.context.collection.objects.link(ob) bpy.context.scene.update() if jBOOL: @@ -371,7 +371,7 @@ def addEdge(ob, va, vb): def newMesh(mname): mmesh = bpy.data.meshes.new(mname) omesh = bpy.data.objects.new(mname, mmesh) - bpy.context.scene.objects.link(omesh) + bpy.context.collection.objects.link(omesh) return omesh @@ -399,7 +399,7 @@ def writeArrayToCurves(cname, arr, gridBU, bd=.05, rpt=None): if rpt: addReportProp(cob, rpt) - bpy.context.scene.objects.link(cob) + bpy.context.collection.objects.link(cob) cur.splines.new('BEZIER') cspline = cur.splines[0] div = 1 # spacing for handles (2 - 1/2 way, 1 - next bezier) @@ -1084,17 +1084,17 @@ def setupObjects(): winmgr = bpy.context.scene.advanced_objects1 oOB = bpy.data.objects.new('ELorigin', None) oOB.location = ((0, 0, 10)) - bpy.context.scene.objects.link(oOB) + bpy.context.collection.objects.link(oOB) gOB = bpy.data.objects.new('ELground', None) gOB.empty_display_type = 'ARROWS' - bpy.context.scene.objects.link(gOB) + bpy.context.collection.objects.link(gOB) cME = makeMeshCube(1) cOB = bpy.data.objects.new('ELcloud', cME) cOB.location = ((-2, 8, 12)) cOB.hide_render = True - bpy.context.scene.objects.link(cOB) + bpy.context.collection.objects.link(cOB) iME = makeMeshCube(1) for v in iME.vertices: @@ -1106,7 +1106,7 @@ def setupObjects(): iOB = bpy.data.objects.new('ELinsulator', iME) iOB.location = ((0, 0, 5)) iOB.hide_render = True - bpy.context.scene.objects.link(iOB) + bpy.context.collection.objects.link(iOB) try: winmgr.OOB = 'ELorigin' diff --git a/add_advanced_objects_panels/oscurart_constellation.py b/add_advanced_objects_panels/oscurart_constellation.py index 796c38fe5be08facff5728ac616319049d9d62f7..a07f78f2e0886d31c52db795ee3419211c239165 100644 --- a/add_advanced_objects_panels/oscurart_constellation.py +++ b/add_advanced_objects_panels/oscurart_constellation.py @@ -61,7 +61,7 @@ def OscConstellation(limit): mesh = bpy.data.meshes.new("rsdata") obj = bpy.data.objects.new("rsObject", mesh) - bpy.context.scene.objects.link(obj) + bpy.context.collection.objects.link(obj) mesh.from_pydata(vertlist, edgelist, []) diff --git a/add_mesh_extra_objects/Wallfactory.py b/add_mesh_extra_objects/Wallfactory.py index 1f36d884841872f438b87b008653aa244e957ffe..fa006774fb06b9333d7e4805f589cee2bd5495b2 100644 --- a/add_mesh_extra_objects/Wallfactory.py +++ b/add_mesh_extra_objects/Wallfactory.py @@ -871,7 +871,7 @@ class add_mesh_wallb(Operator): mesh.update() ob_new = bpy.data.objects.new("Wall", mesh) - scene.objects.link(ob_new) + context.collection.objects.link(ob_new) # leave this out to prevent 'Tab key" going into edit mode :) # Use rmb click to select and still modify. context.view_layer.objects.active = ob_new diff --git a/add_mesh_extra_objects/add_mesh_beam_builder.py b/add_mesh_extra_objects/add_mesh_beam_builder.py index b4865c6d48435a87b04f50bba233b2cb52bc6ddc..0489050772f7e65b774c55ad049e4f3f107e3a83 100644 --- a/add_mesh_extra_objects/add_mesh_beam_builder.py +++ b/add_mesh_extra_objects/add_mesh_beam_builder.py @@ -663,7 +663,7 @@ def addBeamObj(sRef, context): beamMesh = bpy.data.meshes.new("Beam") beamObj = bpy.data.objects.new("Beam", beamMesh) - context.scene.objects.link(beamObj) + context.collection.objects.link(beamObj) context.view_layer.objects.active = beamObj beamObj.select_set(True) diff --git a/add_mesh_extra_objects/add_mesh_triangles.py b/add_mesh_extra_objects/add_mesh_triangles.py index bdede2c54ff4d1ab086dcacd01f5ee03c58cccac..64a56ef2cc0a7376726694c71e5edf9f367cda34 100644 --- a/add_mesh_extra_objects/add_mesh_triangles.py +++ b/add_mesh_extra_objects/add_mesh_triangles.py @@ -277,7 +277,7 @@ class MakeTriangle(Operator): NewMesh.update() NewObj = bpy.data.objects.new("Triangle", NewMesh) - context.scene.objects.link(NewObj) + context.collection.objects.link(NewObj) # before doing the deselect make sure edit mode isn't active exitEditMode() diff --git a/add_mesh_extra_objects/mesh_discombobulator.py b/add_mesh_extra_objects/mesh_discombobulator.py index f19f19276ddb7dbf4f596c9e3d577526f2a6fb5e..f31c3e628bdad00f06c01a81730c36484dc8860e 100644 --- a/add_mesh_extra_objects/mesh_discombobulator.py +++ b/add_mesh_extra_objects/mesh_discombobulator.py @@ -444,7 +444,7 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4, # Create the discombobulated mesh mesh = bpy.data.meshes.new("tmp") object = bpy.data.objects.new("tmp", mesh) - bpy.context.scene.objects.link(object) + bpy.context.collection.objects.link(object) # init final verts and polygons tuple nPolygons = [] @@ -486,7 +486,7 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4, # Fill in the discombobulated mesh with the new polygons mesh1 = bpy.data.meshes.new("discombobulated_object") object1 = bpy.data.objects.new("discombobulated_mesh", mesh1) - bpy.context.scene.objects.link(object1) + bpy.context.collection.objects.link(object1) mesh1.from_pydata(Verts, [], Polygons) mesh1.update(calc_edges=True) @@ -507,7 +507,7 @@ def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4, doodads(object1, mesh1, dmin, dmax) mesh2 = bpy.data.meshes.new("dood_mesh") object2 = bpy.data.objects.new("dood_obj", mesh2) - bpy.context.scene.objects.link(object2) + bpy.context.collection.objects.link(object2) mesh2.from_pydata(dVerts, [], dPolygons) mesh2.update(calc_edges=True) setMatDood(object2) diff --git a/animation_add_corrective_shape_key.py b/animation_add_corrective_shape_key.py index 8a9bdb28bc1b18e740751d7dd4d1569c65a8f6b7..c18d3b891fdd91d6bea463e73ebbbc38197fb54a 100644 --- a/animation_add_corrective_shape_key.py +++ b/animation_add_corrective_shape_key.py @@ -200,12 +200,12 @@ class add_corrective_pose_shape(bpy.types.Operator): return {'FINISHED'} -def func_object_duplicate_flatten_modifiers(scene, obj): - mesh = obj.to_mesh(scene, True, 'PREVIEW') +def func_object_duplicate_flatten_modifiers(context, obj): + mesh = obj.to_mesh(context.scene, True, 'PREVIEW') name = obj.name + "_clean" new_object = bpy.data.objects.new(name, mesh) new_object.data = mesh - scene.objects.link(new_object) + context.collection.objects.link(new_object) return new_object @@ -220,10 +220,9 @@ class object_duplicate_flatten_modifiers(bpy.types.Operator): return context.active_object is not None def execute(self, context): - scene = context.scene obj_act = context.active_object - new_object = func_object_duplicate_flatten_modifiers(scene, obj_act) + new_object = func_object_duplicate_flatten_modifiers(context, obj_act) # setup the context bpy.ops.object.select_all(action='DESELECT') diff --git a/btrace/bTrace.py b/btrace/bTrace.py index 2fdb1b940cd61353d49bda2370858831991b820b..9897afcc1884f6fe14392baa65b35670b0f06fba 100644 --- a/btrace/bTrace.py +++ b/btrace/bTrace.py @@ -140,7 +140,7 @@ class OBJECT_OT_objectconnect(Operator): spline = tracer.splines.new('BEZIER') spline.bezier_points.add(len(lists) - 1) curve = bpy.data.objects.new('curve', tracer) - bpy.context.scene.objects.link(curve) + bpy.context.collection.objects.link(curve) # render ready curve tracer.resolution_u = Btrace.curve_u @@ -205,7 +205,7 @@ def curvetracer(curvename, splinename): tracer = bpy.data.curves.new(splinename, 'CURVE') tracer.dimensions = '3D' curve = bpy.data.objects.new(curvename, tracer) - bpy.context.scene.objects.link(curve) + bpy.context.collection.objects.link(curve) try: tracer.fill_mode = 'FULL' except: @@ -336,7 +336,7 @@ class OBJECT_OT_traceallparticles(Operator): # Create new object with settings listed above curve = bpy.data.objects.new('Tracer', tracer) # Link newly created object to the scene - bpy.context.scene.objects.link(curve) + bpy.context.collection.objects.link(curve) # add a new Bezier point in the new curve spline = tracer.splines.new('BEZIER') spline.bezier_points.add(setting.count - 1) diff --git a/io_export_unreal_psk_psa.py b/io_export_unreal_psk_psa.py index 8695ee5ea73e6427ec2cd945c915217d209d7917..c4fb410e561f0c4ae296496a99769992ad8c0dff 100644 --- a/io_export_unreal_psk_psa.py +++ b/io_export_unreal_psk_psa.py @@ -982,7 +982,7 @@ def triangulate_mesh(object): me_ob = object.copy() me_ob.data = object.to_mesh(bpy.context.scene, True, 'PREVIEW') # write data object - bpy.context.scene.objects.link(me_ob) + bpy.context.collection.objects.link(me_ob) bpy.context.scene.update() bpy.ops.object.mode_set(mode='OBJECT') @@ -1027,7 +1027,7 @@ def meshmerge(selectedobjects): me_ob = selectedobjects[count].copy() # copy object # note two copy two types else it will use the current data or mesh me_ob.data = me_da # assign the data - bpy.context.scene.objects.link(me_ob) # link the object to the scene #current object location + bpy.context.collection.objects.link(me_ob) # link the object to the collection (current obj location) print("Index:", count, "clone object", me_ob.name) # print clone object cloneobjects.append(me_ob) # add object to the array @@ -1094,7 +1094,7 @@ def parse_mesh(mesh, psk): mesh = triangulate_mesh(mesh) if bpy.types.Scene.udk_copy_merge is True: - bpy.context.scene.objects.unlink(setmesh) + bpy.context.collection.objects.unlink(setmesh) # print("FACES----:",len(mesh.data.tessfaces)) verbose("Working mesh object: {}".format(mesh.name)) @@ -1399,7 +1399,7 @@ def parse_mesh(mesh, psk): verbose("Removing temporary triangle mesh: {}".format(mesh.name)) bpy.ops.object.mode_set(mode='OBJECT') # OBJECT mode mesh.parent = None # unparent to avoid phantom links - bpy.context.scene.objects.unlink(mesh) # unlink + bpy.context.collection.objects.unlink(mesh) # unlink # =========================================================================== @@ -1930,9 +1930,9 @@ def export(filepath): if bpy.context.scene.udk_option_rebuildobjects: print("Unlinking Objects") print("Armature Object Name:", udk_armature.name) # display object name - bpy.context.scene.objects.unlink(udk_armature) # remove armature from the scene + bpy.context.collection.objects.unlink(udk_armature) # remove armature from the collection print("Mesh Object Name:", udk_mesh.name) # display object name - bpy.context.scene.objects.unlink(udk_mesh) # remove mesh from the scene + bpy.context.collection.objects.unlink(udk_mesh) # remove mesh from the collection print("Export completed in {:.2f} seconds".format((time.clock() - t))) @@ -2175,7 +2175,7 @@ def rebuildmesh(obj): group = obmesh.vertex_groups.new(name=vgroup) for v in vertGroups[vgroup]: group.add([v[0]], v[1], 'ADD') # group.add(array[vertex id],weight,add) - bpy.context.scene.objects.link(obmesh) + bpy.context.collection.objects.link(obmesh) # print("Mesh Material Count:",len(me_ob.materials)) matcount = 0 # print("MATERIAL ID OREDER:") @@ -2218,7 +2218,7 @@ def rebuildarmature(obj): meshname = "ArmatureObjectPSK" armdata = bpy.data.armatures.new(objectname) ob_new = bpy.data.objects.new(meshname, armdata) - bpy.context.scene.objects.link(ob_new) + bpy.context.collection.objects.link(ob_new) # bpy.ops.object.mode_set(mode='OBJECT') for i in bpy.context.scene.objects: diff --git a/io_import_scene_lwo.py b/io_import_scene_lwo.py index 141093665ddc732702ae40b2aa22306d99a9d217..ffe18c9f1449280baa4551354d0855a1e670b36e 100644 --- a/io_import_scene_lwo.py +++ b/io_import_scene_lwo.py @@ -1047,7 +1047,7 @@ def build_objects(object_layers, object_surfs, object_tags, object_name, add_sub ngons[fi]= fpol # Deal with them later ob= bpy.data.objects.new(layer_data.name, me) - bpy.context.scene.objects.link(ob) + bpy.context.collection.objects.link(ob) ob_dict[layer_data.index]= [ob, layer_data.parent_index] # Move the object so the pivot is in the right place. diff --git a/io_import_scene_unreal_psa_psk.py b/io_import_scene_unreal_psa_psk.py index 81af56f27d7e849a8e3a0e11df103f6891dc8662..bed4c66fa2dd3f1b106041ef25e055c675d193fb 100644 --- a/io_import_scene_unreal_psa_psk.py +++ b/io_import_scene_unreal_psa_psk.py @@ -422,7 +422,7 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures): ob_new = bpy.data.objects.new(meshname, armdata) #ob_new = bpy.data.objects.new(meshname, 'ARMATURE') #ob_new.data = armdata - bpy.context.scene.objects.link(ob_new) + bpy.context.collection.objects.link(ob_new) #bpy.ops.object.mode_set(mode='OBJECT') for i in bpy.context.scene.objects: i.select_set(False) #deselect all objects @@ -697,7 +697,7 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures): #bpy.ops.object.select_name(name=str(ob_new.name)) #bpy.context.scene.objects.active = ob_new me_ob.update() - bpy.context.scene.objects.link(obmesh) + bpy.context.collection.objects.link(obmesh) bpy.context.scene.update() obmesh.select_set(False) ob_new.select_set(False) diff --git a/io_mesh_pdb/import_pdb.py b/io_mesh_pdb/import_pdb.py index 72aa8d36970a3e07a126fee1ebb3ea60199ca901..51d3e814e17d5c269c1d7a0f17a314cc1798f03e 100644 --- a/io_mesh_pdb/import_pdb.py +++ b/io_mesh_pdb/import_pdb.py @@ -522,14 +522,14 @@ def build_stick(radius, length, sectors): cylinder.from_pydata(vertices, [], faces1) cylinder.update() new_cylinder = bpy.data.objects.new("Sticks_Cylinder", cylinder) - bpy.context.scene.objects.link(new_cylinder) + bpy.context.collection.objects.link(new_cylinder) # Build the mesh, Cups cups = bpy.data.meshes.new("Sticks_Cups") cups.from_pydata(vertices, [], faces2) cups.update() new_cups = bpy.data.objects.new("Sticks_Cups", cups) - bpy.context.scene.objects.link(new_cups) + bpy.context.collection.objects.link(new_cups) return (new_cylinder, new_cups) @@ -563,7 +563,7 @@ def camera_light_source(use_camera, camera = bpy.data.objects.new("A_camera", camera_data) camera.location = camera_xyz_vec camera.layers = current_layers - bpy.context.scene.objects.link(camera) + bpy.context.collection.objects.link(camera) # Here the camera is rotated such it looks towards the center of # the object. The [0.0, 0.0, 1.0] vector along the z axis @@ -614,7 +614,7 @@ def camera_light_source(use_camera, lamp = bpy.data.objects.new("A_light", light_data) lamp.location = light_xyz_vec lamp.layers = current_layers - bpy.context.scene.objects.link(lamp) + bpy.context.collection.objects.link(lamp) # Some settings for the World: a bit ambient occlusion bpy.context.scene.world.light_settings.use_ambient_occlusion = True @@ -645,7 +645,7 @@ def draw_atoms_one_type(draw_all_atoms_type, atom_mesh.from_pydata(atom_vertices, [], []) atom_mesh.update() new_atom_mesh = bpy.data.objects.new(atom[0], atom_mesh) - bpy.context.scene.objects.link(new_atom_mesh) + bpy.context.collection.objects.link(new_atom_mesh) # Now, build a representative sphere (atom). current_layers = bpy.context.scene.layers @@ -838,7 +838,7 @@ def draw_sticks_dupliverts(all_atoms, mesh.from_pydata(vertices, [], faces) mesh.update() new_mesh = bpy.data.objects.new("Sticks"+stick[0], mesh) - bpy.context.scene.objects.link(new_mesh) + bpy.context.collection.objects.link(new_mesh) # Build the object. # Get the cylinder from the 'build_stick' function. @@ -958,7 +958,7 @@ def draw_sticks_skin(all_atoms, stick_mesh.from_pydata(stick_vertices, stick_edges, []) stick_mesh.update() new_stick_mesh = bpy.data.objects.new("Sticks", stick_mesh) - bpy.context.scene.objects.link(new_stick_mesh) + bpy.context.collection.objects.link(new_stick_mesh) # Apply the skin modifier. new_stick_mesh.modifiers.new(name="Sticks_skin", type='SKIN') diff --git a/io_scene_ms3d/ms3d_export.py b/io_scene_ms3d/ms3d_export.py index aed7f400d27ca9c8ea8458a5ca644214dee6687e..004a0e4eeafb80485a3f72f0ac1e4b9dc9a4d284 100644 --- a/io_scene_ms3d/ms3d_export.py +++ b/io_scene_ms3d/ms3d_export.py @@ -221,6 +221,7 @@ class Ms3dExporter(): def create_geometry(self, blender_context, ms3d_model, blender_mesh_objects, blender_to_ms3d_bones): blender_view_layer = blender_context.view_layer blender_scene = blender_context.scene + blender_collection = blender_context.collection blender_to_ms3d_vertices = {} blender_to_ms3d_triangles = {} @@ -271,7 +272,7 @@ class Ms3dExporter(): blender_mesh_temp = blender_mesh_object.data.copy() blender_mesh_object_temp = blender_mesh_object.copy() blender_mesh_object_temp.data = blender_mesh_temp - blender_scene.objects.link(blender_mesh_object_temp) + blender_collection.objects.link(blender_mesh_object_temp) blender_view_layer.objects.active = blender_mesh_object_temp # apply transform @@ -532,7 +533,7 @@ class Ms3dExporter(): ########################## # remove the temporary data - blender_scene.objects.unlink(blender_mesh_object_temp) + blender_collection.objects.unlink(blender_mesh_object_temp) if blender_mesh_temp is not None: blender_mesh_temp.user_clear() blender_context.blend_data.meshes.remove(blender_mesh_temp) diff --git a/io_scene_ms3d/ms3d_import.py b/io_scene_ms3d/ms3d_import.py index d4fd6f2cfe6daf2a135162106eb34450306a0673..01019a1284379b4d6d7901ee3ff9a9804b2fbe69 100644 --- a/io_scene_ms3d/ms3d_import.py +++ b/io_scene_ms3d/ms3d_import.py @@ -233,13 +233,14 @@ class Ms3dImporter(): ###blender_mesh_object.parent = blender_armature_object blender_scene = blender_context.scene + blender_collection = blender_context.collection blender_group = blender_context.blend_data.collections.new( FORMAT_GROUP.format(ms3d_model.name)) blender_empty_object = blender_context.blend_data.objects.new( FORMAT_EMPTY_OBJECT.format(ms3d_model.name), None) blender_empty_object.location = blender_scene.cursor_location - blender_scene.objects.link(blender_empty_object) + blender_collection.objects.link(blender_empty_object) blender_group.objects.link(blender_empty_object) for blender_object in blender_objects: @@ -284,9 +285,9 @@ class Ms3dImporter(): ########################## # blender stuff: # link to blender scene - blender_scene = blender_context.scene + blender_collection = blender_context.collection blender_view_layer = blender_context.view_layer - blender_scene.objects.link(blender_mesh_object) + blender_collection.objects.link(blender_mesh_object) #blender_mesh_object.location = blender_scene.cursor_location enable_edit_mode(False, blender_context) select_all(False) @@ -665,6 +666,7 @@ class Ms3dImporter(): def create_animation(self, blender_context, ms3d_model, blender_mesh_object): ########################## # setup scene + blender_collection = blender_context.collection blender_scene = blender_context.scene blender_scene.render.fps = ms3d_model.animation_fps if ms3d_model.animation_fps: @@ -696,7 +698,7 @@ class Ms3dImporter(): blender_armature.use_auto_ik = True blender_armature_object = blender_context.blend_data.objects.new( ms3d_armature_object_name, blender_armature) - blender_scene.objects.link(blender_armature_object) + blender_collection.objects.link(blender_armature_object) #blender_armature_object.location = blender_scene.cursor_location blender_armature_object.show_in_front = True diff --git a/io_scene_x3d/import_x3d.py b/io_scene_x3d/import_x3d.py index e6e29dbc526bf1002588de72940901b2c5b2c58a..903222cf6bce3b10264382573d998a16a83ce22a 100644 --- a/io_scene_x3d/import_x3d.py +++ b/io_scene_x3d/import_x3d.py @@ -2981,7 +2981,7 @@ def appearance_LoadPixelTexture(pixelTexture, ancestry): # Called from importShape to insert a data object (typically a mesh) # into the scene def importShape_ProcessObject( - bpyscene, vrmlname, bpydata, geom, geom_spec, node, + bpycollection, vrmlname, bpydata, geom, geom_spec, node, bpymat, has_alpha, texmtx, ancestry, global_matrix): @@ -3028,7 +3028,7 @@ def importShape_ProcessObject( # bpymesh.transform(getFinalMatrix(node)) bpyob = node.blendObject = bpy.data.objects.new(vrmlname, bpydata) bpyob.matrix_world = getFinalMatrix(node, None, ancestry, global_matrix) - bpyscene.objects.link(bpyob).select_set(True) + bpycollection.objects.link(bpyob).select_set(True) if DEBUG: bpyob["source_line_no"] = geom.lineno @@ -3071,7 +3071,7 @@ geometry_importers = { } -def importShape(bpyscene, node, ancestry, global_matrix): +def importShape(bpycollection, node, ancestry, global_matrix): # Under Shape, we can only have Appearance, MetadataXXX and a geometry node def isGeometry(spec): return spec != "Appearance" and not spec.startswith("Metadata") @@ -3082,7 +3082,7 @@ def importShape(bpyscene, node, ancestry, global_matrix): bpyob = node.blendData = node.blendObject = bpyob.copy() # Could transform data, but better the object so we can instance the data bpyob.matrix_world = getFinalMatrix(node, None, ancestry, global_matrix) - bpyscene.objects.link(bpyob).select_set(True) + bpycollection.objects.link(bpyob).select_set(True) return vrmlname = node.getDefName() @@ -3124,7 +3124,7 @@ def importShape(bpyscene, node, ancestry, global_matrix): # There are no geometry importers that can legally return # no object. It's either a bpy object, or an exception importShape_ProcessObject( - bpyscene, vrmlname, bpydata, geom, geom_spec, + bpycollection, vrmlname, bpydata, geom, geom_spec, node, bpymat, tex_has_alpha, texmtx, ancestry, global_matrix) else: @@ -3218,7 +3218,7 @@ def importLamp_SpotLight(node, ancestry): return bpylamp, mtx -def importLamp(bpyscene, node, spec, ancestry, global_matrix): +def importLamp(bpycollection, node, spec, ancestry, global_matrix): if spec == 'PointLight': bpylamp, mtx = importLamp_PointLight(node, ancestry) elif spec == 'DirectionalLight': @@ -3230,7 +3230,7 @@ def importLamp(bpyscene, node, spec, ancestry, global_matrix): raise ValueError bpyob = node.blendData = node.blendObject = bpy.data.objects.new(bpylamp.name, bpylamp) - bpyscene.objects.link(bpyob).select_set(True) + bpycollection.objects.link(bpyob).select_set(True) bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry, global_matrix) @@ -3238,7 +3238,7 @@ def importLamp(bpyscene, node, spec, ancestry, global_matrix): # ----------------------------------------------------------------------------------- -def importViewpoint(bpyscene, node, ancestry, global_matrix): +def importViewpoint(bpycollection, node, ancestry, global_matrix): name = node.getDefName() if not name: name = 'Viewpoint' @@ -3256,17 +3256,17 @@ def importViewpoint(bpyscene, node, ancestry, global_matrix): mtx = Matrix.Translation(Vector(position)) * translateRotation(orientation) bpyob = node.blendData = node.blendObject = bpy.data.objects.new(name, bpycam) - bpyscene.objects.link(bpyob).select_set(True) + bpycollection.objects.link(bpyob).select_set(True) bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry, global_matrix) -def importTransform(bpyscene, node, ancestry, global_matrix): +def importTransform(bpycollection, node, ancestry, global_matrix): name = node.getDefName() if not name: name = 'Transform' bpyob = node.blendData = node.blendObject = bpy.data.objects.new(name, None) - bpyscene.objects.link(bpyob).select_set(True) + bpycollection.objects.link(bpyob).select_set(True) bpyob.matrix_world = getFinalMatrix(node, None, ancestry, global_matrix) @@ -3451,7 +3451,7 @@ ROUTE champFly001.bindTime TO vpTs.set_startTime def load_web3d( - bpyscene, + bpycontext, filepath, *, PREF_FLAT=False, @@ -3463,6 +3463,8 @@ def load_web3d( # Used when adding blender primitives GLOBALS['CIRCLE_DETAIL'] = PREF_CIRCLE_DIV + bpyscene = bpycontext.scene + bpycollection = bpycontext.collection #root_node = vrml_parse('/_Cylinder.wrl') if filepath.lower().endswith('.x3d'): root_node, msg = x3d_parse(filepath) @@ -3495,15 +3497,15 @@ def load_web3d( # by an external script. - gets first pick pass if spec == 'Shape': - importShape(bpyscene, node, ancestry, global_matrix) + importShape(bpycollection, node, ancestry, global_matrix) elif spec in {'PointLight', 'DirectionalLight', 'SpotLight'}: - importLamp(bpyscene, node, spec, ancestry, global_matrix) + importLamp(bpycollection, node, spec, ancestry, global_matrix) elif spec == 'Viewpoint': - importViewpoint(bpyscene, node, ancestry, global_matrix) + importViewpoint(bpycollection, node, ancestry, global_matrix) elif spec == 'Transform': # Only use transform nodes when we are not importing a flat object hierarchy if PREF_FLAT == False: - importTransform(bpyscene, node, ancestry, global_matrix) + importTransform(bpycollection, node, ancestry, global_matrix) ''' # These are delt with later within importRoute elif spec=='PositionInterpolator': @@ -3528,7 +3530,7 @@ def load_web3d( node = defDict[key] if node.blendData is None: # Add an object if we need one for animation node.blendData = node.blendObject = bpy.data.objects.new('AnimOb', None) # , name) - bpyscene.objects.link(node.blendObject).select_set(True) + bpycollection.objects.link(node.blendObject).select_set(True) if node.blendData.animation_data is None: node.blendData.animation_data_create() @@ -3579,7 +3581,7 @@ def load_with_profiler( import cProfile import pstats pro = cProfile.Profile() - pro.runctx("load_web3d(context.scene, filepath, PREF_FLAT=True, " + pro.runctx("load_web3d(context, filepath, PREF_FLAT=True, " "PREF_CIRCLE_DIV=16, global_matrix=global_matrix)", globals(), locals()) st = pstats.Stats(pro) @@ -3595,7 +3597,7 @@ def load(context, ): # loadWithProfiler(operator, context, filepath, global_matrix) - load_web3d(context.scene, filepath, + load_web3d(context, filepath, PREF_FLAT=True, PREF_CIRCLE_DIV=16, global_matrix=global_matrix, diff --git a/light_field_tools/light_field_tools.py b/light_field_tools/light_field_tools.py index d46dec02d2c0a14c95f819edb9d867a0d494bfe5..585e3a9a25bb9fd8bddf4803b1dc0d6e5dc3403f 100644 --- a/light_field_tools/light_field_tools.py +++ b/light_field_tools/light_field_tools.py @@ -319,6 +319,7 @@ class OBJECT_OT_create_lightfield_basemesh(Operator): return normal * vl def addMeshObj(self, mesh): + collection = bpy.context.collection scene = bpy.context.scene view_layer = bpy.context.view_layer @@ -327,7 +328,7 @@ class OBJECT_OT_create_lightfield_basemesh(Operator): mesh.update() nobj = bpy.data.objects.new(self.objName, mesh) - scene.objects.link(nobj) + collection.objects.link(nobj) nobj.select_set(True) if view_layer.objects.active is None or view_layer.objects.active.mode == 'OBJECT': diff --git a/mesh_bsurfaces.py b/mesh_bsurfaces.py index fba912407ff7bae02bd2f8e5e309182939774bc6..9cbcd0e05eca96a1625bebe68097016e6a9a2b7b 100644 --- a/mesh_bsurfaces.py +++ b/mesh_bsurfaces.py @@ -1355,7 +1355,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator): ob = bpy.data.objects.new(me_name, me) ob.data = me - bpy.context.scene.objects.link(ob) + bpy.context.collection.objects.link(ob) bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT') ob.select_set(True) @@ -1533,7 +1533,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator): me_surf.update() ob_surface = bpy.data.objects.new(surf_me_name, me_surf) - bpy.context.scene.objects.link(ob_surface) + bpy.context.collection.objects.link(ob_surface) # Delete final points temporal object bpy.ops.object.select_all('INVOKE_REGION_WIN', action='DESELECT') @@ -2419,7 +2419,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator): # Create a curve object for the actual spline "cyclic extension" simplified_curve.append(bpy.data.curves.new('SURFSKIO_simpl_crv', 'CURVE')) ob_simplified_curve.append(bpy.data.objects.new('SURFSKIO_simpl_crv', simplified_curve[i])) - bpy.context.scene.objects.link(ob_simplified_curve[i]) + bpy.context.collection.objects.link(ob_simplified_curve[i]) simplified_curve[i].dimensions = "3D" @@ -2587,7 +2587,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator): me = bpy.data.meshes.new(mesh_ctrl_pts_name) ob_ctrl_pts = bpy.data.objects.new(mesh_ctrl_pts_name, me) ob_ctrl_pts.data = me - bpy.context.scene.objects.link(ob_ctrl_pts) + bpy.context.collection.objects.link(ob_ctrl_pts) cyclic_loops_U = [] first_verts = [] @@ -2741,7 +2741,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator): for i in range(len(ob_curves_surf.data.splines)): spline_U_curve = bpy.data.curves.new('SURFSKIO_spline_U_' + str(i), 'CURVE') ob_spline_U = bpy.data.objects.new('SURFSKIO_spline_U_' + str(i), spline_U_curve) - bpy.context.scene.objects.link(ob_spline_U) + bpy.context.collection.objects.link(ob_spline_U) spline_U_curve.dimensions = "3D" @@ -3013,7 +3013,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator): me_surf.update() ob_surface = bpy.data.objects.new(surf_me_name, me_surf) - bpy.context.scene.objects.link(ob_surface) + bpy.context.collection.objects.link(ob_surface) # Select all the "unselected but participating" verts, from closed selection # or double selections with middle-vertex, for later join with remove doubles @@ -3046,7 +3046,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator): # Build splines from the "last saved splines". last_saved_curve = bpy.data.curves.new('SURFSKIO_last_crv', 'CURVE') self.main_splines = bpy.data.objects.new('SURFSKIO_last_crv', last_saved_curve) - bpy.context.scene.objects.link(self.main_splines) + bpy.context.collection.objects.link(self.main_splines) last_saved_curve.dimensions = "3D" diff --git a/mesh_carver.py b/mesh_carver.py index 9b158f4730b8ce8f75fa88ec1cd27afb2ec21f08..b8c14d8c52e59c46cfbf2ba6a55ae47a954b8e20 100644 --- a/mesh_carver.py +++ b/mesh_carver.py @@ -1340,7 +1340,7 @@ def CreateCutSquare(self, context): PlaneNormalised = PlaneNormal.normalized() # Link object to scene - context.scene.objects.link(ob) + context.collection.objects.link(ob) # New bmesh t_bm = bmesh.new() @@ -1406,7 +1406,7 @@ def CreateCutLine(self, context): PlaneNormal = depthLocation PlaneNormalised = PlaneNormal.normalized() - context.scene.objects.link(ob) + context.collection.objects.link(ob) t_bm = bmesh.new() t_bm.from_mesh(me) @@ -1505,7 +1505,7 @@ def CreateCutCircle(self, context): PlaneNormal = depthLocation PlaneNormalised = PlaneNormal.normalized() - context.scene.objects.link(ob) + context.collection.objects.link(ob) t_bm = bmesh.new() t_bm.from_mesh(me) @@ -3080,9 +3080,8 @@ class Carver(bpy.types.Operator): # Copy the brush object ob = bpy.data.objects.new("CarverBrushCopy", context.object.data.copy()) ob.location = self.ObjectBrush.location - scene = context.scene - scene.objects.link(ob) - scene.update() + context.collection.objects.link(ob) + context.scene.update() # Get default variables self.InitBrushPosition = self.ObjectBrush.location.copy() diff --git a/mesh_tissue/tessellate_numpy.py b/mesh_tissue/tessellate_numpy.py index 5d8ed35ec96819c787e43710cf5f3c1332ebe159..8803966df66919ede3ccefcab52b60c8a142089b 100644 --- a/mesh_tissue/tessellate_numpy.py +++ b/mesh_tissue/tessellate_numpy.py @@ -886,8 +886,7 @@ class tessellate(Operator): new_ob.location = ob0.location new_ob.matrix_world = ob0.matrix_world - scene = bpy.context.scene - scene.objects.link(new_ob) + bpy.context.collection.objects.link(new_ob) new_ob.select_set(True) bpy.context.view_layer.objects.active = new_ob if self.merge: @@ -1429,8 +1428,7 @@ class settings_tessellate(Operator): self.ob.data = temp_ob.data # Create object in order to transfer vertex group - scene = bpy.context.scene - scene.objects.link(temp_ob) + bpy.context.collection.objects.link(temp_ob) temp_ob.select_set(True) bpy.context.view_layer.objects.active = temp_ob @@ -1439,7 +1437,7 @@ class settings_tessellate(Operator): except: pass - scene.objects.unlink(temp_ob) + bpy.context.scene.objects.unlink(temp_ob) bpy.data.objects.remove(temp_ob) bpy.context.view_layer.objects.active = self.ob diff --git a/mocap/retarget.py b/mocap/retarget.py index f46b371657587ddb38a1638f68ccf77cd85608e4..d5a17097d9f0297e92f85d46dbb15d7122dd9d08 100644 --- a/mocap/retarget.py +++ b/mocap/retarget.py @@ -120,7 +120,7 @@ def createIntermediate(performer_obj, enduser_obj, root, s_frame, e_frame, scene #creates the intermediate armature object inter_obj = enduser_obj.copy() inter_obj.data = inter_obj.data.copy() # duplicate data - bpy.context.scene.objects.link(inter_obj) + bpy.context.collection.objects.link(inter_obj) inter_obj.name = "intermediate" bpy.context.view_layer.objects.active = inter_obj bpy.ops.object.mode_set(mode='EDIT') diff --git a/object_cloud_gen.py b/object_cloud_gen.py index 199bc2c2bd49157cc734f72ac3e74f8c681f27a3..b06a1236c1198bad3c9ab0f216892c6aa552b850 100644 --- a/object_cloud_gen.py +++ b/object_cloud_gen.py @@ -313,7 +313,7 @@ def makeParent(parentobj, childobj, view_layer): childobj.parent = parentobj -def addNewObject(scene, name, copyobj): +def addNewObject(collection, name, copyobj): # avoid creating not needed meshes pro forme # Create a new object tempme = copyobj.data @@ -323,7 +323,7 @@ def addNewObject(scene, name, copyobj): ob_new.location = copyobj.location # Link new object to the given scene and select it - scene.objects.link(ob_new) + collection.objects.link(ob_new) ob_new.select_set(True) return ob_new @@ -508,6 +508,7 @@ class GenerateCloud(Operator): active_object = context.active_object # Make variable scene that is current scene + collection = context.collection scene = context.scene view_layer = context.view_layer @@ -575,7 +576,7 @@ class GenerateCloud(Operator): # Create CloudPnts for putting points in # # Create a new object cloudPnts - cloudPnts = addNewObject(scene, "CloudPoints", bounds) + cloudPnts = addNewObject(collection, "CloudPoints", bounds) cloudPnts["CloudMember"] = "CreatedObj" cloudPnts.display_type = 'WIRE' cloudPnts.hide_render = True @@ -603,7 +604,7 @@ class GenerateCloud(Operator): # Create a new object bounds bounds = addNewObject( - scene, "CloudBounds", + collection, "CloudBounds", selectedObjects[0] ) @@ -645,7 +646,7 @@ class GenerateCloud(Operator): # Create Cloud for putting Cloud Mesh # # Create a new object cloud. - cloud = addNewObject(scene, "CloudMesh", bounds) + cloud = addNewObject(collection, "CloudMesh", bounds) cloud["CloudMember"] = "CreatedObj" cloud.display_type = 'WIRE' cloud.hide_render = True @@ -835,7 +836,7 @@ class GenerateCloud(Operator): if not scene.cloudparticles: # Create CloudPnts for putting points in # # Create a new object cloudPnts - cloudPnts = addNewObject(scene, "CloudPoints", bounds) + cloudPnts = addNewObject(collection, "CloudPoints", bounds) cloudPnts["CloudMember"] = "CreatedObj" cloudPnts.display_type = 'WIRE' cloudPnts.hide_render = True diff --git a/object_fracture/fracture_ops.py b/object_fracture/fracture_ops.py index 7d24116a016810e1902b069e005548c0350e130b..30515f594e6c615b20af3b460cf2ded9f85530ec 100644 --- a/object_fracture/fracture_ops.py +++ b/object_fracture/fracture_ops.py @@ -169,7 +169,7 @@ def getIslands(shard): shards.append(a) - bpy.context.scene.objects.unlink(shard) + bpy.context.collection.objects.unlink(shard) return shards @@ -233,6 +233,7 @@ def boolop(ob, cutter, op): def splitobject(context, ob, crack_type, roughness): + collection = context.collection scene = context.scene view_layer = context.view_layer @@ -262,17 +263,17 @@ def splitobject(context, ob, crack_type, roughness): if fault > 0: # Delete all shards in case of fault from previous operation. for s in shards: - scene.objects.unlink(s) + collection.objects.unlink(s) - scene.objects.unlink(cutter) + collection.objects.unlink(cutter) #print('splitobject: fault') return [ob] if shards[0] != ob: - bpy.context.scene.objects.unlink(ob) + bpy.context.collection.objects.unlink(ob) - bpy.context.scene.objects.unlink(cutter) + bpy.context.collection.objects.unlink(cutter) return shards @@ -331,7 +332,7 @@ def fracture_group(context, group): if fault == 1: # Delete all shards in case of fault from previous operation. for s in shards: - bpy.context.scene.objects.unlink(s) + bpy.context.collection.objects.unlink(s) #print('fracture_group: fault') #print('fracture_group: ' + str(i)) diff --git a/object_fracture_cell/__init__.py b/object_fracture_cell/__init__.py index f4122d33e70539b8738d72af94e2388a05c13ac6..75da5e2822158392884f2b0e077951f8311c288f 100644 --- a/object_fracture_cell/__init__.py +++ b/object_fracture_cell/__init__.py @@ -45,7 +45,7 @@ from bpy.props import ( from bpy.types import Operator -def main_object(scene, obj, level, **kw): +def main_object(context, obj, level, **kw): import random # pull out some args @@ -66,6 +66,8 @@ def main_object(scene, obj, level, **kw): use_sharp_edges = kw_copy.pop("use_sharp_edges") use_sharp_edges_apply = kw_copy.pop("use_sharp_edges_apply") + collection = context.collection + if level != 0: kw_copy["source_limit"] = recursion_source_limit @@ -78,8 +80,8 @@ def main_object(scene, obj, level, **kw): obj_display_type_prev = obj.display_type obj.display_type = 'WIRE' - objects = fracture_cell_setup.cell_fracture_objects(scene, obj, **kw_copy) - objects = fracture_cell_setup.cell_fracture_boolean(scene, obj, objects, + objects = fracture_cell_setup.cell_fracture_objects(context, obj, **kw_copy) + objects = fracture_cell_setup.cell_fracture_boolean(context, obj, objects, use_island_split=use_island_split, use_interior_hide=(use_interior_vgroup or use_sharp_edges), use_debug_bool=use_debug_bool, @@ -123,9 +125,9 @@ def main_object(scene, obj, level, **kw): objects_recursive = [] for i, obj_cell in objects_recurse_input: assert(objects[i] is obj_cell) - objects_recursive += main_object(scene, obj_cell, level_sub, **kw) + objects_recursive += main_object(context, obj_cell, level_sub, **kw) if use_remove_original: - scene.objects.unlink(obj_cell) + collection.objects.unlink(obj_cell) del objects[i] if recursion_clamp and len(objects) + len(objects_recursive) >= recursion_clamp: break @@ -182,7 +184,6 @@ def main_object(scene, obj, level, **kw): def main(context, **kw): import time t = time.time() - scene = context.scene objects_context = context.selected_editable_objects kw_copy = kw.copy() @@ -194,7 +195,7 @@ def main(context, **kw): objects = [] for obj in objects_context: if obj.type == 'MESH': - objects += main_object(scene, obj, 0, **kw_copy) + objects += main_object(context, obj, 0, **kw_copy) bpy.ops.object.select_all(action='DESELECT') for obj_cell in objects: diff --git a/object_fracture_cell/fracture_cell_setup.py b/object_fracture_cell/fracture_cell_setup.py index 2b46715fa2d39feedbef41f333405b693a6a6c43..fcd6568115c202695f44860ab0659533090704dc 100644 --- a/object_fracture_cell/fracture_cell_setup.py +++ b/object_fracture_cell/fracture_cell_setup.py @@ -121,7 +121,7 @@ def _points_from_object(obj, source): return points -def cell_fracture_objects(scene, obj, +def cell_fracture_objects(context, obj, source={'PARTICLE_OWN'}, source_limit=0, source_noise=0.0, @@ -137,6 +137,8 @@ def cell_fracture_objects(scene, obj, ): from . import fracture_cell_calc + collection = context.collection + scene = context.scene # ------------------------------------------------------------------------- # GET POINTS @@ -187,7 +189,7 @@ def cell_fracture_objects(scene, obj, bm.to_mesh(mesh_tmp) bm.free() obj_tmp = bpy.data.objects.new(name=mesh_tmp.name, object_data=mesh_tmp) - scene.objects.link(obj_tmp) + collection.objects.link(obj_tmp) del obj_tmp, mesh_tmp mesh = obj.data @@ -278,7 +280,7 @@ def cell_fracture_objects(scene, obj, # OBJECT obj_cell = bpy.data.objects.new(name=cell_name, object_data=mesh_dst) - scene.objects.link(obj_cell) + collection.objects.link(obj_cell) # scene.objects.active = obj_cell obj_cell.location = center_point @@ -309,7 +311,7 @@ def cell_fracture_objects(scene, obj, return objects -def cell_fracture_boolean(scene, obj, objects, +def cell_fracture_boolean(context, obj, objects, use_debug_bool=False, clean=True, use_island_split=False, @@ -320,6 +322,8 @@ def cell_fracture_boolean(scene, obj, objects, ): objects_boolean = [] + collection = context.collection + scene = context.scene if use_interior_hide and level == 0: # only set for level 0 @@ -346,7 +350,7 @@ def cell_fracture_boolean(scene, obj, objects, if not mesh_old.users: bpy.data.meshes.remove(mesh_old) if not mesh_new.vertices: - scene.objects.unlink(obj_cell) + collection.objects.unlink(obj_cell) if not obj_cell.users: bpy.data.objects.remove(obj_cell) obj_cell = None diff --git a/object_print3d_utils/export.py b/object_print3d_utils/export.py index d563b5493479a1a32efe454b8730848bf05f207a..d980bcc493a908cd1ad951c253a11f4326239268 100644 --- a/object_print3d_utils/export.py +++ b/object_print3d_utils/export.py @@ -53,6 +53,7 @@ def image_copy_guess(filepath, objects): def write_mesh(context, info, report_cb): scene = context.scene + collection = context.collection layer = context.view_layer unit = scene.unit_settings print_3d = scene.print_3d @@ -184,7 +185,7 @@ def write_mesh(context, info, report_cb): if obj_base_tmp is not None: obj = obj_base_tmp.object mesh = obj.data - scene.objects.unlink(obj) + collection.objects.unlink(obj) bpy.data.objects.remove(obj) bpy.data.meshes.remove(mesh) del obj_base_tmp, obj, mesh diff --git a/render_povray/primitives.py b/render_povray/primitives.py index e5ea3a9626cf1a8f155439897d9753e3b6291de6..4e07dee4c1929bebc2c51ea27c35fd6482bed2b3 100644 --- a/render_povray/primitives.py +++ b/render_povray/primitives.py @@ -1826,7 +1826,7 @@ class ImportPOV(bpy.types.Operator, ImportHelper): me = bpy.data.meshes.new(name) ######## ob = bpy.data.objects.new(name, me) ########## - bpy.context.scene.objects.link(ob) ######### + bpy.context.collection.objects.link(ob) ######### me.from_pydata(verts, [], faces) ############ for mat in bpy.data.materials: ############## diff --git a/uv_texture_atlas.py b/uv_texture_atlas.py index f57f338976d5c3af5e46d0e5d8f3184b15868596..5e527874918e9f34ca27fac5804788781376c3f7 100644 --- a/uv_texture_atlas.py +++ b/uv_texture_atlas.py @@ -604,6 +604,7 @@ class TexAtl_MergeObjects(Operator): unwrap: BoolProperty(default=False) def execute(self, context): + collection = context.collection scene = context.scene view_layer = context.view_layer @@ -618,7 +619,7 @@ class TexAtl_MergeObjects(Operator): me = bpy.data.meshes.new(self.group_name + '_mergedObject') ob_merge = bpy.data.objects.new(self.group_name + '_mergedObject', me) ob_merge.location = scene.cursor_location # position object at 3d-cursor - scene.objects.link(ob_merge) # Link object to scene + collection.objects.link(ob_merge) # Link object to collection me.update() ob_merge.select_set(False)