Navigation

    • Register
    • Login
    • Search
    1. Home
    2. BigRoy
    3. Posts
    • Profile
    • More
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups

    Posts made by BigRoy

    RE: Custom menu in C4D top menu bar with custom Python commands

    @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 .tiff only?

    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 str using str(path).

    posted in Cinema 4D SDK •
    Custom menu in C4D top menu bar with custom Python commands

    I'm looking to set up a custom menu in the Cinema4D's top menu bar. I found the Enhancing the Main Menu example which shows how to add a custom menu yet it skips to to show how to add a bunch of custom commands as menu items.

    So basically this is what I found:

    import c4d
    from c4d import gui
      
    
    main_menu = gui.GetMenuResource('M_EDITOR')            
    
    # Create custom menu
    menu = c4d.BaseContainer()
    menu.InsData(c4d.MENURESOURCE_SUBTITLE, "MyMenu")
    
    # Add commands
    menu.InsData(c4d.MENURESOURCE_COMMAND, "IDM_NEU")
    menu.InsData(c4d.MENURESOURCE_SEPERATOR, True)
    menu.InsData(c4d.MENURESOURCE_COMMAND, "IDM_NEU")
    
    # Add custom menu to main menu
    main_menu.InsData(c4d.MENURESOURCE_STRING, menu)
    
    # Refresh menu bar
    gui.UpdateMenus()
    

    Yet now I'm looking to add some menu items that allow me to trigger some custom Python code to show some pipeline tools (Qt widgets). This would be the first step to integrating open-source pipeline Avalon completely into Cinema4D, status for that will be tracked in this Avalon issue.

    1. Say I wanted to add five menu items, each triggering its own tool. How would I do so? I believe I have to register a command and then add it to the menu item. But a quick search didn't bring me to a concrete example on how to do so. I found this topic but it still was unclear how to proceed and make a simple menu item with some custom commands.
    2. Would I need a unique plug-in ID for each single command I'll register? Or can this be done differently?

    A short to the point example could would be much appreciated.

    Thanks in advance! 🙂

    posted in Cinema 4D SDK •