• 0 Votes
    3 Posts
    700 Views
    ferdinandF
    Hello @RenoBozo, without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022. Thank you for your understanding, Ferdinand
  • Expresso show hidden objects

    macos project tool
    4
    1
    0 Votes
    4 Posts
    976 Views
    ferdinandF
    Hello @mauovernet, without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022. Thank you for your understanding, Ferdinand
  • Modifying Cinema 4D Preferences from External Python Script?

    r23 s24 r25 python sdk
    4
    0 Votes
    4 Posts
    1k Views
    ferdinandF
    Hello @wuzelwazel, without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022. Thank you for your understanding, Ferdinand
  • Detect new project in Python plugin

    python
    4
    0 Votes
    4 Posts
    631 Views
    ferdinandF
    Hello @mheberlein, without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022. Thank you for your understanding, Ferdinand
  • RS Reference Node in Python

    s24 python windows
    3
    0 Votes
    3 Posts
    519 Views
    ferdinandF
    Hello @kverhaar, without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022. Thank you for your understanding, Ferdinand
  • Get object by active tag in Python

    python
    5
    0 Votes
    5 Posts
    1k Views
    ferdinandF
    Hello @stanDM, without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022. Thank you for your understanding, Ferdinand
  • import presets and be reversible

    Moved r20 python
    6
    0 Votes
    6 Posts
    927 Views
    ferdinandF
    Hello @JH23, without any further questions or postings, we will consider this thread as solved by Friday the 4th, February 2022. Thank you for your understanding, Ferdinand
  • Exporting data from Takes to a file

    sdk r23 python
    8
    0 Votes
    8 Posts
    2k Views
    F
    Hi Manual, This is exactly what I needed. Thank you very much. Best regards, Tomasz
  • Unique Material per Object Plugin instance?

    r20 python macos
    4
    0 Votes
    4 Posts
    979 Views
    H
    Hi Guys, as I'm pretty sure I found a way to achieve what I'm after I thought I update this thread. Maybe this will help others as well. After taking some time to make NodeData.CopyTo() work, I ended up not getting it to work at all. So I thought about how I could achieve what I'm after a different way. Long story short, I ended up implementing a MessageData plugin as some kind of watchdog for a document. Since its CoreMessage runs on the main thread I can happily insert and delete materials as much as I wish to. (At least I'm hoping so ) Tl; dr The idea behind this goes as follows. I have a timer running and in addition to that I listen for c4d.EVMSG_CHANGE and do some checking to see if the scene needs to update. In my case it's comparing the amount of a specific object against the amount of "specific" materials. If there's a difference I use that difference to delete or insert materials until there's no difference. Once there's no difference I can assign the materials to the objects and let each object control its own material. To distinguish between materials responsible for my plugin and the ones that aren't I make sure to put a unique plugin id inside the base container of the material I can then check for. Here's a code snippet of that MessageData: class Watchdog(c4d.plugins.MessageData): PLUGIN_ID = "Use your own unique one" PLUGIN_NAME = "A MessageData plugin." PLUGIN_INFO = 0 def __init__(self): self._time = 1000 def GetTimer(self): return self._time def SetTimer(self, time): self._time = time @property def should_execute(self): is_mainthread = c4d.threading.GeIsMainThread() check_running = ( bool(c4d.CheckIsRunning(c4d.CHECKISRUNNING_EDITORRENDERING)), bool(c4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING)), bool(c4d.CheckIsRunning(c4d.CHECKISRUNNING_INTERACTIVERENDERING)), bool(c4d.CheckIsRunning(c4d.CHECKISRUNNING_ANIMATIONRUNNING)), bool(c4d.CheckIsRunning(c4d.CHECKISRUNNING_VIEWDRAWING)) ) is_running = any(item is True for item in check_running) return is_mainthread and not is_running def CoreMessage(self, mid, mdata): if not self.should_execute: return False doc = c4d.documents.GetActiveDocument() # SceneHandler is a custom class I delegate the whole creation and comparing stuff to. objs, mats = ..., ... scene = SceneHandler(objs, mats) # Check for a change and start the timer again. But only if the scene should update. Otherwise the timer would run all the time. if mid == c4d.EVMSG_CHANGE: if scene.should_update: self.SetTimer(1000) # If we get a timer event we update the scene as long as it shouldn't update anymore. We can then stop the timer. if mid == c4d.MSG_TIMER: if not scene.should_update: self.SetTimer(0) scene.update(doc) return True Maybe this will help others. Since I found a solution for my problem this thread can be marked solved. Cheers, Sebastian
  • 0 Votes
    3 Posts
    746 Views
    D
    @m_magalhaes said in Copying Take Overrides from an object to another via Python not working properly: adding the backupvalue You are master! thanks my friend, it's working!
  • Info GetUserDataContainer and RemoveUserData switched

    sdk
    2
    1
    1 Votes
    2 Posts
    387 Views
    M
    Thanks, this is going to be fixed in the next documentation release. Cheers, Maxime.
  • Draw Icon (maxon id) into treeview list geUserArea()

    r25 python
    3
    1
    0 Votes
    3 Posts
    659 Views
    M
    Thanks, @m_magalhaes yes my code is inside the drawcell() method. I didn' have any luck with c4d.gui.GetIcon(lIconID) but i got c4d.bitmaps.InitResourceBitmap(resource_id) working. here are my 3 lines of code that got me an icon. ICON_SIZE = drawinfo["height"] bmp = c4d.bitmaps.InitResourceBitmap(12098) geUserArea.DrawBitmap(bmp, drawinfo["xpos"], drawinfo["ypos"], ICON_SIZE, ICON_SIZE, 0, 0, bmp.GetBw(), bmp.GetBh(), c4d.BMP_ALLOWALPHA) kind regards mogh
  • Python Generator and texte

    python r25
    3
    2
    0 Votes
    3 Posts
    501 Views
    B
    Hello, Thanks a lot for your help !
  • Compare Matrices Matrix with matrix.__eq__

    r25 python
    3
    0 Votes
    3 Posts
    752 Views
    M
    I was suspecting something like this ... Thanks for taking the time to type a solution which I could copy ...
  • How to track user changes to parameter animation

    r21 c++
    5
    1
    0 Votes
    5 Posts
    972 Views
    ManuelM
    hi, There is no really way of doing it. The only way is to keep track of what is going on. the number of keys, the position, values etc. When setDparameter is called you need to compare and update your data. You could just store the dirty state or a lot more information. Keep in mind that you can have mutiple tracks for the position. This is tricky and long to do but possible. Cheers, Manuel
  • Table With TreeViewCustomGui with no Tree Icon

    r21 python
    3
    1
    0 Votes
    3 Posts
    803 Views
    mikeudinM
    @mogh Thank you very much!
  • How to activate the recent Saved Document

    python r25
    3
    0 Votes
    3 Posts
    540 Views
    M
    No stupid me, overlocked this ... thanks for the hint Frank.
  • Set "Strength" on Constraint tag via Python Xpresso Node?

    2
    0 Votes
    2 Posts
    425 Views
    J
    Ok, nevermind... I got something working about 3 minutes after posting this question. I'll paste below what worked for my needs. Maybe this will help someone else, or maybe you all have a more direct method to achieve this. def main(): #inputs to the Xpresso Node are Link (named "LayerLink") and Float (named "FieldtInfluence") myObject = LayerLink myTag = myObject.GetTag(1019364) myTag.SetParameter(c4d.ID_CA_CONSTRAINT_TAG_AIM_TWEIGHT, FieldInfluence, c4d.DESCFLAGS_SET_0)
  • Getting material 'use' flag

    sdk c++
    3
    0 Votes
    3 Posts
    528 Views
    WickedPW
    Thanks Frank, @fwilleke80 said in Getting material 'use' flag: BaseMaterial* const materialPtr = textureTagPtr->GetMaterial(); Yep, that's what I was missing. I was thinking the texture tag was the material, but it wasn't and I needed to get the link to the material from the texture tag. Cheers, WP.
  • How do I get GvNodeMaster stored in Redshift material

    r21 c++
    4
    0 Votes
    4 Posts
    1k Views
    ferdinandF
    Hello @aimidi, please excuse, I overlooked the C++ tag you did assign to your posting. R21, the version you tagged this posting as, is also out of scope of support. The code examples I provided below have been written for R25. There were substantial changes to the C++ Python API with R23, you might not be able to translate that example to R21. The branch info approach should work in R21. The short answer is, "no, there is no C++ API for Redshift at the moment". You can however use the Python API from C++ or use BranchInfo to access the Xpresso nodes attached to a Redshift material. The Python approach has the advantage that you can make use of the whole Python Redshift API, but the disadvantage that it is a bit involved. The branch info approach is easier, but it will only solve your problem at hand, getting the underlying graph, and will not give you access to the other functionalities of the Redshift Python API (there are not many other features in the Python API). Find below an example demonstrating both approaches. Cheers, Ferdinand The result: [image: 1642078861503-redshiftcpp.gif] The code: // For https://developers.maxon.net/forum/topic/13752 #include "c4d_basedocument.h" #include "c4d_basematerial.h" #include "c4d_general.h" #include "c4d_graphview.h" #include "lib_py.h" #include "maxon/cpython.h" #include "maxon/cpython_c4d.h" #include "maxon/cpython3_raw.h" #include "maxon/errortypes.h" #include "maxon/vm.h" // The type id of Redshift materials. const maxon::Int32 g_redshift_material_id = 1036224; /// Attempts to retrieve the Redshift GvNodeMaster of #material with Python. /// /// @param material The material to get the Redshift GvNodeMaster for. /// @param pythonCode The Python code that is used to retrieve it. /// @return The Redshift GvNodeMaster for #material. /// ------------------------------------------------------------------------------------------------ static maxon::Result<GvNodeMaster*> CallRedshiftPythonLayer( BaseMaterial* material, const maxon::String& pythonCode) { iferr_scope; // Bail when #material is null or not a Redshift material. if (!material || (material->GetType() != g_redshift_material_id)) return maxon::IllegalArgumentError( MAXON_SOURCE_LOCATION, "Passed material is not a Redshift material."_s); // Initialize a scope with the Python 3 virtual machine for #pythonCode. const maxon::VirtualMachineRef& vm = MAXON_CPYTHON3VM(); const maxon::VirtualMachineScopeRef scope = vm.CreateScope() iferr_return; scope.Init("Python"_s, pythonCode, maxon::ERRORHANDLING::PRINT, nullptr) iferr_return; // We could setup here the modules attributes doc and op that are commonly used in Cinema 4D // Python scripts by adding them to the scope. But that is not really necessary in the example // since we just call one function which does not require any module attributes. // Set the __name__ attribute of the module so that the execution context guard ifnamemain works. // Also not necessary in a technical sense, since we do not make use of it. scope.Add("__name__"_s, maxon::Data("__main__"_s)) iferr_return; // When the script does modify the active document, you must stop all threads before executing it. // Here not necessary, since the example code does not modify anything. StopAllThreads(); // Execute the module context of the script, i.e., carry out imports and module level expressions, // as for example an ifnamemain execution guard. scope.Execute() iferr_return; // Now we are going to call the specific function GetNodeMaster() in the script. // Make the passed material accessible as an argument for the python function GetNodeMaster() // by casting it into its binding type that handles the C++/Python type binding. maxon::specialtype::BaseMaterial* materialSpeical = ( reinterpret_cast<maxon::specialtype::BaseMaterial*>(material)); // Create a data structure for the arguments of GetNodeMaster(), containing the material binding. maxon::Data materialArgument = maxon::Data(materialSpeical); maxon::BaseArray<maxon::Data*> arguments; arguments.Append(&materialArgument) iferr_return; // Setup the return type. We are using here BaseList2D for the return type, or more specifically // its special binding type, since there is no dedicated binding type for GvNodeMaster. But // GvNodeMaster is of type BaseList2D and we will later attempt to cast the return value back to // GvNodeMaster. maxon::BlockArray<maxon::Data> helperStack; const maxon::DataType& returnType = maxon::GetDataType<maxon::specialtype::BaseList2D*>(); // Call GetNodeMaster() in the scope and interpret its return value(s). maxon::Data* res = scope.PrivateInvoke( "GetNodeMaster"_s, helperStack, returnType, &arguments.ToBlock()) iferr_return; // The function execution did fail. if (!res) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Function execution did fail."_s); // The function in Python does not conform to the expected return type of BaseList2D. maxon::specialtype::BaseList2D* returnValue = res->Get<maxon::specialtype::BaseList2D*>().GetValue(); if (returnValue == nullptr) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION, "Function does not conform to its return value signature."_s); // The C++/Python binding type return value cast back into its native C++ form. BaseList2D* result = reinterpret_cast<BaseList2D*>(returnValue); // Finally cast it into what we are after, a GvNodeMaster. GvNodeMaster* nodeMaster = static_cast<GvNodeMaster*>(result); return nodeMaster; } /// Attempts to retrieve the Redshift node graph of #material with branching information. /// /// An alternative and less complex solution than CallRedshiftPythonLayer() which uses branch info /// to get hold of the graph. This is easier but other than with the Python approach it will give /// you not access to all the things the Redshift Python API can do. /// /// @param material The material to get the Redshift graph for. /// @return The Redshift graph for #material. /// ------------------------------------------------------------------------------------------------ maxon::Result<GvNode*> GetRedshiftNodeBranch(BaseMaterial* material) { iferr_scope; // Bail when #material is null or not a Redshift material. if (!material || (material->GetType() != g_redshift_material_id)) return maxon::IllegalArgumentError( MAXON_SOURCE_LOCATION, "Passed material is not a Redshift material."_s); // Setup an array for all branches of #material. Usually nodes do not have more than ten // branches, e.g., a BaseObject might have a tags and tracks branch, and one or two internally // used branches. So, setting maxBranchCount to 64 is very generous. const maxon::Int32 maxBranchCount = 64; BranchInfo branches[maxBranchCount]; // Get all branches for #material. maxon::Int32 count = material->GetBranchInfo(branches, maxBranchCount, GETBRANCHINFO::NONE); // Search for a "Node" branch, which is the branch containing the Redshift graph. BranchInfo* nodeBranch = nullptr; for (maxon::Int32 i = 0; i < count; i++) { if (branches[i].name.Compare("Node"_s) == maxon::COMPARERESULT::EQUAL) { nodeBranch = &branches[i]; } } if (!nodeBranch) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION, "The passed material does not contain a Redshift 'Node' branch."_s); GeListHead* head = nodeBranch->head; if ((!head) || (!head->GetFirst())) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Malformed or empty branch info."_s); // Get the first node in the list head, this is equivalent to nodeMaster->GetRoot(). We cannot // access the node master itself with this approach, but all the nodes in it. GvNode* node = static_cast<GvNode*>(head->GetFirst()); return node; } /// Prints #node and all its descendants as a tree to the console. /// /// @param node The graph node to print. /// @param level (optional) The indentation level. /// ------------------------------------------------------------------------------------------------ static void PrintNodes(GvNode* node, const maxon::Int level = 0) { if (!node) return; maxon::String indentation = ""_s; for (maxon::Int i = 0; i < level; i++) indentation += "\t"_s; while (node) { maxon::Int location = reinterpret_cast<maxon::Int>(node); ApplicationOutput("@ @ at 0x@{x}", indentation, node->GetTitle(), location); PrintNodes(node->GetDown(), level + 1); node = node->GetNext(); } } /// Runs the two examples. static maxon::Result<void> pc13752(BaseDocument* doc) { iferr_scope_handler { ApplicationOutput("@: @", err.GetClass().GetId(), err.GetMessage()); return err; }; // The Python code we are going to run with CallRedshiftPythonLayer. const maxon::String pythonCode = ( "import c4d\n"_s + "import redshift\n\n"_s + "def GetNodeMaster(\n"_s + " material: c4d.BaseMaterial) -> c4d.modules.graphview.GvNodeMaster:\n"_s + " '''Attempts to return the Redshift GvNodeMaster for #material.\n"_s + " '''\n"_s + " if material.GetType() != redshift.Mrsmaterial:\n"_s + " raise ArgumentError(f'Unexpected type with {material = }.')\n\n"_s + " master = redshift.GetRSMaterialNodeMaster(material)\n"_s + " if master is None:\n\n"_s + " raise RuntimeError(f'Could not access node master for {material}.')\n\n"_s + " return master\n\n\n"_s); // Get the active material for which we will attempt to get the RS node master for. BaseMaterial* activeMaterial = doc->GetActiveMaterial(); if (!activeMaterial) return maxon::IllegalStateError(MAXON_SOURCE_LOCATION, "No material selected"_s); // Run the example using Python to get hold of the nodes in the material. ApplicationOutput("\nAccess with Python layer:"); GvNodeMaster* nodeMaster = CallRedshiftPythonLayer(activeMaterial, pythonCode) iferr_return; if (!nodeMaster) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "CallRedshiftPythonLayer() failed."_s); PrintNodes(nodeMaster->GetRoot()); // Run the example using branching information to get hold of the nodes in the material. ApplicationOutput("\nAccess with branching information:"); GvNode* nodeRoot = GetRedshiftNodeBranch(activeMaterial) iferr_return; if (!nodeRoot) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "GetRedshiftNodeBranch() failed."_s); PrintNodes(nodeRoot); return maxon::OK; }