Link object by name then run command

Link object by name then run command

dgeeQYWSW
Contributor Contributor
529 Views
4 Replies
Message 1 of 5

Link object by name then run command

dgeeQYWSW
Contributor
Contributor

Hello, all Hope you are having a good day.  I have a mel script that will take a selected curve and apply stitching to it.  What I want to be able to do is loop the command by selecting all of the stitch geo and all of the curves.  Then have the script apply the command to the curve and stitch of the same suffix: example stich_004 and PolyCurve_004.  I'm not sure how to go about that.   I know how to add them to a list but how can I say I only want the pairs with the same numbering?  Also sidenote how would I add a proper suffix to a rename script? 

 

seam2Curve

 

global proc seam2curve ()
{
    string $geeseam[] = `ls -sl`;
    createCurveWarp;
    applyPresetToSelectedNodes "curveWarp2" "" "" "sofa_chair_stich" 1;
    select $geeseam;
    toggleVisibilityAndKeepSelection `optionVar -query toggleVisibilityAndKeepSelectionBehaviour`;
    select -cl  ;  
}
seam2curve ()

 

rename script:

string $geerename[] = `ls -sl`;
for( $x=000; $x < size ($geerename) ;$x++ ) {
rename $geerename[$x] ("polyToCurve_" + $x);
}

Thank you for all your help!

0 Likes
530 Views
4 Replies
Replies (4)
Message 2 of 5

FirespriteNate
Advocate
Advocate

when you say "add a proper suffix to a rename" what exactly do you mean?

Do you want to add a given suffix (e.g. "_crv", "_left", etc..) or do you mean you want a padded index (i.e. "_004")?

 

Do you have to use MEL? it's possible in MEL, but all this stuff is so much easier in Python.

Here's one way to do all of that in MEL:

global proc myRenamer(string $prefix, string $suffix, int $pad)
{
    // we probably only want to rename transforms
    string $sel[] = `ls -sl -tr`;
    int $count = 1;
    for ($item in $sel)
    {
        int $width = `size(string($count))`;
        string $padding = `substring "0000000000" 1 ($pad-$width)`;
        rename $item ($prefix+"_"+$padding+$count+$suffix);
        $count++;
    }
}

now, if you select a bunch of objects and execute something like:

myRenamer "box" "_mesh" 4;

 it will rename them all:

box_0001_mesh
box_0002_mesh
box_0003_mesh
...
box_0010_mesh
box_0011_mesh

But bear in mind this is, in practice, a lot more complicated than this.. what if you want to rename shapes or DG nodes? what if you have edges or CVs selected? What if you already have an object (or namespace?) with the desired name? etc, etc...

 

As for your first question, that has way too much to unpack right now, so lets come back to that later 😅

Message 3 of 5

dgeeQYWSW
Contributor
Contributor

Thanks for the feedback.  It does not have to be in mel.  I'm learning how to go between mel and python.   I would like to be able to tack on a _004 at the end.  

 

In your code I'm no sure what padding does.  but this looks great thank you.

0 Likes
Message 4 of 5

Kahylan
Advisor
Advisor

Hi,

The padding makes sure that all the numbers have the same lenght. So your numbers count up like:
0008

0009

0010

0011

Instead of:
8

9

10

11

 

This makes it easier if you need to later split your strings.

As for your other question. I'm not quite sure what you mean by "take a selected curve and apply stitching to it". Maybe this is a tool I don't know yet. But could you describe to me what it does and how you would do it manually?

I'm pretty sure that there will be a better and more robust way to find the geo from the curve without comparing their names. for example a history relationship. But I would have to recreate what you are doing to find that out.

 

Message 5 of 5

dgeeQYWSW
Contributor
Contributor

So what I have is a mesh that is modeled like stitches.  I'm taking that mesh and attaching it to a curve using the Curve warp tool.  So I have like 80 curves and stitches that I'm trying to do all at once.  But I first want to rename the curves and the mesh so that they have a name match.   Example:  stitch_01_geo and curv_01_cv.   Then apply the curve warp too to the matching geo and curve. 

0 Likes