Jump to content

Python Rig Assembly Wizard (Import Type)


Recommended Posts

Hey C4DCafe!

 

I just started to work on an Import-Type Rig Assembly Wizard, which extracts relevant rig parts from my rig's preset folder to the object manager (since my rig was built as individual pieces and being linked by Python nodes)

I have some problems in terms of getting the AddUndo work with MergeDocument. Here's my code:

 

import c4d
#Welcome to the world of Python


def main():
    global Output1
    
    if Input1 != None and Input2 == 1:
      	doc.AddUndo(c4d.UNDOTYPE_CHANGE,doc,True)
        c4d.documents.MergeDocument(doc,Input1,c4d.SCENEFILTER_MERGESCENE|c4d.SCENEFILTER_OBJECTS|c4d.SCENEFILTER_MATERIALS)
        c4d.EventAdd()
        Output1 = None #Ground Output
    Output1 = None #Ground Output

As you can see, there was "Ground Output" comments. My code was situated in a Python node on the following screenshot:
image.png.0f49faa6bd0f7dc954ccf2e87cff1d13.png

The issue are the following:

- When using c4d.UNDOTYPE_CHANGE, the object that have been added using the Run switch (It was a boolean attached to a Float(Real) port), the added object just swaps place with the Null, giving the Null the way to get back as the first object (when the null was at the top of the root heirarchy, and the added object stays as the first item in the object manager when the Null was on 2nd/3rd/etc. because of other objectc above it.
- When using c4d.UNDOTYPE_NEW, c4d suddenly freezes and just turns my cursor into loading mode. I then need to force close it via Task Manager, and when I open c4d, the bug report window pops up, even if it wasn't a bugreport crash and also did not generate any bugreport file.
 

Other than the two Undo Types, I haven't tested anything that was actually can change data like adding an object from my preset folder, and when Undo was done, the object being added will be deleted.

I was aware of the doc.StartUndo() and doc.EndUndo() usage, but I also tried that, but same results.

I hope you guys can help me with this particular problem.

Link to post

I'm sorry to be so direct. But this is plain wrong. You are really risking the stability of C4D.

You can not use AddUndo() outside of Start/EndUndo(). And you shouldn't use AddUndo() inside of an Xpresso Python node. In fact you shouldn't make any scene changes from inside the Xpresso Python node. Period.
And yes, I saw, that you try to limit the execution of the node with some "run" flag. But this doesn't change anything of what I said before.

Without knowing more details I'd say, you should implement a Script (Menu Extensions -> Script Manager or in previous versions Menu Script -> Script Manager) or a CommandData plugin.

Cheers

Link to post
39 minutes ago, MighT said:

I'm sorry to be so direct. But this is plain wrong. You are really risking the stability of C4D.

You can not use AddUndo() outside of Start/EndUndo(). And you shouldn't use AddUndo() inside of an Xpresso Python node. In fact you shouldn't make any scene changes from inside the Xpresso Python node. Period.
And yes, I saw, that you try to limit the execution of the node with some "run" flag. But this doesn't change anything of what I said before.

Without knowing more details I'd say, you should implement a Script (Menu Extensions -> Script Manager or in previous versions Menu Script -> Script Manager) or a CommandData plugin.

Cheers

So far, modification of heirarchy was successful, also the swapping of objects using a python node. It's just the thing that MergeDocuments doesn't have a way to be undone using an AddUndo command

I also tried placing the AddUndo between a StartUndo and EndUndo scope

Also, if you mean by limiting the run is the Ground Outputs, that's because the node itself won't make changes with the scene file, so I need to make a ground connection that goes into an unused/useless Link-type input.

Or if you mean by that one was the boolean switch, I also do it mostly on some switches like auto-updating filename field for textures on rigs and stuff.

I can really scrap up the Undo feature by having the Import Wizard do it's thing then deletes itself once it imports all the objects and arranges it according to the correct heirarchy. I want to do this with an Undo feature so that when a user actually want to undo that import, it can be done. But since setting an Undo marking/event was kind of impossible on the Import Wizard, I'll do --Load Parts > Arrange > Delete Wizard-- flow.

That is because on my rig, there were:
- 1 Bone Version with 2 settings with Remote Control Feature
- 6 Mesh Types (3 per bone version)
- 2 Cape Objects, which is optional on the rig's binding

- Separate Facial Rig (You might also have guessed it already, it's a Minecraft Character Rig, but most parts running on Python scripts)

- Remote Facial Controls (just like the bones)

The actual goal was to create a wizard that can bind this without taking each part one-by-one and assemble it. I plan it to still be revertible using an Undo event, but it seems like it was less likely to be undone because of how AddUndo can't undo anything used with MergeDocument().

 

I already have done an Object Hierarchy Manager which orders the objects to be child of a chosen parent, and it can use the AddUndo() without any problem at all, so I think there was no stability issues at all.

Link to post

Please, believe me, what you are doing is wrong and will risk stability of C4D.
Just because you can get something to work somehow, it does not get correct.


I won't argue here, it is this simple.

 

You can believe me or continue with this route, but then you are on your own, at least from my side.

You can ask the moderators of this forum, why I feel entitled to be so definite in this case. Or you can ask in MAXON's Plugin Café to get more or less the same answer (I'd bet quite a few beers on this).

 

Link to post
17 hours ago, MighT said:

Please, believe me, what you are doing is wrong and will risk stability of C4D.
Just because you can get something to work somehow, it does not get correct.


I won't argue here, it is this simple.

 

You can believe me or continue with this route, but then you are on your own, at least from my side.

You can ask the moderators of this forum, why I feel entitled to be so definite in this case. Or you can ask in MAXON's Plugin Café to get more or less the same answer (I'd bet quite a few beers on this).

 

Might be lifting a fog, you can follow my question on MAXON's Plugin cafe here: https://plugincafe.MAXON.net/topic/12481/python-nodes-shouldn-t-really-they-can-change-the-scene

It seems like it really depends on the format on how you modify your scene. The sure thing is if it was ran via Execute method, it will affect the stability.

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...