0
$\begingroup$

I have two objects in the same collection. How can I edit(like transform) the second object only? I can only edit both objects in the same time.

(for example, I have object1 from mesh1, and object 2 from mesh2, and I use codes below)

ob = bpy.context.edit_object

me = ob.data

bm = bmesh.from_edit_mesh(me)

for v in bm.verts:

    v.co.z *= -1

bmesh.update_edit_mesh(me)

The codes seem only edit the whole meshes and objects.

I only want object2 to be done like this, and leave object1 the same as before.

Thank you enter image description here

Thank you for your answer! However can you show me the resolution using my style of codes below? I only want to change obj2 but the codes changes obj1 and obj2 at the same time.

mesh1 = bpy.data.meshes.new('mesh1')    
obj1 = bpy.data.objects.new('obj1', mesh1)    
bpy.context.scene.collection.objects.link(obj1)    
mesh2 = bpy.data.meshes.new('mesh2')
obj2 = bpy.data.objects.new('obj2', mesh2) ;  
bpy.context.scene.collection.objects.link(obj2)
bpy.context.view_layer.objects.active = obj2
bpy.ops.object.mode_set(mode='EDIT')
ob = bpy.context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)
for v in bm.verts:
    v.co.z *= -1
bmesh.update_edit_mesh(me)

And the two meshes( or two objects ) change at the same time, how to correct my codes to make changes to obj2 only? (this code is only an example, what I want to see is the way to edit the obj2 instead of both obj1 and obj2, so can you please just write some codes in general, thats enough for me, not for specific codes to create real obj1 and obj2)

$\endgroup$
7
  • $\begingroup$ This code should not affect them both except if they are duplicate linked (mesh1 is mesh2) $\endgroup$
    – lemon
    Commented Nov 29, 2020 at 9:21
  • $\begingroup$ how can I know which object is being edited in the code 'ob = bpy.context.edit_object' ? Or how should I write if I only want object2 to be edited( or mesh2 I dont know, IM newbee) $\endgroup$
    – dkpapa
    Commented Nov 29, 2020 at 9:36
  • $\begingroup$ bpy.context.edit_object is the active object when in edit mode. So the object the user (or your code) has made as active. I'm not figuring what you ask or want to do exactly? $\endgroup$
    – lemon
    Commented Nov 29, 2020 at 9:48
  • $\begingroup$ thankyou. what I want to do is like: create object1 from mesh1, create object2 from mesh2, (mesh2 is same as mesh1), then make object2 as the mirror of object1 on co.z.And last step is to combine the two objects. $\endgroup$
    – dkpapa
    Commented Nov 29, 2020 at 9:56
  • $\begingroup$ Where the objects supposed to be located one relatively to the other? $\endgroup$
    – lemon
    Commented Nov 29, 2020 at 10:23

1 Answer 1

0
$\begingroup$

A way to do its is to use bmesh.ops with mirror.

import bpy
import bmesh

# Get the object and its mesh
obj = bpy.context.object
mesh = obj.data

# Give the mesh to a bmesh
bm = bmesh.new()
bm.from_mesh(mesh)

# Call the mirror operation with Z axis
bmesh.ops.mirror(bm, geom = bm.faces[:], axis='Z')

# Back to mesh
bm.to_mesh(mesh)

# Force update (if not the screen won't refresh immediatly)
mesh.update()
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .