Creating and managing rivets with cmds.Rivet

Creating and managing rivets with cmds.Rivet

infoLGS2B
Explorer Explorer
1,382 Views
1 Reply
Message 1 of 2

Creating and managing rivets with cmds.Rivet

infoLGS2B
Explorer
Explorer

Hi, I am trying to create some rivets with python using cmds.Rivet. Since i have to constraint them to some precise objects in a for loop, i need either to create them with the proper names or to rename them after the creation. I am seeing that cmds.Rivet() creates both the uvPin and the locator nodes but the function does not return the list with the two object names, therefore I can't access these two objects if not with some hard coded/not so clean tricks.

 

I tried also to add a name kwarg to the function call but it looks like it accepts it but it does not create the locators with the proper names (maybe there is something like *kwargs in the function definition? Because i tested it and it is accepting any argument I am writing without raising errors).

 

I also tried 

import maya.internal.nodes.uvpin.cmd_create as ptguv
ptguv.Command().execute(setupMode=0, outputConnect=3, allowCreateWithoutInputs=False)

 

Which should be the code run under the hood, but still the execute method is not returning anything. Am i missing something?

 

Thanks!

0 Likes
1,383 Views
1 Reply
Reply (1)
Message 2 of 2

Kahylan
Advisor
Advisor

Hi!

 

Using cmds.Rivet() is already not the cleanest way to go about this, since it is a compound function that is very restricted (it needs correct selection, doesn't return values,changes selection, etc), I would probably write my own uvPin constraint function so I can decide what kwargs I can give and what I will receive.

 

But the fact that cmds.Rivet is so restricted also has an upside. Namely that it will select all relevant objects after it is finished, so you can simply use the selection list to get your uvPin Node and your pinOutput node/nodes like this:

def returnRivet():

    cmds.Rivet()
    uvPinOut = mc.ls(sl=True)
    uvPin = uvPinOut.pop(0)
    return [uvPin,uvPinOut]


pin, output = returnRivet()

But I'm not sure if this falls under your definition of "not clean"... You could also try to access the mel feedback of the script editor, but that is a lot more hacky than using the selectionlist...

 

I hope it helps!