Group Details Private

Global Moderators

Forum wide moderators

  • RE: Automatically execute python scripte

    Hi @serco, there is multiple way to execute a script automatically when Cinema 4D is opened.

    1. Use python_init.py, this force you to add your script into the temp folder. Bu it can be done for a particular instance of a Cinema 4D or it can also be applied to all Cinema 4D versions that use a given python version.
    2. Implement a Plugin and react to PluginMessage various event are sent to Python, and you can hook into them to execute your code. This require to have a Python plugin loaded by Cinema 4D.
    3. Depending of your needs there is c4dpy which act as a Python Interpreter, where you can pass directly your Python file as an argument. Then again depending of your need you may be able to start what you want to do next.

    Cheers,
    Maxime.

    posted in Cinema 4D SDK
  • RE: Get command information from command palette

    Hi I've forwarded to the responsible developers, since it's Christmas and new year period, it may take some time until I come back to this topic (most likely only next week).

    Cheers,
    Maxime.

    posted in Cinema 4D SDK
  • RE: SetJointResetState() Parameter interpretation error in py doc?

    Thanks a lot for reporting this kind of issue !
    This is going to be fixed in the next update of the doc.

    Cheers,
    Maxime.

    posted in Cinema 4D SDK
  • RE: Making changes to the document through a websocket

    Hi please open new topic for any new question that is not directly related to your initial question.

    If I understand correctly you want to toggle the Coordinate state, if that's the correct you can either use CallCommand(12156) # Coordinate System. You can find this number by opening the Script Log and if you click on the Coordinate System it will give you the Id. However CallCommand have the issue that it automatically add an Undo step, which can be an issue in some case.

    So the proper way would be to call:

    bool enableWorld = true;
    doc->SetParameter(CreateDescID(DOCUMENT_STATEW), enableWorld , DESCFLAGS_SET::NONE);
    

    How I found this, looking at the code internally, sadly it is no documented anywhere...
    If you have any other questions related to this topic, reply to this topic and I will move it to a new topic.

    Cheers,
    Maxime.

    posted in Cinema 4D SDK
  • RE: Gear Settings Icon Workflow

    Hi @BretBays Happy Christmas ! Thanks for getting back, and indeed PLUGINFLAG_COMMAND_OPTION_DIALOG is the way to go. Find an example in CommandData with Options Dialog - Docked command button

    Cheers,
    Maxime.

    posted in Cinema 4D SDK
  • RE: Making changes to the document through a websocket

    Hi using MessageData is correct, however the best way is to call ExecuteOnMainThread as you can see in the websocket example I share with you here.

    This lambda will be executed on main thread, therefor it will be safe to create object and perform undo from it. One note make sure to pass a copy of the data to your lambda, since this lambda will be executed when the main thread is free and you do not know exactly when it can happen. And it can be latter than your OnMessage function, so with a copy you are sure that object are not nullptr.

    Cheers,
    Maxime.

    posted in Cinema 4D SDK
  • RE: SetJointResetState() Parameter interpretation error in py doc?

    Hi the C++ one is the most up to date version, thanks for pointing it.

    The Python doc will be updated.
    Cheers,
    Maxime.

    posted in Cinema 4D SDK
  • RE: WebSocket usage in C++

    Hi I do not have access to PostMan so it's hard to reproduce. Would be nice if you can provide a Python/C++/Javascript code that act as a client. So take my answers with a grain of salt.
    In my example I used a VsCode plugin (so a NodeJS instance), you can have a look at the client implementation
    Cinema-4D-Visual-Studio-Code-Extension
    .

    With that's said looking at the error I would say your request header should contain the protocol in the Sec-WebSocket-Protocol fields which should match the one you defined in mWebSocketServer.StartWebServer(addr, false, "<tried different values here but no change>"_s) iferr_return;.
    While Sec-WebSocket-Protocol is normally not a mandatory field, in our implementation it is mandatory to provide one.

    Cheers,
    Maxime.

    posted in Cinema 4D SDK
  • RE: WebSocket usage in C++

    Hi @Cankar001 we do not really have any official example for the Websocket, but fortunately I did make the Visual Studio Code Bridge project, which have the duty to exchange code from VSCode to Cinema via Websocket, and it's open source. So it is not nicely documented and explained as an example could be but it can serve you as a base.
    So find this example in Cinema-4D-Legacy-Visual-Studio-Code-Bridge-Plugin and look at the websocket_json_codeexchange.h and cpp.

    The main entry point is in WebSocketJsonCodeExchangeImpl::Start where all the observable are properly feed.

    Three special notes:

    • The code was written for S26 and is now directly merged into Cinema 4D, so it is not up to date, so for the observable the new way is to call it like that:
    g_wsServer.ObservableHandshake(true).AddObserver(OnHandShake) iferr_return;
    g_wsServer.ObservableConnected(true).AddObserver(OnConnected) iferr_return;
    g_wsServer.ObservableDisconnected(true).AddObserver(OnDisconnected) iferr_return;
    g_wsServer.ObservableMessage(true).AddObserver(OnMessage) iferr_return;
    
    • ObservableHandshake observable always need to be defined otherwise you won't be able to connect. Even if it's empty (like mine in OnHandShake).
    • You need to close all connections before calling StopWebServer otherwise it will wait forever. This means you needs to keep tracks of all theses connections somehow. In my case I do it by storing connections in a BaseArray during the OnConnect within the WebSocketJsonCodeExchangeImpl which is as a Singleton (so only one instance of it exist).

    Regarding your question it does not compile because you are calling it wrongly if I may say. First you pass a nullptr argument at the end that is not needed and secondly you do not handle the error that AddObserver emit which is probably the cause of the non-compilation. I would advice you to read Maxon API - Error Handling. With that's said here the adapted version that compile:

    g_wsServer.ObservableConnected(true).AddObserver(
    	[](const maxon::NetworkWebSocketConnectionRef& webSocket, const maxon::DataDictionary& request) -> maxon::Result<void>
    	{
    		iferr_scope;
    		return maxon::OK;
    	}) iferr_return;
    

    If you need more help and there is detail you have hard time to understand in the code example do not hesitate to ask questions.
    Cheers,
    Maxime.

    posted in Cinema 4D SDK
  • RE: Center Axis with Python

    Hi @Kantronin,

    Instead of creating multiple consequent postings please consolidate them in a single one. I've also noticed that you've added "programming" tag but haven't mentioned the language you're talking about (is it c++ or python?).

    Regarding your questions. Transforming the axis of a PointObject effectively means transforming the point values. There're some helping commands that I've shown you in my previous message, but what they effectively do is just transforming the points. Please have a look into the operation_transfer_axis_s26.py example, which demonstrates how to perform axis translation.

    As for the rotation part, I'd need to point you once again to our Matrix Manual, which actually contains the answer to your question. Namely, the chapter "Constructing and Combining Transforms" explains the usage of functions c4d.utils.MatrixRotX(), c4d.utils.MatrixRotY() and c4d.utils.MatrixRotZ(). I will not copy & paste the same code snippet from our manual, so please check it youself.

    Combining these with the example above should do the trick for you, unless you don't have the initial transformation of your ring splines. If that's the case, then your task turns into a way more complex form of the optimization problem.

    Please also note, that you can only do the object axis transformations on PointObject (and on PolygonObject since it's inherited from PointObject). This effectively means that if you're using the Osplinecircle instead of an ordinary Ospline, this wouldn't work, as it doesn't store any points inside. In this case you'd need to convert to Ospline. If that's not an option for you, you can check the Geometry Axis and Geometry Orientation scene nodes, as they allow you to transform the axis "on-the-fly", so this would work even with non-point objects.

    Cheers,
    Ilia

    posted in General Talk