• How do I get the status of redshift AOV mode?

    Cinema 4D SDK python
    2
    0 Votes
    2 Posts
    366 Views
    ManuelM
    Hi, Please mark your thread as a question using the forum tools. Redshift is a VideoPostData plugin. You cannot access the parameter directly in the renderdata. This is just a guess of what you are trying to do. Instead, you must find the VideoPostData that contain all Redshift parameters. from typing import Optional import c4d import redshift doc: c4d.documents.BaseDocument # The active document op: Optional[c4d.BaseObject] # The active object, None if unselected def main() -> None: renderdata = doc.GetActiveRenderData() vprs = redshift.FindAddVideoPost(renderdata, redshift.VPrsrenderer) if vprs is None: raise ValueError("Cannot find the redshift VideoPostData") print (vprs[c4d.REDSHIFT_RENDERER_AOV_GLOBAL_MODE]) if __name__ == '__main__': main() There is this thread where you will find a script to print all the AOVs Cheers, Manuel
  • 0 Votes
    3 Posts
    645 Views
    ferdinandF
    Hello @lingza, Thank you for reaching out to us. There are in principle two ways how you can do this: Do not use an InExcludeData and make the dependencies of your deformer direct children of the deformer. A deformer will automatically be invoked when either the direct parent or children are modified. This is IMHO a much simpler solution, but you are of course restricted in where you can put these dependencies in a scene, as they must be children of the deformer. When you want to go with InExcludeData, you must overwrite ObjectData.CheckDirty to manually flag the deformer as dirty when necessary. You iterate over all objects in the InExcludeData and based on their dirty count decide if the deformer is dirty or not. Find a draft for the method at the end of my posting. Cheers, Ferdinand The result: [image: 1662476641343-modifierdirty.gif] The code: def CheckDirty(self, op: c4d.BaseObject, doc: c4d.documents.BaseDocument) -> None: """Called by Cinema 4D to let a modifier flag itself as dirty. Args: op: The object representing the modifier hook. doc: The document containing the modifier. """ # When we want to track dependencies we must keep a cache for what we consider to be the # last no-dirty state of things. This could be done in many ways, I have chosen here a # dict of (bytes, int) tuples. # # The general idea is to store the last known dirty state data for each item in the # InExcludeData as such: # # { Object_A: 193, Object_B: 176, Object_C: 25, ...} # # But BaseList2d instances itself are not hashable, i.e., cannot be keys in a dict, and # doing something like `myDict[id(someObject)] = someValue` would be a really bad idea, # as objects are managed in the backend by Cinema 4D and can be reallocated all the time, # so id(myBaseList2d) is not a safe way to identify objects. Instead we are using # C4DAtom.FindUniqueID to get the unique MAXON_CREATOR_ID marker of each item and then # use that marker to store the dirty flags. # The dirty cache data structure attached to the plugin class and the InExcludeData parameter # in question. self._linklistDirtyCache: dict[bytes: int] data: c4d.InExcludeData = op[c4d.ID_LINKLIST] if not isinstance(data, c4d.InExcludeData): return # Now we iterate over all items in the InExcludeData to see if their dirty state has changed. isDirty: bool = False for i in range(data.GetObjectCount()): node: c4d.BaseList2D = data.ObjectFromIndex(doc, i) if not isinstance(node, c4d.BaseList2D): continue # Get the MAXON_CREATOR_ID unique ID of this node. mem: memoryview = node.FindUniqueID(c4d.MAXON_CREATOR_ID) if not isinstance(mem, memoryview): continue uuid: bytes = bytes(mem) # Get the current and cached dirty state of that item. currentDirtyCount: int = node.GetDirty(c4d.DIRTYFLAGS_DATA | c4d.DIRTYFLAGS_MATRIX) cachedDirtyCount: typing.Optional[int] = self._linklistDirtyCache.get(uuid, None) # When there is either no cache or the cache differs from the current value, we update # our cache and set isDirty to True. if (currentDirtyCount is None) or (cachedDirtyCount != currentDirtyCount): isDirty = True self._linklistDirtyCache[uuid] = currentDirtyCount # When isDirty is True, we flag ourselves as dirty, which will cause ModifyObject to be called. if isDirty: op.SetDirty(c4d.DIRTYFLAGS_DATA) print (f"Modifier has been set dependency dirty: {self._linklistDirtyCache.values()}")
  • some problem with CUSTOMGUI_BITMAPBUTTON

    Cinema 4D SDK s26 python sdk
    3
    2
    0 Votes
    3 Posts
    651 Views
    M
    thank you very much! It's help me a lot! sorry about the multiple topics, I'll take them apart next time
  • 0 Votes
    2 Posts
    459 Views
    M
    Hi @pyxelrigger sadly since S26 this is not anymore possible, previously it was saved within the world container like so wc = c4d.GetWorldContainerInstance() wc[c4d.WPREF_FILEPATH_ALL] = r"C:\Users\m_adam\Documents\MAXON\Build\2023.000_381745" This is still used by c4d.storage.LoadDialog and c4d.storage.SaveDialog functions, but internally we don't use anymore these functions. I've open a ticket internally as this is a regression. Cheers, Maxine.
  • SetString() to Update Dialog crash c4d

    Moved Bugs python s22
    5
    2
    0 Votes
    5 Posts
    1k Views
    chuanzhenC
    @m_magalhaes Thanks for the detailed explanation as to why it crashed!
  • Remove Shortcut failed

    Cinema 4D SDK
    3
    1
    0 Votes
    3 Posts
    456 Views
    DunhouD
    @ferdinand Thank you for detailed explain . It's great to add a shortcut container document update and small examples , actually , more examples on sdk or Github is really helpful. After reading I try to re-write it and add some functions like add shortcut or check plugin's shortcut list, It's all worked as expected . Shortcut BaseContainer explain is that great to move on . By the way , from those examples , I learned and try to keep code style as easy to read and repair like yours at the same time . So much appreciated.
  • After id exeetzer axis alignment

    Cinema 4D SDK r21 python
    4
    2
    0 Votes
    4 Posts
    1k Views
    ferdinandF
    Hello @WDP, Please excuse the very long delay, but I have to overlooked your answer here. But as stated in my initial posting, we can only provide support on concrete technical questions. If I remember correctly, there was another thread preceding this one where the same rule had been lined out, which is why I was as strict in my answer here as I was. And while we understand that this line of questions usually does not come from a bad place when asked by less experienced Python users, we ultimately cannot provide full solutions or even write applications. What might get you (and other information seekers) started on this subject is the operation_transfer_axis_s26.py code example, as it manipulates the "axis" of an object. I have closed this topic due to the lack of an eligible support request. Please feel free to open a new question when you have tangible coding problem for that subject. Cheers, Ferdinand
  • Attach Export Dialog

    Cinema 4D SDK python
    5
    0 Votes
    5 Posts
    921 Views
    J
    @m_adam Thank you very much! This is what I was looking for.
  • Store SplineData inside a Container

    Cinema 4D SDK python
    3
    0 Votes
    3 Posts
    483 Views
    ferdinandF
    Hey @rui_mac, thank you for reaching out to us. It is great to hear that you solved your problem yourself. I would however recommend to use BaseContainer.SetData. As a brief explanation, because the Python docs are not too clear on what can be written with SetData, and not all users/readers might be familiar with the C++ API. The SetData and GetData methods in C++ allow you to write anything that can be expressed as GeData into a BaseContainer. That type is not exposed in Python. When looking at the GeData documenation in C++, we can see that there is the constructor GeData (Int32 type, const CustomDataType &data), i.e., CustomDataType can be wrapped as GeData, i.e., SplineData can be written into a BaseContainer. Because this also comes up from time to time, you should be aware that the data is being copied. See example at the end of my posting for details. Cheers, Ferdinand """Demonstrates how to write SplineData into a BaseContainer. """ import c4d def UnpackData(bc: c4d.BaseContainer, cid: int) -> None: """ """ data: any = bc.GetData(cid) if not isinstance(data, c4d.SplineData): return print("\nThe first two knots of the spline in the container:") for i, knot in enumerate(data.GetKnots()[:2]): print (i, knot) def main() -> None: """ """ # Create a spline data instance and use MakeCubicSpline() to generate some data in it. spline: c4d.SplineData = c4d.SplineData() spline.MakeCubicSpline(lPoints=4) # Iterate over the knots. print("The first two knots of the original spline:") for i, knot in enumerate(spline.GetKnots()[:2]): print (i, knot) # Store the SplineData in a BaseContainer. The data will be copied, so any modification made # to #spline after inserting it, will not be reflected. print ("\nWriting spline into container.") bc: c4d.BaseContainer = c4d.BaseContainer() bc.SetData(1000, spline) # Modify the first knot of the spline. spline.SetKnot(0, c4d.Vector(1), c4d.FLAG_KNOT_T_BREAK) print("\nThe first two knots of the modified spline:") for i, knot in enumerate(spline.GetKnots()[:2]): print (i, knot) UnpackData(bc, 1000) if __name__ == '__main__': main()
  • python sdk document error

    Cinema 4D SDK python
    3
    1
    1 Votes
    3 Posts
    573 Views
    M
    Hi with the release 2023.1 of the python documentation the issue have been fixed. Thanks a lot for your reports. Cheers, Maxime.
  • Working with UserData Python

    Cinema 4D SDK python
    7
    3
    0 Votes
    7 Posts
    1k Views
    E
    Thank you once again I marked as solved
  • Is there a "msgId" when I add a child to an object?

    Cinema 4D SDK python
    2
    0 Votes
    2 Posts
    449 Views
    M
    Hi @LingZA there is not such event in Cinema 4D object system. Moreover if there would be one it will be on the Message method which is responsible to receive various event rather than GetDParameter which have the duty to override the value when C4DAtom.GetParameter is called. With that said the way to do that is to let Cinema 4D handle it for you, as Cinema 4D will call GetDDescription when it is needed. So you should check directly in GetDDescription if the object have a child. But it does not work when the attribute manager is locked with a specific object since GetDDescription is called only at the beginning when the object should be displayed. So to workaround this issue you can set the description of the object to be dirty, this will force Cinema 4D to update the description and therefor call GetDDescription. A concrete example bellow where a Float parameter is added if there is no child class DynamicParametersObjectData(c4d.plugins.ObjectData): def __init__(self): self.has_children = False def GetDDescription(self, node, description, flags): """Called by Cinema 4D when the description (UI) is queried. Args: node (c4d.GeListNode): The instance of the ObjectData. description (c4d.Description): The description to modify. flags: return: The success status or the data to be returned. Returns: Union[Bool, tuple(bool, Any, DESCFLAGS_DESC)]: The success status or the data to be returned. """ # Loads the parameters from the description resource before adding dynamic parameters. if not description.LoadDescription(node.GetType()): return False # If there is a child just return and don't add the float parameter if node.GetDown(): return True # Add a Float Parameter bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_REAL) bc.SetString(c4d.DESC_NAME, "Dynamic REAL") descid = c4d.DescID(c4d.DescLevel(1100, c4d.DTYPE_REAL, node.GetType())) description.SetParameter(descid, bc, c4d.DescID(c4d.DescLevel((c4d.ID_OBJECTPROPERTIES)))) # After dynamic parameters have been added successfully, return True and c4d.DESCFLAGS_DESC_LOADED with the input flags return True, flags | c4d.DESCFLAGS_DESC_LOADED def GetVirtualObjects(self, op, hh): """This method is called automatically when Cinema 4D ask for the cache of an object. Args: op (c4d.BaseObject): The Python Generator c4d.BaseObject. hh (c4d.HierarchyHelp): Not implemented. Returns: c4d.BaseObject: The newly allocated object chain, or None if a memory error occurred. """ if op is None or hh is None: raise RuntimeError("Failed to retrieve op or hh.") # Force Cinema 4D to call GetDDescription and therefor update the description if there is a child and the saved state is not in sync with scene state has_children = bool(op.GetDown()) if (self.has_children) != has_children: op.SetDirty(c4d.DIRTYFLAGS_DESCRIPTION) self.has_children = has_children returnObj = c4d.BaseObject(c4d.Osphere) if returnObj is None: raise MemoryError("Failed to create a sphere.") return returnObj if __name__ == "__main__": c4d.plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="Py-DynamicParametersObject", g=DynamicParametersObjectData, description="opydynamicparametersobject", icon=c4d.bitmaps.InitResourceBitmap(c4d.Onull), info=c4d.OBJECT_GENERATOR) Cheers, Maxime.
  • How to Get checked/unchecked state of menu item?

    Cinema 4D SDK s22 python
    3
    0 Votes
    3 Posts
    688 Views
    chuanzhenC
    @ferdinand Thanks!
  • Pragma directives in Python?

    Moved Bugs python
    5
    0 Votes
    5 Posts
    2k Views
    R
    Once again, thenk you very much for all the information, Ferdinand. What I had done already was the last "solution". I do have a file inside the plugin folder that, when the code detects that it is present, skips some verifications. So, I guess I will go on doing that. That even allows me to check for specific filenames and perform different actions for each one. I was just checking to see if there was any type of build-in mechanism to emulate that pragma directives did. And I do know that python is interpreted and that real pragma directives are evaluated in the prepass stage. But I didn't knew if the Source Protector performed some type of evaluation, when protecting the code.
  • How to get the render time from picture viewer

    Cinema 4D SDK python
    3
    1
    0 Votes
    3 Posts
    846 Views
    K
    Hi @ferdinand, Thank you as always for your detailed answer and even the sample scene file! It seems like a lot of work with my current level of understanding, but your answer is a great hint. I'll try to do a little research on my own. Thank you very much.
  • 0 Votes
    3 Posts
    722 Views
    I
    Oh yes that's a much better approach! I will provide executables from now on, sorry for the trouble To be honest I was just stuck in an inaccurate frame for how to solve this... thanks for breaking it
  • 0 Votes
    5 Posts
    724 Views
    DunhouD
    @m_magalhaes Thanks for that explain.
  • Rotation for polygon

    Cinema 4D SDK python
    3
    0 Votes
    3 Posts
    876 Views
    KantroninK
    @ferdinand Thanks, it works well My first method was complex: creation of a new orthogonal spatial system, with one of its axes is identical to the axis of rotation compute the coordinates of the points of the object in this new spatial system, then rotate the object calculation of the new coordinates in the initial orthogonal spatial system.
  • Tool plugin gui

    Cinema 4D SDK s22 python
    7
    0 Votes
    7 Posts
    1k Views
    chuanzhenC
    @ferdinand Thanks!
  • 0 Votes
    5 Posts
    1k Views
    ferdinandF
    Hello @jack0319, Yes, this is a bug. I had to do some digging first (debug against c4d) to find out what is going wrong here. It seems like this is a bug in the scroll group gadget. I was unable to pinpoint what is going exactly wrong, but when a new document is created, the scroll group position is set again, because Cinema 4D is reinitializing its layout. You currently cannot do anything about this. I have filed a bug report on our bug tracker and will update this thread when the bug has been fixed. We cannot make any guarantees regarding an ETA and considering that this is a negligible impact bug, it could take multiple revisions until the bug is fixed. Cheers, Ferdinand