SOLVED Attach XPresso Graph to GUI via Python

User Information:
Cinema 4D Version: R19;
Platform: Windows ;
Language(s) : Python ;

Hello Everyone!

Its been a while I have not post anything. Well I have been getting an error on attaching a xpresso node graph to a gui manual
dialog. I don't know or understand why its not working but hope y'all can he me. 😞

        self.GroupBegin(self.ID_GRP, c4d.BFH_SCALEFIT, 1, 0, "")
        # Static UI Text
        self.AddStaticText(0, c4d.BFH_CENTER, 0, 15, "Node Editor", c4d.BORDER_WITH_TITLE_BOLD)
        # Get Active Document
        doc = c4d.documents.GetActiveDocument()
        if doc == None:
            return False
        # Search for the Object in the (Objects) List Manger Hierarchy Outliner Tab.
        getnodeobj = doc.SearchObject("node")
        if getnodeobj == None:
            return ValueError("Make sure the selected object.")       
        # Retrieves the Xpresso Tag
        graphtag = getnodeobj.GetTag(c4d.Texpresso)
        if graphtag is None:
            raise ValueError("Make sure the selected object get an Xpresso Tag.")        
            # Set Xpresso Tag Name
            graphtag[c4d.ID_BASELIST_NAME]="Custom Node Graph Editor"
            Retrieves the node master and retrieves the Root node (the Main XGroup) 
            that holds all others nodes and set name of (the Main XGroup)
            gvNodeMaster = graphtag.GetNodeMaster()
            if gvNodeMaster is None:
                raise RuntimeError("Failed to retrieves the Node Master.")
                nodegraph_root_group = gvNodeMaster.GetRoot()
                if nodegraph_root_group is None:
                    raise RuntimeError("Failed to retrieves the Root Node.")
                    # Set the Main XGroup Name            
                    nodegraph_root_group[c4d.ID_BASELIST_NAME]="Tool Node Editor"
                # Add to UI
                self.AddUserArea(self.ID_NODE_VIEWPORT, c4d.BFH_CENTER, 350, 200)
                self.AttachUserArea(gvNodeMaster, self.ID_NODE_VIEWPORT)

Error in Console:

But if there is another way of making a custom node graph editor via python , I would love to know. 😁
Any help would be very much appreciated.

cheers, Ashton

How the Xpresso Node UI is added to a GeDialog is shown here: gedialog_gadgets.cpp

However, since GvGetWorld() and related functions are not available in Python, I guess it is not possible to use the Xpresso UI in a Python based GeDialog.

best wishes,

@s_bach Hi s_bach Is there another way of making a custom node graph editor via python? Cause I dont know c++ , so any tip can be great.


you can implement a custom class based on GeUserArea. In such custom gadget, you can control everything: what is drawn, how it is drawn and how the user interaction works. The problem is that you have implement all of that yourself. So depending on the complexity of your desired solution, this can be a lot of work.

See this previous discussion: Node Graph

best wishes,

@s_bach Okay I look at that tread, So pyQt is out of the window sense it's not good to use or wont work the right way and maxon is not going to add it or support it and don't do it for a commercial plugin, The only way is using c4d.gui.GeUserArea (GeUserArea) like Octane Node Graph and cmNodes. It will just be alot of work, when doing this with GeUserArea. I just want make sure I'm understanding everything correctly?

Yes, using GeUserArea is a way of creating a custom node editor (or any kind of custom UI).

@s_bach Okay I will give it a try , and I will do a open source example project for anyone, who would love to do this with python only for Cinema 4D. lol I been making different types c4d python plugins for 3 years now, from 2015 for my studio I work for and I love making c4d plugins. But this will be my first time using GeUserArea Class to the fullest lol.🤣

A little update on the node editor via Python 😉 small demo: Node Graph Editor via C4D Python API Video
I will share with the c4d py devs community when I'am done with this beast of a script.

That is so cool , Is it finish yet? I am new to GeUserArea too , That's a dreamly example to learn GeUserArea.