question about blender object selection

(sanki) #1

Hi!
I am trying to write a script that creates armature chain based on selected objects.
this is my code so far:

import Blender
from Blender.Mathutils import *
from Blender import *
print '========================================'
sel = Blender.Object.GetSelected()
print sel
scn = Blender.Scene.GetCurrent()
arm = Armature.New()
obj = scn.objects.new(arm)
print sel

for i in range(len(sel)-1):    
    print i    
    print '
'    
    arm.makeEditable()
    eb = Armature.Editbone()
    eb.tail = Vector(sel[i].LocX,sel[i].LocY,sel[i].LocZ)
    eb.head = Vector(sel[i+1].LocX,sel[i+1].LocY,sel[i+1].LocZ)
    eb.options = [Armature.HINGE]
    arm.bones["bone$i"] = eb
    arm.update()
Blender.Redraw()
print "finito"

probem i’ve met is with Blender.Object.GetSelected()
it returns the list of selected objects with active object first and next objects sorted alphabetically.
Is there any method or possibilty to aquire list or stack of selected items from first selected to last one ??

0 Likes

(ideasman42) #2

sce = Blender.Scene.GetCurrent()
sel = list(sce.objects.context)
sel.sort(key= lambda a: a.name)

or
sel = Blender.Object.GetSelected()
sel.sort(key= lambda a: a.name)

0 Likes

(sanki) #3

that gives me perfectly sorted list from a to z, while i need list from object which i selected first to object which was selected last

0 Likes

(ideasman42) #4

this information is not stored.

0 Likes

(sanki) #5

thats a pity :frowning: it would be so much nicer

0 Likes

(ideasman42) #6

out of interest, how would you use this?

0 Likes

(sanki) #7

it was supposed to created armature in centres of selected objects, making chain based on how objects were selected.
I.E. having an arm with joints, by selecting joints from shoulder to wrist it should create 2 bones with heads and tails in joints centres

0 Likes

(ashsid) #8

sanki,

you can save order in which objects were selected using spacehandler script.

0 Likes

(sanki) #9

ashsid thx i will check that.

0 Likes