Connecting Attributes through API

I’ve written my first and very simple sine wave node using the python maya api.

In order to use the node I need to connect the time1 nodes outputTime to an attribute in my custom sine node called input.

I can do this manually every time I create the node, but thats not fun, I was wondering how to do it via the api, so everytime I create the node it automatically connects the two attributes together.

Cheers.

The typical “api approach” to this type of problem is to create a command along with your node in the same plug-in.

If all you’re doing is connecting attributes though, it’s an awful lot of overhead, so you’d be just as well to write a simple python function to do the same thing.

If you want to do it “properly” and create an API command to go with your node, check out RobTheBloke’s site. Look for API/SimpleNode example 2, where he does exactly what you want.

http://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/

Many thanks, had a quick read and it certainly seems a lot of work for something so simple, I’ll have a dig through it tomorrow see if I can convert it to python.

Cheers.

If you’re wanting to do this in Python, then I don’t think it’s especially helpful to look at a site with C++ examples when there are plenty of free Python examples out there.

I have a few freebies on my site at the bottom of this page. I’d suggest looking at the Expose Transform plug-in, since it’s a bit cleaner and clearer than some others.

Just curious why you just dont do it in C++ ?

If it is something the node should do every single time it is made, what is wrong with postContructor?

Is there a benefit to having it either as a command (I agree to heavy handed) or external to the node which breaks the idea of encapsulation?

Love to know for my edumafacationism

The reason I am using python is due to the fact that its for a uni project all about using python inside maya.

I have no idea what a postConstructor is lol.

Adam, cheers for the python example, I see you use the connectAttr method, will have a further read later.