Im basing this text on my posting #1 above.
Related to another thread of mine Link_1 (Im providing you now only one link to one other thread casue the other one’s issue has been solved thanks to migius! :)), I will explain with pics and text in all reasonable details the problem Im facing to (1) detaching some object from their parent armature bones, (2) renaming them (this step can be skip for now for easy explaining the code problem), (3) attaching the same objects to the same bones (with new names or w/o new names) with the idea to everything working OK after this! Of course, Im speaking of doing this via a python script. And of course my idea is to do that over many bones/objects but for ease of explaining I customized my current scripts to just 1 object called “Cube.084” and 1 bone called “Bone.032”.
Here are some .blend files which I will refer to further - Robo_test_41.blend file Robo_test_42.blend file Robo_test_43.blend file
Here is the armature in my testing .blend file (with many of bones deleted, just R arm and back bones preserved plus three objects representing the three parts of the little finger):
This layout is with ALL three parts of the little finger parented to the bones. They are moving OK (see Robo_test_041.blend file).
How it is produced? There’ve been a lot of other parts (for legs, head, etc. - no removed for simplification of the scene) that were put at their positions. Then I added appropriate bones, then I linked (manually) objects to their respective bones. Then, of course, ALL this was saved!!! And before getting to the point of attaching a script to control the armature, I had the problem to rename the bones and I thought it could be done automatically (via a script). Then - after renaming - a complete mess of re-positioned objects appeared… So Im writing you about just one of those in order to investigate the reasons and = hopefully - find a solution which is to be spread out over all others, ok?
Now, let’s see what’s going on with object “Cube.084”… Starting with Robo_test_041.blend file, using the script set-up as shown in the following pic (running proc Arma_remove_parents(aName,oaName) ONLY - see the right part of the pic too!!!) and saved under a new file will give you the Robo_test_042.blend file with object “Cube.084” detached off its bone and still at the same position (see the Properties tab):
At the joint between 2-nd and third bone of little finger, I placed a cube that is NOT connected to the armature. I will tell you later on about this…
Now as soon as you have the file securely saved, you can load it again at what-so-ever time after that you’d expect (just as myself) after connecting the Cube.084 to the same bone nothing visually to happen except a new tiny dashed line to appear just showing us that the object and the bone have a parent-child relationship, right? Sooo please try only the next proc Arma_restore_parent_armature(aName,oaName) as shown on the pic below (right part) and look at the left part… Object Cube.084 moved slightly!
You may notice that the bigger cube (old position of Cube.084) is at (-10.240, -2.560, 7.610) while BEFORE and AFTER script run Cube.084 is reported to be (-10.240, -2.460, 7.610)!!!
The dashed line goes to armature insert point (armature center) and right now Cube.084 is NOT parented to its old bone Bone.032 but the whole armature. This is only for testing purposes! And you see, the Cube.084 moved a little! My question is why? Well, I can imagine that during construction and firls linking to the armature, some of cubes were moved, may be in EDIT mode, but I cannot expect after SAVING the file and linking to the same armature the same object to move!!! Also - pls compare the Properties panel - it show the same! Heh :eek: That is why Im looking for an answer to the question WHY SO?… At this point it is practically impossible to write a script (at for me) which is to “judge” somehow which object will move and which wont move after connecting to the armature! That is why I put the other cube (just in the middle of 2-nd and 3-rd bone of the little finger) - to test this… So to test what will happen - start with the original Robo_test_042.blend file, rename the bigger cube (called there Cube.0842) to cube.084, then apply the proc Arma_restore_parents(aName,oaName) ONLY as above, i.e. it will work over the “NEW” object “Cube.084”… And the rsult is that now the cube is NOT moved at all, just connected to the armature!
OK… Now start over again the original Robo_test_042.blend file and run proc Arma_restore_bone(aName,oaName) ONLY as shown in the script set-up to the right (pic below). The result is to the left - my object of interest (Cube.084) is linked to the bone but now it is located at bone’s end (not bone’s root as it was) plus that the object Cube.084 is rotated:
In the mean time the bone is renamed to “Fg_4_3_R” as per my plan. Even not renaming the bone, you will have the same situation with the Cube.084. Now Cube.084 location is reported to be (0,0,0) - it is due to the need of nulifying object’s location - otherwise, I need to look for my object very far away of this place! Suddenly, I found that the rotation applied to my cube is exactly (90,0,0) sooo if I apply a rotation to the oposite direction and move my cube at bone’s root, I will have the perfect situation I am looking for! The problem is HOW TO jusge on this as soon as - as above - I am still not able to write a script to sense this (location and rotation changed)… I tend to think that change of rotation comes due to the fact the arm point straight downwards and we are speaking about one of the fingers. If we dealt with one shoulder, there shouldnt be a need of rotation!!! Again - the problem HOW TO learn that via a certain script, i.e. w/o looking by eyes on it??? Plus - what if the angle wasnt 90 degrees? What if it is NOT sooo obvious? How to find it?
Again - try the above with the bigger cube - it attaches the same way to the same renamed bone! Does it mean that I need to destroy my ALL old object and re-work them again, position, rotate then attach to the bones so that I avoid the mess? I dont think so… There should be a way to attach old objects to their bones w/o deleting and reworking new ones! I think…
I tried to get bone’s matrix… but using this approach I reached nothing. May be this is a part of the solution, may be NOT.
Exploring the idea of bone’s matrix influencing the solution, I made the Robo_test_043.blend file. The armature there s with the R arm rotate to be horizontal, i.e. -90 degrees on X thus providing a chance to object Cube.084 NOT being rotated after the exercise I described last. On the pic below. pls notice that this is a TOP view and it come from the Robo_test_043.blend file with proc applied as per the script’s set-up to the right:
The result is as before - Cube.084 is moved and rotated, i.e. NOT following the bone’s line as it may be expected BEFORE starting the script…
The same question - WHAT is the reason for all that?
I know the posting became quite long… Thanks for the patience of ALL of you having read it entirely!
Pls any info/ideas on the solving the issues mentioned above… This will be very much appreciated!