Home Technical Talk

[Maxscript Help] How to rename multiple bones in 3dsmax?

nidalnijm
polycounter lvl 2
Offline / Send Message
nidalnijm polycounter lvl 2
Hello folks,

I have some rigged biped characters which I want to export to UDK. For exporting to UDK, the bones objects must have the same name of default UDK Skeleton.

Whenever I manually rename the bones, it works perfectly, however I want a script to this automatically. Searching on google I came to this topic:


It`s exactly what I need, however, the above script does not work!

I only know the very few basic notions of maxscript, and whenever I run this script:

(
    local fromPrefix = "mixamo:"
    local toPrefix = "bip01_"

    local nameMap = #( \
        dataPair "left_foot" "Lfoot", 
        dataPair "neck" "neck_special_effects_attachment" 
        -- add more mappings here 
    )

    for namePair in nameMap do
    (
        local fromName = fromPrefix + namePair.v1
        for o in getNodebyName fromName all:on do 
        (
            o.name = toPrefix + namePair.v2
        )       
    )
)

I don`t receive any errors in Max Listener, however, the bones don`t get renamed and by analizing the script, I think the problem is with the variable namePair, which was not declared.

Whenever i try to print the fromName variable, then i get a Max Listener error message saying that the namePair.v1 (the first value of the array) is undefined.

I tried to read some instructions here on official 3dsmax documentation:


But i don`t know how to make this script to work.

If anyone can help me, I will be very gratefull.

Thanks in advance.

Cheers.

Replies

  • monster
    Options
    Offline / Send Message
    monster polycounter
    The script is correct. Did you add all the dataPairs at line 8? The script as it stands will only find and rename two objects. (Lines 6 and 7).

    "I think the problem is with the variable namePair, which was not declared."

    In MaxScript you don't need to declare variables as strictly as with other languages. "for namePair in nameMap do" is enough for MaxScript.

    "Whenever i try to print the fromName variable, then i get a Max Listener error "

    It works for me if I put print namePair.v1 after line 13. 
  • nidalnijm
    Options
    Offline / Send Message
    nidalnijm polycounter lvl 2
    monster said:
    The script is correct. Did you add all the dataPairs at line 8? The script as it stands will only find and rename two objects. (Lines 6 and 7).

    "I think the problem is with the variable namePair, which was not declared."

    In MaxScript you don't need to declare variables as strictly as with other languages. "for namePair in nameMap do" is enough for MaxScript.

    "Whenever i try to print the fromName variable, then i get a Max Listener error "

    It works for me if I put print namePair.v1 after line 13. 
    Thanks friend for the fast repply and taking your time for helping me :awesome:

    You are right, the two values of dataPair are being correctly processed on the script.

    I changed the script a bit:

    (
        local nameMap = #( \
            dataPair "R_" "Right", 
            dataPair "L_" "Left",
            dataPair "Clavicle" "Clav"
            -- add more mappings here 
        )

        for namePair in nameMap do
        (
    --test variable values
    print namePair.v1
    print namePair.v2
            for o in getNodebyName namePair.v1 all:on do 
            (
                o.name = namePair.v2
            )
        )
    )

    Now it prints:

    "R_"
    "Right"
    "L_"
    "Left"
    "Clavicle"
    "Clav"
    OK

    So this is good, however, the problem is that the object selected, in case the bone Clavicle, does not get renamed, the name is still Clavicle instead of Clav.

    I think it is something which has to do with this part of the script, this statement which tells to rename the object:

            for o in getNodebyName namePair.v1 all:on do 
            (
                o.name = namePair.v2
            )

    Any help?

    Cheers.
  • trebor777
    Options
    Offline / Send Message
    trebor777 polycounter lvl 10
    I think you're trying to substitute a part of the object name by another?
    GetNodeByName needs the fullname :) not just a part of it.
    The script work, it just doesn't find any node just named 'L_'  or 'Clavicle'
    It can't find (currently) 'L_Clavicle' or vice-versa.

    This should do it:
    (
        local nameMap = #( \
            dataPair "R_" "Right", 
            dataPair "L_" "Left",
            dataPair "Clavicle" "Clav"
            -- add more mappings here 
        )
        
    	for namePair in nameMap do ( -- check name pattern
    		for obj in objects where matchPattern obj.name pattern:("*" + namePair.v1 + "*") do ( -- parse all objects that match the pattern with the name of the object
    			obj.name = substituteString obj.name namePair.v1 namePair.v2 -- replace the strings
    		)
    	)
    )



  • nidalnijm
    Options
    Offline / Send Message
    nidalnijm polycounter lvl 2
    Oh man, thanks!!!!!!! It worked!!!!!!!!!! You saved my day!!!!!!!!!!!!!!!  =)
Sign In or Register to comment.