administrators

Private

Posts

  • RE: C++ SDK 2026.4 — Supported ordered mouse movement input for keyboard-initiated modal transforms

    Hey @hey2495,

    okay, this changes things a bit. I also overlooked the SetCursorPos in your first posting, I do not know what you are exactly doing, but setting the cursor position is a bit unusual for a plugin.

    When you say "G/R/S transform" I assume you are trying to implement some kind of move/scale/rotate gizmo for your tool plugin? And the main issue you currently have is that when you set the cursor, that you read (from your perspective) incorrect input information?

    1. As you said it yourself, I would try to switch to input states here rather than events. You gave the special condition that your events are without any button being pressed which is rather unusual for Cinema event polling. I would have to check myself having no pressed button impacts mouse pos polling.
    2. I would for sure use here the global input polling (cinema::GetInputState and not the specialization attached to viewports or dialogs. You talk about screen borders and using there a filtered version of the input stream (even when you viewport or dialog seemingly fills the whole screen) does not seem like a good idea.
    3. There is EVMSG_ASYNCEDITORMOVE, a core message that is sent when the user moves something in the editor window. Our Cappucino mouse movement recorder tool uses this.

    Is there a supported Cinema 4D C++ SDK input callback or API that can supply mouse movement during a keyboard-initiated, button-free modal interaction with documented semantics that distinguish real user motion from SetCursorPos()-related repositioning or delayed events?

    Our input handling is probably about thirty years old (with improvements made along the way). The rigid modern day system boundaries you are asking for (does this and that under these conditions) do not exist. This was written in a time when devs thought using more than one character for a variable name is something offensive 😄

    When you implement a tool (be it ToolData or ToolDescriptionData), you should use its mouse and keyboard functions to track inputs. Using a scene hook (which would also have dedicated polling functions) and on top manual polling also seems not necessary (but I only have a very superficial view on your project).

    When you are still stuck, I would recommend sharing a brief executable/compile-able code snippet, so that I can better understand what is going wrong for you. And with executable I mean for example a minimal SceneHook impl that shows your problem. There are so many things that could go wrong for such a delicate issue as yours. But my key idea would be that you might operate on stale data when polling for events instead of states.

    we want to avoid taking ownership of Cinema 4D's window event loop.

    This could mean a lot, but a plugin which does runtime monkey patching is not allowed. Maybe I am misunderstanding you here, but at face value, 'taking ownership of Cinema 4D's window event loop' is absolutely off limits and we will ban any plugin ID and their owners who would attempt to do such openly malicious actions.

    Cheers,
    Ferdinand

  • RE: Can a plugin use the native Node Editor for its own graph?

    You can implement your own material node spaces, all of example.nodes in the C++ SDK is about this. Just compile the SDK and you will find a custom material node space in Cinema once you load the SDK. It also shows you how to implement nodes.

    Another alternative could be the old Xpresso system. You can also use HTML if you want but I would advise against reinventing the wheel and either pick Xpresso or the node editor.

    I thought you wanted to use the node editor to implement your own node subject, think of a node particle system, or a node system to create sound.

    Cheers,
    Ferdinand

  • RE: Can a plugin use the native Node Editor for its own graph?

    Hey,

    that menu is a different menu. I assume you are talking about this menu?

    eae8a6dd-f42a-434d-b36d-703fded72602-image.png.

    These are the node spaces and it is intended that you can add stuff there, the SDK shows you how to. The other menu is something different, there does not even exist a defined term for that. I would call it Node space groups, i.e. enclosing entities for a collection of node spaces of similar purpose. All render engine node spaces (Redshift, VRay, Arnold, etc.) are for example all material node nodespaces. The Nodes API currently defines two larger groups of node spaces. Scene nodes and material nodes; capsules are sort of an extension of scene nodes. And they come with certain conventions for the node editor. Which are hardcoded in the menu I showed you.

    You could technically setup shop in a material nodes space and just let your nodes do there what you want to be done, and implement a hacky end node. But that would be very hacky. Currently there is no way to implement such concept of a node space group as third party.

  • RE: VS Code -> Cinema 4D Connector -> Agent

    Hello @mogh,

    your question is a bit ambiguous. What is 'Connector Debug output' for you and what is exactly 'inside VSCode' for you, especially under the condition of 'limited access to the machine'?

    The connection between VSCode and Cinema 4D to exchange scripts and console output of Cinema 4D is proprietary. It is an websocket connection that runs on the port you define in Cinema (by default 7788), e.g., 127.0.0.1:7788. The payload is JSON but I would rather not publicly document its details, primarily because I do not want to give the impression that there is any guarantee that the protocol is meant to be a stable API third parties can hook into. But since this is a VSCode extension, you can of course just look at the source to understand the details, or ask an agent to do it for you.

    When you mean with debug output the actual debugger, then we are using the Microsoft library debugpy. We use port 5678 but you could also use any other port because your app is the server, not the consumer. I.e., the debug IP could be 127.0.0.1:5678. The old (2026.3) docs contained a section that showed how to manually attach from your code to a debugpy client, e.g. VS Code. But I have removed this section in the 2027 Debugging Manual because the debugger is currently not properly working under MacOS and I did not find the time to fix that for 202.0.0 (but I will fix it within 2027.X.X).

    Note that the debugger connection is made from your code; your code is the server, VSCode is the client. debugpy is a proprietary Microsoft library and the only meaningful enterprise debugger for Python at the moment. There is the builtin pdb library which you can use but it IMHO has its limits. There are also some smaller third party alternatives, but they are all inconsequential and I do not know if they work with Cinema 4D. debugpy is using the open DAP protocol, so it is not impossible to create your own consumer, but it is probably also not trivial (I am mentioning this because your message somewhat implies that you want to sidestep the VS Code debugger interface).

    Cheers,
    Ferdinand

  • RE: Deadlock: TakeData.SetCurrentTake() from Python holds the GIL

    @nik684 said in Deadlock: TakeData.SetCurrentTake() from Python holds the GIL:

    Also worth to note:
    We hit the same freeze in BaseDocument.AddUndo() and maxon.GraphTransaction.Commit() on the main thread while a Python tag was drawing.
    py-spy showed the same pattern: the main thread holds the GIL and waits, and the draw/ca thread sits in PyGILState_Ensure.
    Could those wrappers be missing the GIL release too?

    Undo maybe be related to Take switch though.

    AddUndo just as some other Undo methods does not release the GIL, I just checked. But other than for the take system, this could be intentional here, due to adding an undo could imply changes to PyObject instances (which are not allowed while you drop the GIL).

    For maxon.GraphTransaction.Commit() I would have to check, things work entirely different there, the Maxon API is not implemented in a traditional way, things work much differently there. I would need code and a context for the latter. For the former I probably need a good night sleep to think about it and a reason where this would be relevant.

    Cheers,
    Ferdinand

  • RE: Deadlock: TakeData.SetCurrentTake() from Python holds the GIL

    You picked a terrible spot to start your Cinema journey, the take system while beloved by users, is both complicated and not performance-wise not great when it comes to the API 😄

    That is why I added my "It can entail a lot of data copying and scene traversal to bring the current scene into its new state" warning above. The take system entails a lot of copying of data containers or at least parts of them. The data itself is probably only a small portion of the spike you see, what makes this then really expensive, is the fact that when you make half your scene dirty by applying new parameters to it, you also have to rebuild half your scene from scratch which eats a lot of memory.

    But I cannot really do anything about this, as this is not my domain, I do not own the take system, just the Python bindings to it. When you consider the take system too slow, I would encourage you to make a user report in our Support Center. This is also probably not something you fix in five minutes.

    Cheers,
    Ferdinand

  • RE: Deadlock: TakeData.SetCurrentTake() from Python holds the GIL

    Okay, this did fix it. I made a merge request. It will not be included in the next release (which will arrive very soon). I hope to get it into the 2027 Q1 release (which is also already on the finish line), otherwise it will come with Q2. I also fixed some other methods in take take system, as quite a few were missing proper GIL handling.

  • RE: Deadlock: TakeData.SetCurrentTake() from Python holds the GIL

    Hello @nik684,

    Welcome to the Maxon developers forum and its community, it is great to have you with us!

    Getting Started

    Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.

    • Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
    • Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
    • Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.

    It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: How to Ask Questions.

    About your First Question

    This has to be one of the most thorough bug reports I have ever seen. Well done! Maybe tell your agent next time to make it a bit shorter, I have a not too long attention span 😄

    Could the Python wrappers of TakeData.SetCurrentTake() release the GIL while the native call runs ?

    You were right, CPyTakeData::SetCurrentTake was missing the GIL release and acquire around its takeData->SetCurrentTake(take) call as it is customary for methods that write something. I have just pushed a build to the build server which changes that. I will then try to run your script there once I have that build. And even when the fix does not resolve your issue, I will submit it anyway, as the GIL should be released by convention around that call I would say.

    Is there a supported way for a Python plugin to block or pause viewport redraws for the duration of a set of scene changes?

    No, there is unfortunately not. You are in a more or less curated threading environment in Python. The Python VM calls your code at specific points in time and you are more or less at its mercy. There are c4d.StopAllThreads and c4d.threading.GeThreadLock but using them is rarely a good idea. And some drawing threads might even ignore them.

    Is calling TakeData.SetCurrentTake() from a GeDialog.Timer() or a GeUserArea mouse handler supported, or should it be deferred to some other context?

    That is indeed the main question. You can look at the all new Scene Excecution manual which I wrote for 2027 to get a better understanding of this. In short, changing the active take of a loaded scene is a scene modification and therefore must be main thread bound. Timer and Mouse/Keyboard IO functions usually run on the MT, but I would add an explicit check to such functions just to me sure. So, on paper, this is fine.

    Where I can see a bit an issue is with your INTERVAL_MS in the demo script you gave us, it is set to 50ms. Quoting the warning I once added to GetTimer:

    "Depending on the speed of the computer, the operating system, the complexity of the dialog and the threads running in the background, there is no guarantee that event messages will occur on a regular basis. Using a value of 500 ms should be no problem but if using a value of 1 ms one might get events with the following time spaces: 3 ms, 76 ms, 15 ms, 19 ms, 67 ms…"

    With 50ms you are dangerously close to saturating the event system. Although it might not look like it, SetCurrentTake is a VERY expensive call. Doing this every 50ms with all Python shenanigans in between is not great. You would be better served with a value such as 100 or even 250ms.

    I am like 66% confident that the GIL release I added will fix your issue. But all that event and timer stuff could also throw a wrench into things. But I will cross that bridge once I have a build of my fix, and your code still freezes, as that is probably not fun to debug. You should take as a lesson here that writing takes is not cheap. It can entail a lot of data copying and scene traversal to bring the current scene into its new state.

    I will post here an update once I have a final answer.

    Cheers,
    Ferdinand

  • RE: Free script: convert Redshift scenes back to native C4D materials WITHOUT a Redshift license (R23)

    Hey @Marite,

    Welcome to the Maxon developers forum and its community, it is great to have you with us!

    Getting Started

    Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.

    • Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
    • Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
    • Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.

    It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: How to Ask Questions.

    About your First Posting

    Thank you for sharing your project! And please excuse the long wait time in the posting queue, I somehow managed to overlook your posting.

    Cheers,
    Ferdinand

  • RE: C++ SDK 2026.4 — Supported ordered mouse movement input for keyboard-initiated modal transforms

    Hey,

    please excuse the long delay. Please have a look at Support Procedures for future topics, we do not allow for multi-question topics, as they have a tendency to derail.

    Is there a supported way for a C++ plugin to continuously receive ordered mouse movement events during a keyboard-initiated modal operation, without any mouse button held down?

    Yes, there are multiple ways to do this. I cannot highlight each way in all details due to the broad nature of this question and topic. Some ways are:

    • Implement SceneHookData and implement ::MouseInput, ::KeyboardInput etc. Scene hooks are sort of spider in the net node types which exist always exactly once in each document. They are often used to do command and control tasks. Things like render regions or the simulation system in Cinema are all backed by scene hooks.
    • Implement a GeDialog, start a timer via GeDialog::SetTimer and on each tick, poll the current input state yourself via GetInputState (the current state) or GetInputEvent (the last enqueued input event, could lie in the past).
    • Implement a thread or job, and poll from there on each tick.

    Can EditorWindow::BfGetInputEvent() be used for this purpose?

    EditorWindow::BfGetInputEvent() just like GeDialog::GetInputEvent and similar methods is a specialization of the generic cinema::GetInputEvent. It is often better to use the global functions rather than the specific ones, unless one wants to filter out all events that do not go to a specific viewport or dialog. As hinted at above, you often also want to poll for the state and not for events, as they can be consumed (the user is still holding down "X" but something has already consumed this event) and temporally offset (the user is not pressing x anymore, but the event is still last in queue).

    Does calling BfGetInputEvent() remove events from the queue ...

    I would quite frankly have to check this, and this is probably not an easy "look it up in file foo.c on line 4555". Without checking, I would say that the InputEvent methods do not consume the events, as there is no way to signal back that you have consumed an event. The canonical way to consume events are plugin methods such as the scene hook methods discussed above, or similar methods of other plugin types. There you can then return true ore false to indicate if you want to consume an event or not.

    If BfGetInputEvent() is not suitable, which API or callback mechanism would Maxon recommend for this type of keyboard-initiated continuous viewport interaction? Are there specific thread, window ownership, or lifecycle restrictions?

    This is exactly why we disallow multi question topics 😄 I could write an essay alone on this because while this is a precise question it covers so much ground. In general, you should avoid polling the input state off main thread if you can. The input methods are not explicitly thread-unsafe but I would still avoid it. The reason is that the plugin type specific methods which are about inputs, such as SceneHookData::MouseInput, ObjectData::MoveHandle, or ToolData::KeyboardInput usually run on the MT. I would advise the against polling inputs in heavily parallelized methods such as SceneHookData::Execute, ObjectData::GetVirtualsObjects, TagData::Execute. While it might not provoke crashes, it is for sure not good for performance. Polling for the input in your own custom thread spawned from the MT is fine.

    But you usually do not have to use threading, there should be a plugin interface with input methods which fits your needs. And when the plugin interface you use does not have an input polling function, e.g., you implement a tag, it means that you should not poll for inputs there and use another plugin type or rethink your whole design. You could for sure make it technically work that a tag behaves differently depending on the key(s) the user presses, but from a Maxon point of view, this would be a rogue UX.

    Cheers,
    Ferdinand