0
$\begingroup$

I import and object C27389_Part into the scene. I search the part by using bpy.ops.object.select_pattern(pattern="*_Part"). That's all good, however it is selected (in red outline) and not active (orange), so I cannot do anything with it at this stage. Please help. I have searched and yet cannot solve this simple riddle. bpy.context.scene.objects.active will not do it.

$\endgroup$
3
  • $\begingroup$ Suggest try: bpy.context.selected_objects[:] after the import, and get rid of the operator. To make it active, read my answer to one of your previous questions: blender.stackexchange.com/questions/132825/… ... "# Make the cube the active object" $\endgroup$
    – brockmann
    Aug 23, 2020 at 8:36
  • $\begingroup$ The object is imported in OBJ format and is part of an assembly of objects and hence it is not selected at all at import. The pattern code detects the object, as it would do with others with a similar name. In this event however there is only one of these objects, so i need not worry about similar objects. Sorry, I can't figure it out. $\endgroup$ Aug 23, 2020 at 9:36
  • $\begingroup$ All objects are selected after the import, always. No need for that operator (pattern detection) as well as no need to say sorry... Since you're searching for one specific object, suggest iterate through all the imported objects and check for their name -> docs.python.org/3/library/stdtypes.html#str.endswith $\endgroup$
    – brockmann
    Aug 23, 2020 at 13:24

1 Answer 1

-1
$\begingroup$

This works after selecting the pattern.

OB = bpy.context.selected_objects[0]
OB.select_set(state=True)
bpy.context.view_layer.objects.active = OB
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.