0
$\begingroup$

I create Python script for automatic create particle system use any two selected objects. Object 1 is emitter object and object 2 is particle object.

objectSelectList = bpy.context.selected_objects
print(objectSelectList)

This command give list of objects a user selected but sometime list order is reverse order (user select object A first then object B but list is: object B, object A).

How get correct select order?

$\endgroup$
1
  • $\begingroup$ I am not a Python expert, but it appears that you would first need a Python function to actively listen for selection events and to build a list based on that. Every time you select an object, it will be added to the list of selected objects in the order that you selected them. You would also probably need a "stop" listening function so the list stays clean. $\endgroup$ Jul 15 '20 at 15:24
3
$\begingroup$

Blender doesn't really have a "select order"

The standard method used by blender operators is to use the context object (context.object, context.active_object) and selected object(s) (context.selected_objects in which if there is a context object, it will occupy position 0).

For example Ctrl+P the parent operator makes the context object the parent of all selected objects, except itself. One parent many children. Similarly for join all like typed selected objects are joined to the context object.

Henceforth for making an operator to select emitter and particle you need to decide which is the many, ie make the context object a particle and then make all other selected objects an emitter of that particle, or vice versa.

$\endgroup$
1
  • $\begingroup$ context.selected_objects won't automatically shift the active_object to position 0, does it? Example in case that logic isn't automatically applied.active_obj = bpy.context.active_object selected_objs = [obj for obj in bpy.context.selected_objects if obj != bpy.context.active_object] $\endgroup$ Feb 24 at 17:41
0
$\begingroup$

You can use bpy.context.scene.objects.active to get the active object (the last selected object)

$\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.