Results 1 to 12 of 12
  1. #1

    move a bone using python on "frame change" scriptlink?

    does anyone know a working python script that will get the position, then set the position of a bone in an armature using python so it can be activated on a frame change(using scriptlinks)?

    any help would be MUCH appreciated, thank you very much :-)
    Last edited by 3Duaun; 20-Dec-09 at 13:55.



  2. #2
    I found the solution:
    Here's the simple way to have constraints that arent properly updating do what they "should"

    use this as the python script that is triggered on FRAME CHANGE in your SCENE SCRIPT LINKS:
    ****************
    import Blender

    ob = Blender.Object.Get('YourArmatureNameHere)

    ob.makeDisplayList()

    Blender.Window.Redraw()
    **************************
    Last edited by 3Duaun; 25-Apr-10 at 23:18.



  3. #3
    here's the complex solution, now constraints UPDATE AUTOMATICALLY that would otherwise need the bone to be manually moved with the G key to update in the 3D window.


    import Blender
    from Blender import Draw, Object, Scene, Mathutils, Noise, Armature
    from Blender import *

    scn = Scene.GetCurrent()
    ob = Blender.Object.Get('NameOfYourRig')
    pose = ob.getPose()
    posebone = pose.bones['nameOfBoneYouWantToMoveHere']

    #print posebone.poseMatrix
    print "\n"

    ref1 = Blender.Object.Get('Rig').getPose().bones['nameOfYourBoneHere']
    ref2 = Blender.Object.Pose.PoseBone

    #Pose.LOC

    print 'refresh3'
    print (ref1)

    #ob.makeEditable()
    #ob.update()
    pose = ob.getPose()


    #set variable for current frame
    curfx1 = frame=Blender.Get('curframe')
    #print variable for current frame
    print curfx1

    if curfx1 == 1:
    posebone.loc[0] = 0.5
    posebone.loc[1] = 0.5
    posebone.loc[2] = 0.5
    print posebone.loc[0]
    print posebone.loc[1]
    print posebone.loc[2]
    elif curfx1 == 2:
    posebone.loc[0] = 0
    posebone.loc[1] = 0
    posebone.loc[2] = 0
    print posebone.loc[0]
    print posebone.loc[1]
    print posebone.loc[2]
    elif curfx1 == 3:
    posebone.loc[0] = 1
    posebone.loc[1] = 1
    posebone.loc[2] = 1
    print posebone.loc[0]
    print posebone.loc[1]
    print posebone.loc[2]

    #THIS LINE BELOW IS THE KEY TO THE FRAME CHANGE UPDATE!!!!!!
    ob.makeDisplayList()

    Blender.Window.Redraw()
    Blender.Window.RedrawAll()
    Blender.Scene.getCurrent().update()



  4. #4
    Originally Posted by blenderificus View Post
    here's the complex solution, now constraints UPDATE AUTOMATICALLY that would otherwise need the bone to be manually moved with the G key to update in the 3D window.


    import Blender
    from Blender import Draw, Object, Scene, Mathutils, Noise, Armature
    from Blender import *

    scn = Scene.GetCurrent()
    ob = Blender.Object.Get('NameOfYourRig')
    pose = ob.getPose()
    posebone = pose.bones['nameOfBoneYouWantToMoveHere']

    #print posebone.poseMatrix
    print "\n"

    ref1 = Blender.Object.Get('Rig').getPose().bones['nameOfYourBoneHere']
    ref2 = Blender.Object.Pose.PoseBone

    #Pose.LOC

    print 'refresh3'
    print (ref1)

    #ob.makeEditable()
    #ob.update()
    pose = ob.getPose()


    #set variable for current frame
    curfx1 = frame=Blender.Get('curframe')
    #print variable for current frame
    print curfx1

    if curfx1 == 1:
    posebone.loc[0] = 0.5
    posebone.loc[1] = 0.5
    posebone.loc[2] = 0.5
    print posebone.loc[0]
    print posebone.loc[1]
    print posebone.loc[2]
    elif curfx1 == 2:
    posebone.loc[0] = 0
    posebone.loc[1] = 0
    posebone.loc[2] = 0
    print posebone.loc[0]
    print posebone.loc[1]
    print posebone.loc[2]
    elif curfx1 == 3:
    posebone.loc[0] = 1
    posebone.loc[1] = 1
    posebone.loc[2] = 1
    print posebone.loc[0]
    print posebone.loc[1]
    print posebone.loc[2]

    #THIS LINE BELOW IS THE KEY TO THE FRAME CHANGE UPDATE!!!!!!
    ob.makeDisplayList()

    Blender.Window.Redraw()
    Blender.Window.RedrawAll()
    Blender.Scene.getCurrent().update()
    I have a scene with objects and bones (all of which belong to the same armature) that are constrained to the objects by copy location and copy rotation.

    If I add the lines in your second will it make the bones move every time the script iterates over the objects to set their coordinates in space?

    Thanks a lot



  5. #5
    Yup! It works but I can't make a parented mesh deform itself along the way. It's weird because it moves alright when I grab or rotate each bone manually. Do you know why that may be?



  6. #6
    Member Atom's Avatar
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    11,632
    You may want to take a look at that walking ant script that was posted here a week or so ago.

    Sorry I don't have a link.
    I rarely use Blender anymore.
    Houdini Indie is only $200.00 and Apprentice is free!
    Atom's Links Page



  7. #7
    Originally Posted by Atom View Post
    You may want to take a look at that walking ant script that was posted here a week or so ago.

    Sorry I don't have a link.
    got any more clues about how to look fot it? I've been googling it but can't find it.



  8. #8
    this script I've posted, truly only operates properly on framechange, I tried a number of methods to get constrained objects to properly position themselves in realtime while transforming/translating another object, but in the end I had to settle on the proper result of the computed constraints working only on framechange. this doesnt mean it impossible in another more real-time form, but I just want able to get it to work that way in the many tests I created/performed.

    In the end, in my opinion, 2.49x has a LOT of hacks in its underpinnings, especially with regard to python. So, yes, you do have to maybe do a "move to next frame", then go back to the previous frame you were working on to see the proper constrained result, but at least it works. 2.5 looks already to have fixed many/all of these issues, but for 2.49, given my time constraints for the project this was needed on , this was the best i could do at the time.

    If you find a new solution to this issue in 2.4x, PLEASE post your finding, I would enjoy looking through them.



  9. #9
    I have posed a blend file here
    http://blenderartists.org/forum/show...48#post1709348

    Download and Press ALT+A
    Bone Angle changing according to Frame Changed. Script Link with Frame Changed.



  10. #10
    Member Atom's Avatar
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    11,632
    I rarely use Blender anymore.
    Houdini Indie is only $200.00 and Apprentice is free!
    Atom's Links Page



  11. #11
    @Atom, thanks for the link. If you've already tested that blendo you know if that solves the realtime constraint&Bone calculation without the need for a framechange?



  12. #12
    Originally Posted by 3Duaun View Post
    @Atom, thanks for the link. If you've already tested that blendo you know if that solves the realtime constraint&Bone calculation without the need for a framechange?
    anybodoy test this in new versions? will it work to make my character aim with the arm???



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •