• How to use GetAllNimbusRefs in 2023

    Cinema 4D SDK 2023 c++ windows
    5
    0 Votes
    5 Posts
    956 Views
    kbarK
    Thanks @ferdinand! Appreciate everything you do. Also what the rest of the sdk support and docs team are doing! Not an easy job keeping on top of all these changes.
  • Crash in ReadChunk()

    Cineware SDK c++ windows
    7
    0 Votes
    7 Posts
    2k Views
    T
    Hi Jens, That fix works for us. This is excellent. Thank you very much. Regards, Tom
  • Undraw Slider in TreeView?

    Cinema 4D SDK windows python 2024
    3
    2
    0 Votes
    3 Posts
    607 Views
    gheyretG
    Hi!@ferdinand Yes , That's what i want to do! I never didn't know LV_CHECKBOX_HIDE would work with LV_SLIDER, I simply assumed that it would only work with LV_CHECKBOX and LV_CHECKBOXUSER. But anyway i test it in my code , and it works perfectly! Thank you so much for your reply. Cheers~
  • 0 Votes
    8 Posts
    2k Views
    sasha_janvierS
    @ferdinand Yay! Amazing. I can confirm that my solution builds without any problems in 2024.3.2. Big thanks to you and the dev team at Maxon!
  • Can we handle drag document from treeview?

    Cinema 4D SDK windows python 2024
    3
    0 Votes
    3 Posts
    580 Views
    DunhouD
    Hi @i_mazlov , Sadly the GenerateDragData() not work in python, I had try the c4d.DRAGTYPE_FILENAME_SCENE, but it will return bad without GenerateDragData(),seems nothing we can do here. Cheers~ DunHou
  • 0 Votes
    10 Posts
    2k Views
    H
    @ferdinand After a lot of time forced to work on other projects, I have looked further into this, and sent you an email. I hope you don't see it until after the holiday season.
  • 0 Votes
    3 Posts
    534 Views
    D
    @i_mazlov thanks ilia!!! ok that was truly obvious actually had to use 'c4d.documents.GetActiveDocument()' to make it work in my case ...
  • Python generation script doesn't work

    Cinema 4D SDK python windows 2024
    2
    2
    0 Votes
    2 Posts
    446 Views
    ferdinandF
    Hello @eegoridze, 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: Asking Questions. About your First Question I would like to point you to four sections in our Support Procedures: Scope of Support: "It doesn't work" is not a support request and we cannot debug your code for you, but instead provide answers to specific problems. Asking Questions: Repeatable: Your claims or problem should be repeatable for us. In most cases this means posting executable code which demonstrates your problem, with the emphasis being on executable. We should be able to paste this code into an editor and then run or compile it without having to write code ourselves. When you just post snippets, this usually means that we will not run your code, as we do not have the time to invent all the code around it. Ignoring this also comes with the substantial risk that you do not post the code which contains your actual mistake/problem.. Asking Questions: Sparseness: Your problems should be sparse, or in other words you should spend some time on boiling down more complex problems. When you, for example, are writing a plugin with which one can create trees with physics and all sorts of fancy things, and you run into a problem, you should spend time on removing as many fancy things as possible, so that we have an easier time helping you. Code examples should only very rarely have more than one thousand lines of code. Reporting Bugs & Crashes: The whole section applies here. While it is understandable that users sometimes violate some of these rules, it is here a bit much. Sparseness: You certainly could have spent some time on pruning your script from things you can remove without removing your problem. Repeatable: We cannot run your code. While you have provided the source code, you have not provided the scene file and possibly other files which are necessary to run this. Reporting Bugs & Crashes: When you have provided (2), you should follow the pattern we require to report bugs and crashes, even when they are your own. It is all about reproducibility and clear instructions. General Advice It is obvious that you have put quite some work into your script and also work into your question here. Thousands lines of code do not write themself and screenshots also do not make themself. But my major advice would be here: "Be more strategic about how you approach things." Writing software is all about breaking things into manageable problems and you seem to try to do everything at once. Which is fine if you are a pro and never make mistakes, but it usually bites you royally in the butt when you run into problems. Remove Non-Const Code from Module Scope In the first 100 lines you have a lot of code in the module scope. You can initialize global constants in the module scope, but you should certainly not open dialogs there. This is just a big no-no as it not only makes your code hard to read - when is happening what, you cannot just start reading in the main function -, but also comes with the problem that some of the code will run when the module is initialized and some when the execution context __name__ is "__main__". [image: 1707760026417-2189247f-36d5-4980-a0ca-aa44f1a95f40-image.png] Divide and Conquer & Abstract There is very little abstraction in your code, which again is fine when you are pro who never makes mistakes, but becomes a problem when you must debug things, as you then have to deal a monolithic piece of code where it is hard to turn off things or understand what is happening. When I take the first lines of your main function: [image: 1707764358023-223b2359-9eec-48c0-9f7b-51bc9a774c4e-image.png] If I would rewrite this, it would look like this: import c4d import mxutils class ObjectGroup: """A class to group objects and set their visibility. """ def __init__(self, groupName: str, parent: c4d.BaseObject) -> None: """Initializes the class. """ self.groupName = groupName self.objects = mxutils.CheckType(parent, c4d.BaseObject).GetChildren() # It seems a bit questionable to me to store the names of the objects in a separate list, # since the data is so easy to access on a node, but I went with it here. self.names = [i.GetName() for i in self.objects] self.SetVisibility() def SetVisibility(self, state: int) -> None: """Sets the editor and render visibility of the objects in the group. """ for obj in self.objects: obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = state obj[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = state def __iter__(self) -> tuple[str, c4d.BaseObject]: """Iterates over name, object pairs. """ for name, obj in zip(self.names, self.objects): yield name, obj def __getitem__(self, index: int) -> tuple[str, c4d.BaseObject]: """Gets the name, object tuple at the given index. """ if index < 0 or index >= len(self.objects): raise IndexError("Index out of range.") return self.names[index], self.objects[index] def GetObjects(doc: c4d.documents.BaseDocument) -> dict[str, ObjectGroup]: """Gets the objects from the document. """ # Get the objects from the document, be defensive about our assumptions, here we assume that # the document contains at least eight objects, but we should check it. objects: list[c4d.BaseObject] = doc.GetObjects() if len(objects) < 8: raise ValueError("The document must contain at least eight objects.") # Now we create one data structure to hold all the object groups, this makes it easier to use. # I personally would crate a class to hold the object groups, but I went with a dictionary here # to keep it simple. return { "glasses": ObjectGroup("glasses", objects[0]), "masks": ObjectGroup("masks", objects[1]), "jewelery": ObjectGroup("jewelery", objects[2]), "headgear": ObjectGroup("headgear", objects[3]), "clothes": ObjectGroup("clothes", objects[4]), "hairs": ObjectGroup("hairs", objects[5]), "eyes": ObjectGroup("eyes", objects[6]), "special_accessories": ObjectGroup("special_accessories", objects[7]) } def main(): """ """ # Now can just call #GetObjects and get the data we need. data: dict[str, ObjectGroup] = GetObjects(doc) # Now we continue in this style, where we "divide and conquer" the problem, i.e., split things # into sub-problems and solve them one by one. So that we can have here in the main function only # the high-level logic. restrictions: list[str] = GetRestrictions(RESTRICTIONS_FILE) ApplyRestrictions(data, restrictions) # ... Doing this will help you to help yourself, as you would get more control over your own code. Conclusion Some of my colleagues are a bit less squeamish than me when I comes to spaghetti code, but I doubt that they are willing to debug your 800 lines of single letter variables. Try to make your code more abstract and clean, you will likely fix the problem yourself in the process. For me it is currently not really possible to follow your code and with that give you meaningful advice. If not, come back with a pruned version of your code, provide all data, and reproduction steps. And with pruning I mean really prune it. Try to remove as many things as possible. You should also be verbose about what your problem is. I think you are encountering freezes, "the program just hangs" but you only mention that somewhere in the middle of your posting. Cheers, Ferdinand
  • 0 Votes
    2 Posts
    1k Views
    ferdinandF
    Hello @GillesKontrol, Thank you for reaching out to us. Jesus Christ, that is a lot of tags! While we do have quite a few topics on selections here on the forum, we have no dedicated Python code examples for selections on GitHub (we probably should change that). Selections are merged with BaseSelect.Merge. But there are some hoops to jump through here, which is why I have written a code example. Although my example is probably pretty close to what you want, I must remind you that we do not provide solutions in the SDK group. Any modification or improvement must be done by yourself. You should also show your code in the future, no matter how little your progress has been. Cheers, Ferdinand Scene: select.c4d Before: [image: 1707503136122-15ec7661-afbb-4fe0-889c-dd5ee6d3622b-image.png] After: [image: 1707503174138-cb1ed039-3e64-4da1-8e01-653ac47dc953-image.png] Code: """Consolidates material assignments on all selected objects. Run with at least one object selected. The script will merge all texture tags using a restriction, i.e., a selection tag, that reference the same material. The operation will be wrapped into one undo item. Note: As always, the SDK group does not provide finished solutions. If you want things to be changed, that would be up to you. Here are some short-comings. * I did not deal with the case that there is a material M referenced on an object both as a texture tag with and without a restriction. Does not make too much sense but I ignored it. * I also ignored differences in projections. The script assumes that all material assignments are just unmodified UVW projections. * Finally, I determine the "sameness" of materials by identity and not by (quasi)-equality. When there are two absolutely identical materials in a scene, or two materials which are only differentiated by their name, they and their tags will not be merged. """ import c4d import mxutils import time doc: c4d.documents.BaseDocument # The active document. def ConsolidateMaterialsOnObject(op: c4d.BaseObject) -> None: """Consolidates the texture tags and selection tags used by them on #op by reference of material. Note: In the API material tags are called texture tags. """ # The first thing we do, is build a map where we associate materials assigned to #op with the # texture tags of #op assigning them. I.e., we collect the texture tags which should be # consolidated as they are assigning the same material. # # NOTE: We use here a 2023.2 feature, C4DAtom.__hash__, to insert the materials as keys into the # dict. In earlier versions we would have to use node UUIDs for that. groups: dict[c4d.BaseMaterial, list[c4d.TextureTag]] = {} # Iterate over all texture tags in #op and store them under the material they assign. for tag in [t for t in op.GetTags() if t.CheckType(c4d.Ttexture)]: material: c4d.BaseMaterial = tag[c4d.TEXTURETAG_MATERIAL] groups[material] = groups.get(material, []) + [tag] # Now we iterate over our build mappings as pairs of a material and the texture tags which # assign it. for material, textureTags in groups.items(): # Step over materials which are assigned by less than two tags. if len(textureTags) < 2: continue # Now we pull all the selection tags of #op which are referenced in the texture tags. selectionTags: list[c4d.SelectionTag] = [] for tag in textureTags: # Since selection tags are referenced a bit weirdly as a string in texture tags, # we cannot just grab their base link and instead must search for them. restriction: str = tag[c4d.TEXTURETAG_RESTRICTION] candidates: list[c4d.SelectionTag] = [t for t in op.GetTags() if t.CheckType(c4d.Tpolygonselection) and t.GetName() == restriction] if len(candidates) != 1: raise RuntimeError( f"Found texture tag {tag} with ambiguous restriction '{restriction}'.") selectionTags.append(candidates[0]) # Now we have all the input data we need. The first thing we do is establish a unique name # for the new selection tag, the 'restriction' referenced in the texture tag, and then # create the selection tag. restriction: str = f"{material.GetName()}_{time.perf_counter_ns()}" selectionTag: c4d.SelectionTag = op.MakeTag(c4d.Tpolygonselection) selectionTag.SetName(restriction) doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, selectionTag) # Now we get the BaseSelect for our new selection tag and copy over all the selection states # of the selection tags we have collected. selection: c4d.BaseSelect = selectionTag.GetBaseSelect() res: bool = all([selection.Merge(t.GetBaseSelect()) for t in selectionTags]) if not res: raise RuntimeError(f"Copying a selection tag for {material} failed.") # We do not need the old selection and texture tags anymore and therefore remove them. for t in (selectionTags + textureTags): doc.AddUndo(c4d.UNDOTYPE_DELETE, t) t.Remove() # We create a new texture tag and reference the current material from the loop and our new # selection tag in it. textureTag: c4d.TextureTag = op.MakeTag(c4d.Ttexture) textureTag[c4d.TEXTURETAG_MATERIAL] = material textureTag[c4d.TEXTURETAG_RESTRICTION] = restriction doc.AddUndo(c4d.UNDOTYPE_NEWOBJ, textureTag) def main() -> None: """ """ # Get all directly selected objects in the scene, bail when there is no selection. selection: list[c4d.BaseObject] = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_NONE) if not selection: print ("no objects selected to consolidate selection tags for.") return # Wrapped in an undo, iterate over them and compact the material assignments on them. doc.StartUndo() for obj in doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN): ConsolidateMaterialsOnObject(obj) doc.EndUndo() # Push an update event. c4d.EventAdd() if __name__ == "__main__": main()
  • 0 Votes
    4 Posts
    857 Views
    S
    @i_mazlov I tried the GetRad() method. This is exactly what I need, thanks!
  • 0 Votes
    4 Posts
    925 Views
    ferdinandF
    Hey @GordOrb, This is not possible. You are not really meant to distinguish the file names you are writing for. I also do not understand the purpose of doing what you want to do. You can already name the beauty file and the multipass file differently in the UI. And when you write out each pass on its own, Cinema 4D will already name them differently for you. There will be singular token call for all pass layers, and before that a call for the RGB/beauty layer. None of the calls for naming the file contains pass information. The inner logic of it seems to be that you first get the call for evaluating the token for a filename and after that the actual passes. The purpose of some fields in the passed data is probably more of internal than public nature, since you cannot really do much with that info due to how the token calls are coming in. In some contexts these fields might be useful when you use the Token System (C++ Manual) more manually. But at least for the passes case, this is not really true either, because when you start to render manually, you will have to fill in the pass data on your own when constructing a RenderPathData. So, long story short: this is not really possible, at least in the intended way. Upon having a closer look at the time stamps and my file output, I realized that you could try to rely on the rule 'the call after the call for the RGB pass', because that is at least how it works in my example. isMultipass: '1', pname: ' ', ptype: ' ', pid: ' -1', t: 9366346949848 // First call, irrelevant isMultipass: '1', pname: ' ', ptype: ' ', pid: ' -1', t: 9367113676312 // Time stamp of saved RGB/beauty. isMultipass: '1', pname: ' RGB', ptype: ' RGB', pid: ' -1', t: 9367113987757 // RGB/beauty pass isMultipass: '1', pname: ' ', ptype: ' ', pid: ' -1', t: 9367114252401 // Time stamp of all passes. ... If this works, this would be hack, and it would be then up to you establish if that holds true or not. To establish "what is the last call", you could have some global list into which you push things. Make sure not to store any Cinema 4D rendering data in that global list (BaseDocument, BaseContainer, RenderData) or you might end up in world of hurt. Cheers, Ferdinand Written Files: [image: 1707477127170-fc970227-90fb-437e-b5d7-b7a25a9e2da0-image-resized.png] My console dump, here I search for the time stamp 9367114252401 of my files, it is the fourth call, long before we get the calls for the passes. The only thing that comes before is a call for the RGB, i. e., the beauty pass. [image: 1707477097394-b5e92449-2ffa-4d4b-a0b7-de02968635d8-image-resized.png] Code: """ """ import c4d import mxutils import time def get_render_type(data: c4d.BaseContainer) -> str: """Dumps information about #data into the token and the console. """ # Get the render document #rdoc, and build a string for the UUID of rdoc as well as its memory # location and #data. Unsurprisingly, the mem locs are meaningless here in Python as everything # must be wrapped by Python objects in each call. In C++ you might be able to establish "sameness" # between calls by the location of #data (the rendering document which is used is always the # same as shown by its UUID). But I doubt that you will have luck with #data in C++, because it # is likely constructed for each call there too (and not reused). rdoc: c4d.documents.BaseDocument = mxutils.CheckType(data[0], c4d.documents.BaseDocument) uuid: bytes = bytes(rdoc.FindUniqueID(c4d.MAXON_CREATOR_ID)) ident: str = f"doc-uuid: {uuid}, doc-mem: {id(rdoc)}, bc-mem: {id(data)}" # Build the token. token: str = (f"isMultipass: '{rdoc.GetActiveRenderData()[c4d.RDATA_MULTIPASS_ENABLE]}', " f"pname: '{data[5]:>20}', ptype: '{data[6]:>10}', pid: '{data[7]:>3}', t: {time.perf_counter_ns()}") print (ident, token) return token if __name__ == "__main__": if "r_type" not in set(item["_token"] for item in c4d.modules.tokensystem.GetAllTokenEntries()): c4d.plugins.RegisterToken("r_type", "[Render] Type", "reg/multi", get_render_type)
  • 'CreateNewTexture': identifier not found

    Cinema 4D SDK windows c++ 2024
    5
    0 Votes
    5 Posts
    893 Views
    sasha_janvierS
    Edit: Nevermind. Once again, a silly oversight. I hadn't provided enough TEXTURE-type settings to the BaseContainer, such as TEXTURE_FILEFORMAT. Apologies!
  • 0 Votes
    3 Posts
    575 Views
    DunhouD
    Thanks @i_mazlov , The msg[c4d.BFM_ACTION_VALUE] is all I want, Thanks for that. Cheers~ DunHou
  • How to preserve the animation of a sphere

    Cinema 4D SDK s26 c++ windows
    9
    2
    0 Votes
    9 Posts
    2k Views
    P
    @i_mazlov thank you very much
  • 0 Votes
    16 Posts
    3k Views
    sasha_janvierS
    Thank you very kindly, @ferdinand! I had already started exploring the maxon::ParallelImage class as I suspected it to be the ideal path forward for my case, so it's great to have my suspicions be validated! I will make sure to start a new thread if I have any questions related to this class. Thank you very much once again. Your assistance has been indispensable! Cheers
  • Project management for C4D SDK projects

    Moved General Talk c++ 2024 macos windows
    4
    3 Votes
    4 Posts
    1k Views
    H
    Thank you very much, Maxime! I'll check out the various points and open a dedicated thread if I have anything further to ask or say about these topics.
  • 0 Votes
    3 Posts
    946 Views
    F
    Hello @ferdinand Thank you for your guidance. I'll follow your suggestion and reach out to the support team for assistance with my query. Best regards, Tomasz
  • How to get sphere coordinates

    Cinema 4D SDK s26 c++ windows
    6
    2
    0 Votes
    6 Posts
    1k Views
    i_mazlovI
    Hi @pchg , This thread is almost a full duplicate of your adjacent thread: How to preserve the animation of a sphere. The answer is provided there. Cheers, Ilia
  • UserArea drag and drop example?

    Cinema 4D SDK windows 2024 python
    6
    0 Votes
    6 Posts
    2k Views
    K
    I tried using a timer to solve this problem, but I still want to know if there is a more direct way import c4d import threading from c4d.gui import GeUserArea, GeDialog GADGET_ID_GEUSERAREA = 10000 class DropArea(GeUserArea): def __init__(self): # Used to store all objects involved in the drag-and-drop operation self.currentDragObjects = [] # Flag to indicate whether a drag operation is in progress self.isDragging = False # Define a timer to delay the handling of the drag completion self.dragTimer = None def Message(self, msg, result): # Handle drag-and-drop messages if msg.GetId() == c4d.BFM_DRAGRECEIVE: # Check if the drag was lost or canceled if msg.GetInt32(c4d.BFM_DRAG_LOST) or msg.GetInt32(c4d.BFM_DRAG_ESC): self.isDragging = False return self.SetDragDestination(c4d.MOUSE_FORBIDDEN) # If the drag just started, clear the previous object list if not self.isDragging: self.currentDragObjects = [] # Initialize the storage list self.isDragging = True # Mark the beginning of the drag # Verify if it is a valid drop area if not self.CheckDropArea(msg, True, True): return self.SetDragDestination(c4d.MOUSE_FORBIDDEN) # Get the dragged file object dragInfo = self.GetDragObject(msg) if dragInfo is not None: dragObject = dragInfo['object'] # Check if the object already exists in the list to avoid duplicates if dragObject not in self.currentDragObjects: self.currentDragObjects.append(dragObject) # Reset the timer to delay the handling of drag completion if self.dragTimer is not None: self.dragTimer.cancel() # Set a short timer (e.g., 0.2 seconds) to determine if the drag operation is complete self.dragTimer = threading.Timer(0.2, self._finalize_drag) self.dragTimer.start() # Set the mouse cursor to a valid state return self.SetDragDestination(c4d.MOUSE_MOVE) # Call the base class Message() method to handle other messages return c4d.gui.GeUserArea.Message(self, msg, result) def _finalize_drag(self): # Delayed execution to ensure all dragged objects have been received self.isDragging = False if self.currentDragObjects: # Print all dropped files print(f"Dropped files: {self.currentDragObjects}") # Additional logic can be executed here, e.g., handling file paths or other content # Clear the object list for the next drag-and-drop operation self.currentDragObjects = [] # Redraw the user area (if UI update is needed) self.Redraw() class ExampleDialog(GeDialog): geUserArea = DropArea() def CreateLayout(self): self.SetTitle("Drag Area") if self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=1, rows=0, title="", groupflags=0, initw=100, inith=100): self.GroupBorderSpace(8, 8, 8, 8) self.GroupSpace(2, 2) # Add the user area gadget self.AddUserArea(GADGET_ID_GEUSERAREA, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 200, 200) # Attach the user area to the gadget self.AttachUserArea(self.geUserArea, GADGET_ID_GEUSERAREA) self.GroupEnd() return True if __name__ == "__main__": global dlg dlg = ExampleDialog() dlg.Open(dlgtype=c4d.DLG_TYPE_ASYNC, defaultw=200, defaulth=200)
  • 0 Votes
    3 Posts
    2k Views
    ThomasBT
    @ferdinand Hello Ferdinand, Thank you very much first of all. yes, you're right, I worked extremely sloppily with the SMC method, of course I'll take the threading into account and also work with a Temp Document. Regarding the problem itself, I can only say that reinstalling CINEMA 4D solved our problem. Cheers