[Maya-Python] pymel setParent()

211 views
Skip to first unread message

shawnpatapoff

unread,
Apr 22, 2010, 2:26:26 PM4/22/10
to python_inside_maya
Is there anyway around Maya selecting the object that you're parenting
when using setParent? Ideally I would like to do this:

a = ls(createNode('transform', ss=True))
b = ls(createNode('transform', ss=True))

b[0].setParent(a)

without 'b' being reselected.
I can of course clear the selection if I need to. Would be nice if
there was a hook in setParent(ss=True)

Cheers,
Shawn

--
http://groups.google.com/group/python_inside_maya

Judah Baron

unread,
Apr 22, 2010, 4:21:30 PM4/22/10
to python_in...@googlegroups.com
This is not an answer to the question, but I thought I'd post a
relevant discovery we made here, with the hope that it might help
someone else out if they run into a similar issue. We found
cmds.parent to be horribly inefficient when doing a large batch of
re-parenting. We have a system that uses callbacks to monitor our
shape library, and in this system we clean up a scene every time it is
loaded. This means we're doing a fair amount of re-parenting, though
for the slowdown that we encountered, the slowdown seemed
disproportionately large: we did tests that topped out at around 400
shapes being parented. this resulted in execution times approaching
some number of minutes. We switched over to api calls and there was a
precipitous drop in execution times: 5-10 seconds tops. It does make
some sense, and I don't think this means you have to use the api to do
all parenting, but in certain situations it may help.

Also of note: we have run into some performance issues using cmds.file
to open files. The mel call works fine, and so does the api, so we use
the api call to open files now.

We are currently running Maya2009 32 bit PC.

-Judah
--
http://groups.google.com/group/python_inside_maya

deanareeno

unread,
Apr 22, 2010, 6:49:01 PM4/22/10
to python_inside_maya
Just for clarification, are you saying that you can use the setParent
command to parent objects? Because my usage of setParent has always
been with UI controls -- I thought that's what it was intended for.

Cheers,

-DW

shawnpatapoff

unread,
Apr 22, 2010, 7:22:37 PM4/22/10
to python_inside_maya
In this particular case I'm using it for parenting nodes. I'm new to
using pymel and since it works I figure it's legit.
--
http://groups.google.com/group/python_inside_maya

Ofer Koren

unread,
Apr 23, 2010, 4:04:27 AM4/23/10
to python_in...@googlegroups.com
As far as I know the only way to do that is through an API call...

curious - what is the 'ls' for? aren't you getting a valid object from the 'createNode' function?

--
http://groups.google.com/group/python_inside_maya

shawnpatapoff

unread,
Apr 23, 2010, 12:05:38 PM4/23/10
to python_inside_maya
You are correct sir.

On Apr 23, 1:04 am, Ofer Koren <kor...@gmail.com> wrote:
> As far as I know the only way to do that is through an API call...
>
> curious - what is the 'ls' for? aren't you getting a valid object from the
> 'createNode' function?
>
> - Oferwww.mrbroken.com
>
> On Thu, Apr 22, 2010 at 11:26 AM, shawnpatapoff <shawnpatap...@gmail.com>wrote:
>
>
>
> > Is there anyway around Maya selecting the object that you're parenting
> > when using setParent? Ideally I would like to do this:
>
> > a = ls(createNode('transform', ss=True))
> > b = ls(createNode('transform', ss=True))
>
> > b[0].setParent(a)
>
> > without 'b' being reselected.
> > I can of course clear the selection if I need to. Would be nice if
> > there was a hook in setParent(ss=True)
>
> > Cheers,
> > Shawn
>
> > --
> >http://groups.google.com/group/python_inside_maya
>

Daniel Ruiz

unread,
Apr 19, 2017, 1:41:45 PM4/19/17
to Python Programming for Autodesk Maya
it should be 
b[0].setParent(a[0]) 

you are trying to parent to an array XD 

Justin Israel

unread,
Apr 19, 2017, 3:25:26 PM4/19/17
to Python Programming for Autodesk Maya


On Thu, Apr 20, 2017, 5:41 AM Daniel Ruiz <danielk...@gmail.com> wrote:
it should be 
b[0].setParent(a[0]) 

you are trying to parent to an array XD 

I think you win the award for reviving the oldest thread. This last post was almost 7 years ago, to the day! :-) 


On Thursday, April 22, 2010 at 2:26:26 PM UTC-4, Poff wrote:
Is there anyway around Maya selecting the object that you're parenting
when using setParent? Ideally I would like to do this:

a = ls(createNode('transform', ss=True))
b = ls(createNode('transform', ss=True))

b[0].setParent(a)

without 'b' being reselected.
I can of course clear the selection if I need to. Would be nice if
there was a hook in setParent(ss=True)

Cheers,
Shawn

--
http://groups.google.com/group/python_inside_maya

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b4b4752b-be39-4139-92bf-9afcdfc9af28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages