0

I've been trying to get this to work for so long now, I've read the docs here, but I can't seem to understand how to implement the GeometryConstraint.

Normally, the derivative version of this would be:

geometryConstraintNode = pm.geometryConstraint(target, object)

However, in Pymel, It looks a little nicer when setting attributes, which is why I want to use it, because it's much more readable.

I've tried this:

geometryConstraintNode = nt.GeometryConstraint(target, object).setName('geoConstraint')

But no luck, can someone take a look?

Shannon

Shannon Hochkins
  • 11,763
  • 15
  • 62
  • 95

1 Answers1

2

this doesn't work for you?

import pymel.core as pm

const = pm.geometryConstraint('pSphere1', 'locator1', n='geoConstraint')
print const
const.rename('fred')
print const

output would be

geoConstraint
fred

and a constraint object named 'fred'.

The pymel node is the return value that comes back from the command defined in pm.animation.geometryConstraint. What it returns is a class wrapper for the actual in-scene constraint, which is defined in pm.nodetypes.GeometryConstraint. It's the class version where you get to do all the attribute setting, etc; the command version is a match for the same thing in maya.cmds with sometimes a little syntactic sugar added.

In this case, the pymel node is like any other pymel node, so things like renamimg use the same '.rename' functionality inherited from DagNode. You could also use functions inherited from Transform, like 'getChildren()' or 'setParent()' The docs make this clear in a round-about way by including the inheritance tree at the top of the nodetype's page. Basically all pynode returns will share at least DagNode (stuff like naming) and usually Transform (things like move, rotate, parent) or Shape (query components, etc)

theodox
  • 12,028
  • 3
  • 23
  • 36
  • I'm looking to do this differently though, I've already posted the exact same code you did in my question, I'm trying to do this an alternate way. – Shannon Hochkins Aug 23 '13 at 05:27
  • The __command__ version has to be fired to create the scene object and hook their connections; the __nodetype__ version is a wrapper around that. You can do pm.geometryConstraint('pSphere1', 'locator1').setName('blah'). You can get an existing constraint with pm.PyNode('oldName').setName('newName') – theodox Aug 23 '13 at 06:04
  • ... btw use pm.PyNode('name-of-existing-object') instead of 'pymel.nodetypes.ClassName('name-of-existing-object') so you don't have to know the type: http://daydreamer3d.weebly.com/instantiating-a-maya-node-in-pymel-pymel.html – theodox Aug 23 '13 at 06:12