Hey @everyone,
Thank you for reporting this bug. It is the known bug ITEM#431586 Object Manager Update Error on Object Insertion from Script
. The bug has been fixed, but the fix has not yet been shipped.
At least when I investigated the shipped code of 2023.2.1
, the code which fixes the issue, was not there. This might have been an integration error. I can however certainly confirm that the bug still does exist in 2023.2.1 (Build 2023.CL401745.844493561) Win
and that the code has not been shipped.
The issue will be fixed in an upcoming version of Cinema 4D. In the meantime, the workaround suggested by Maxime can be used. Find below the full bug report for clarity.
Cheers,
Ferdinand
Bug Report:
The Object Manager (OM) is not being updated in some cases when an object is being inserted from a Python script, resulting in the script to run, the object being part of the new scene graph, but the OM not showing this new state.
Something with the event chain seems to be going wrong here. The script does call EventAdd() but in the problem cases it is ignored, and other ways to force an event (as for example clicking into the interface somewhere), do not work either. Only adding an object manually will make Cinema 4D "snap out of it".
Tested in: S26.107, 2023.0.0, 2023.1.0 (all behave the same)
I have also included a GIF which showcases the problem, as it is a bit tricky to reproduce and explain.
Steps to reproduce:
1. Switch to the Script layout.
2. Copy and paste the attached script.
3. Run the script a couple of times -> Result A
4. Select all newly created null objects in the Object Manager and delete them.
5. Run the script again multiple times -> Result B
6. Change the last line in the script from "print (1)" to "print (12)"
7. Run the script again multiple times -> Result C
8. Manually insert an object from the tool bar into the document -> Result D
Result A:
a. A new null object appears in the OM
b. Prints "1" to the console
Result B:
a. A new null object does NOT appear in the OM
b. Prints "1" to the console
Result C:
a. A new null object does NOT appear in the OM
b. Prints "12" to the console
Result D:
a. All previously added objects now appear in the OM (all the nulls we added)
b. The object we added manually does appear in the OM
c. On all further script executions, Cinema will now behave correctly again (until we trigger the problem again).
There is also at least one alternative way the same behaviour can be induced:
1. Switch to the Script layout.
2. Copy and paste the attached script.
3. Run the script a couple of times -> Result A
4. Rename the variable "node" to "nodea".
5. Run the script again multiple times -> Result B
It his however less reliable in reproducing the problem, and one might have to change the code multiple times. But it is possible to trigger the problem by just changing variable names and without touching the scene graph as for example deleting all objects.
Code:
import c4d
doc: c4d.documents.BaseDocument # The active document.
def main() -> None:
node = c4d.BaseObject(c4d.Onull)
if not isinstance(node, c4d.BaseObject):
raise MemoryError()
doc.InsertObject(node)
c4d.EventAdd()
print (1)
if __name__ == '__main__':
main()