0
$\begingroup$

I am trying to add an object using from_pydata but am unable to deselect the added item - which is currently outlined in red and then select it so it is outlined in orange - and enter Edit mode.

`mycode

    import bpy, bmesh
    
    me = bpy.data.meshes.new("Vert" + "Mesh")
    ob = bpy.data.objects.new("Vert", me) 

    me.from_pydata([(1, 2, 5),(0,-1,0),(2,-2,0)],[],[[0,1,2]])
    
    bpy.data.collections['Collection'].objects.link(ob)

    bpy.data.objects["Vert"].select_set(True)
    bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')

    bpy.context.active_object.select_set(False) # attempt 1

    bpy.data.objects["Vert"].select_set(False) # attempt 2

    bpy.ops.object.select_all(action='DESELECT') # attempt 3

    bpy.data.objects["Vert"].select_set(True)

    bpy.ops.object.mode_set( mode = 'EDIT' )     # Toggle edit mode
    bpy.ops.mesh.select_mode( type = 'FACE' )    # Change to face selection
    bpy.ops.mesh.select_all( action = 'SELECT' )` 

The newly added object is circled in red as opposed to the usual orange. A simple click on anything other than the object "Vert" and select again will make the object orange, as required, but I seem unable to do this via code. I have tried adding other objects, or selecting other objects in the scene but with no luck.

$\endgroup$

1 Answer 1

0
$\begingroup$

The Orange you mention is Active state of object, as other posts described, it is separated from selected object.

The Red ones is selected object. Newly created object in script will be "selected" but not active by default.

enter image description here

If you want to set it as active object:

bpy.context.view_layer.objects.active = some_obj - 2.80 API

For further information: Set active object with python - Blender Stack Exchange

$\endgroup$
1
  • $\begingroup$ Amazing. Thank you. $\endgroup$
    – KK_
    Sep 30, 2020 at 2:41

You must log in to answer this question.

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