@r_gigante Thanks, the command examples were exactly what I needed. And someone stating explicitly that I needed to create a command per menu entry made me help realize that too.
I now have an Avalon menu - perfect.
Bug with C4D and PYTHONPATH
I did hit a C4D bug as I started setting up the pipeline integration, whenever there's an empty value in the list on
PYTHONPATH then Python fails to run correctly in Cinema4D. More details here
Icons. Are they
I've tried to add an icon to the menu but I failed there. I tried to pass it a
.svg icon like so:
bitmap = c4d.bitmaps.BaseBitmap() bitmap.InitWith(path)
And then providing that to
c4d.plugins.RegisterCommandPlugin as the 4th argument (where there's
None in your example). However, the menu entry showed no icon.
Should this work?
Opening files in C4D with Python (resolved)
I should be separating this out into a new Topic I suppose. But any pointers on how to save/open scenes in C4D Python?
I've tried this:
import os import c4d def file_extensions(): return [".c4d"] def _document(): return c4d.documents.GetActiveDocument() def has_unsaved_changes(): doc = _document() if doc: return doc.GetChanged() def save_file(filepath): doc = _document() if doc: return c4d.documents.SaveDocument(doc, filepath, c4d.SAVEDOCUMENTFLAGS_NONE, c4d.FORMAT_C4DEXPORT) def open_file(filepath): doc = c4d.documents.LoadDocument(filepath, c4d.SCENEFILTER_0, None) if doc: c4d.documents.SetActiveDocument(doc) return doc def current_file(): doc = _document() if doc: root = doc.GetDocumentPath() fname = doc.GetDocumentName() if root and fname: return os.path.join(root, fname)
But whenever I
open_file a document and set it active, then all functionality in C4D's UIs gets disabled and greyed out. Am I misinterpreting how this should work? The other code seems to do exactly what I need.
Edit I should have used
c4d.documents.LoadFile for opening a file - that does what I need.
However, it kept failing with:
Traceback (most recent call last): File "C:\Users\Roy\AppData\Roaming\Maxon\Maxon Cinema 4D R21_64C2B3BD\library\scripts\untitled.py", line 16, in <module> doc = c4d.documents.LoadFile(path) TypeError:unable to convert unicode to @net.maxon.interface.url-C
This was due to the filepath being
unicode. That's fixed by forcing it to