Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cinema4D Integration #497

Open
BigRoy opened this issue Dec 23, 2019 · 8 comments
Open

Cinema4D Integration #497

BigRoy opened this issue Dec 23, 2019 · 8 comments

Comments

@BigRoy
Copy link
Collaborator

BigRoy commented Dec 23, 2019

Integrate Avalon with Cinema4D

This issue is about Maxon's Cinema4D and building a cinema4d integration for Avalon.

Cinema4D has grown popular amonst many new small-to-medium sized studios because of its ease-of-use. With that stable user base now growing into larger productions it could be great if Avalon could allow them the stable growth to run animation productions efficiently.

Unlike Blender it seems Cinema4D does have some code related to threading which means it could be slightly more trivial to get things up and running nicely.

Implementation notes

@BigRoy
Copy link
Collaborator Author

BigRoy commented Dec 23, 2019

When Cinema 4D starts, it finds all files in this folder that end with .pyp or .pypv and executes the plugin. A simple plugin possible thus looks like this:

def main():
    print "Hello World!"

main()

Source

As such, this can definitely be used to run code at startup.


The plugin can be contained inside Avalon and pointed to with C4D_PLUGINS_DIR

This C4D_PLUGINS_DIR seems to have been removed since R20 and replaced with g_additionalModulePath as mentioned here and its usage described here


Posted a question regarding adding a Custom Menu with Custom Python Commands to Cinema4D's top menu bar on the Maxon forums as the Enhance Main Menu example left out how to register custom Python commands and add them to the menu.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jan 2, 2020

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jan 4, 2020

Found an odd bug with Cinema4d where Python scripting gets broken, this is noticable in Extensions > Scripts Manager... (Shift + F11) where the Execute button remains disabled.

The command line log shows:

WARNING: no python vm found [main.cpp(547)]

It seems to happen whenever an empty value is in the PYTHONPATH path separated values, as described here:

# good
set PYTHONPATH=
set PYTHONPATH=a;b;c

# bad
set PYTHONPATH=;
set PYTHONPATH=;a;b
set PYTHONPATH=a;;b;c

Found the issue in Cinema4D R21.115 TRIAL (Build RB297076)

This bug is something to be wary of when we would launch it through the Launcher.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jan 4, 2020

Here are some progress previews:

Work Files
2020-01-04-14-11-51

Avalon Qt interfaces opening fine
2020-01-04-14-12-31

Here's the quick and dirty draft integration: BigRoy@99bd8bb

Note:

  • The menu items Plugin id ranges are totally random which is dangerous. These should still be changed to registered plugin id ranges for Avalon. E.g. this one is not "registered for avalon" as such might conflict with other plugins
  • To initialize C4D with this integration I used the g_additionalModulePath environment variable and set that to {core}/setup/cinema4d
  • The menu building currently is initialized in the Plugin and not in avalon.cinema4d.install - we might want to move that to be more in line with the other hosts.
  • I have not tested Loaders or have any ls() implementation yet.
  • save_file should also still set the active document to that path. Now it does save, but your current scene will still think it's set to the old path.
  • Someone will have to explain me how C4D documents/projects work. Apparently you can have many open at the same time but I just can't find where you can actually switch to another open document/project without closing the one you're working in. (Through the UI that is)

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jan 4, 2020

Someone will have to explain me how C4D documents/projects work. Apparently you can have many open at the same time but I just can't find where you can actually switch to another open document/project without closing the one you're working in. (Through the UI that is)

They actually do show in the UI at the bottom of the Window menu item unless you open a document in code with c4d.documents.LoadDocument instead of c4d.documents.LoadFile and not explicitly insert the base document with c4d.documents.InsertBaseDocument. Note that with LoadDocument the file will also not be active automatically (instead its hidden for you) which you can do with c4d.documents.SetActiveDocument however that's all redundant when you instead use c4d.documents.LoadFile.

Still it's confusing. 🗡🐉

save_file should also still set the active document to that path. Now it does save, but your current scene will still think it's set to the old path.

Fixed with BigRoy@9dd09ae

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jan 4, 2020

Did some quick investigating into how one could create and prepare instances for publishing. In Maya we use objectSets as containers of what to output. In Houdini we have "ROP nodes" that point a specific node to export.

Create publish instances in C4D

UserData tags on a node

For Cinema4D I couldn't find any "selection sets" or "object sets" or "containers" that would allow picking a specific set of nodes for exporting - so that didn't seem like the right way to go. I looked at Layers, but they are exclusive for objects (can't be in two layers at the same time) and are used for rendering too which is an area you wouldn't want any clutter to go.

Then I looked into Tags which seemed pretty nice, however it seems they are always applied to a single node and never shared. Nevertheless that definitely seemed like a nice direction because you can colorize them the way you want, give them a custom icon and there seems to be a "Stub" Tag called "UserData" which would be perfect. You can add custom attributes to the tag that allow the customization per tag we need.

Example:
avalon_c4d_userData_tag_example

However the downside is still that it would only allow choosing a specific root note, not specific objects you want to include - but I guess there isn't a simple way to do that in C4D anyway.

UserData tags would be a good way forward.

Or... Inclusion Data on a Null with Inclusion UserData field

Or, a single Null node could be created for each publish instance that has custom attributes defining the settings. There's a specific inclusion user data field in Cinema4D that allows to do some sort of Memberships, like an object set or collection. This could be perfect for what we'd need. However, the UI in managing it is somewhat clunky. Additionally I'm not sure how trivial it is for advanced C4D users to find these relationships (e.g. not even sure if you can find it from e.g. the member itself)

avalon_c4d_null_userData_inclusionMembers

Here's the User data field in the Manage User Data interface:

avalon_c4d_in-exclusion_user_data

Also, this Topic seems related to UserData In-Exclusion fields in C4D and Python access too.

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jan 6, 2020

Another way of creating instances for publishing using "selection sets" was described on Avalon Gitter, linking it here for future reference. Thanks! Here it is in the Maxon Cinema4D documentation on Selection Object

@BigRoy
Copy link
Collaborator Author

BigRoy commented Jan 9, 2020

Progress on this Integration will likely slow down on my end because of two reasons:

  1. The obvious, less time on my hands.
  2. More importantly, I can't actually use Cinema4D anymore as my trial period expired. Had some contact with Maxon but they seem unwilling to extend the trial to allow me to continue the integration work in my spare time.

So if anyone needs this in production feel free to still hit me up, and definitely use the above things as a basis. Regarding Pyblish and pyblish plugins for C4D definitely look in the Pyblish for Cinema4D topic and check in with Andre Anjos as he'll be happy to share details too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant