OpenMaya C# Standalone

Hey Guys,
Has anyone successfully created a C# standalone, that can push changes into Maya, from the the OpenMaya API?

The goal I was aiming for, was a standalone software that could do basic things within a maya scene, like get scene DagNodes, the Dependancy graph, read skin cluster data, or export selections.
I have run a few tests and get the following error every time I use the OpenMayaCS.dll, in my C# project.

"An unhandled exception of type ‘System.BadImageFormatException’ occurred in MyStandalone.exe

Additional information: Could not load file or assembly ‘openmayacs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. An attempt was made to load a program with an incorrect format."

I’ve looked into all the standard fixes for library load failures, and I am being to assume it just cant be done.
Was hoping someone here might have some experience with this, they can share, or pose a possible alternative.

Im using: maya 2014 sp7, Visual studio, .Net 4.5.2

Cheers,
-K

I haven’t tried this, but I suspect you’ll need to use pinvoke.

I don’t believe the openMaya dll includes an actual running Maya: I think it’s just a wrapper around OpenMaya, so i believe it won’t have anything to talk to if run from outside of Maya.

You could maybe write your app as a plugin using the C# api and control Maya from there, passing args on the command line to a headless maya instance

You can load foundation.dll and you’ll have a functional copy of Maya. Here there be dragons.

Oh, BTW, if you want C# to talk with a running copy of Maya directly, I’ve done that both via Maya’s built in command port and by writing a WCF framework to do RPC like calls into Maya. For anyone not willing to pour weeks learning WCF/Python.net, I recommend the command port route.

EDIT: And someone tell me if I’m wrong, but you have to use a real TCP/IP port on Windows. *nix style named pipes seem to be completely bogus on Windows.

Don’t forget that mayabatch.exe is still always an option as well for some tasks (such as a build pipeline). It is no frills, but bulletproof.

figured the first responders would be the TA heavy hitters.

Thanks for the input guys :slight_smile:

@Theo “You could maybe write your app as a plugin using the C# api and control Maya from there, passing args on the command line to a headless maya instance”

K: Yea, was thinking this may be the fallback, I’m not so keen on this as it relies of a level of obfuscation and maintaining the libraries would be a bit more challenging.

though it seems like it may be necessary. sadly. :frowning:

@btribble: “You can load foundation.dll…”
K: Sadly, I was unable to load foundation.dll, I received the following: “Please make sure the file is accessible, and that it is a valid assembly or COM component”

Also, I was planning on having this run seperately, and interface with Maya for content on the Users current working file, as needed. So, maybe… a functional copy isnt ideal, as i need the current application instance. :frowning:

Currently, I have this working with photoshop through its COM interface, but with Maya…I think I may be reaching too far on this one.

Is there a way to do this through another language? maybe python? C++?

You want to look at the commandPort stuff. This will work as advertised, though if you want to run multiple copies of Maya concurrently, things get more complex.

Oh Beautiful. These are great options. :slight_smile:

I have a few options now, plugin[args], commandport and mayaBatch files, and all 3 look promising and expandable.

Thanks very much for taking the time to reply.

:slight_smile:

Hey Just wanted to say thanks again,
Also to update I ended up going with a local PC WCF server/client setup. Between a C# Maya plugin and my External C# Tool, to send string commands back and forth.
Works good so far, and seemed like a decent solution.

Cheers,
-Karl

Don’t forget to use Maya’s threading stuff on the far end.

http://download.autodesk.com/global/docs/maya2014/en_us/index.html?url=files/Python_Python_and_threading.htm,topicNumber=d30e815215