administrators

Private

Posts

  • RE: TreeView DropDown Menu

    Hey,

    yes it is. The trick is c4d.LV_CHECKBOX_HIDE, the relevant bits happen in GetDropDownMenu.

    Cheers,
    Ferdinand

    I removed the command, you can directly run this in the script manager:

    import c4d 
    
    
    PLUGIN_ID = 12345678
    PLUGIN_NAME = "ListView Dropdown Prototype"
    
    ID_TREE_VIEW = 1000
    ID_FILE_NAME = 1001
    ID_IMPORT_OPTION = 1002
    
    ID_IMPORT_OPTION_DEFAULT = 1100
    ID_IMPORT_OPTION_HIGH = 1101
    ID_IMPORT_OPTION_MEDIUM = 1102
    ID_IMPORT_OPTION_LOW = 1103
    
    dummyfile_list = ["hud.stp", "material_reference.wrl", "front_axle.stp", "body.wrl", "wheel_variant.stp"]
    
    
    class DummyFile:
        def __init__(self, file_name, import_option="Default"):
            self.file_name = file_name
            self.import_option = import_option
    
    
    class DummyFileListView(c4d.gui.TreeViewFunctions):
        def __init__(self, dialog):
            self.dialog = dialog
            self.files = [DummyFile(file_name) for file_name in dummyfile_list]
    
        def GetFirst(self, root, userdata):
            return self.files[0] if self.files else None
    
        def GetNext(self, root, userdata, dummy_file):
            current_index = self.files.index(dummy_file)
            next_index = current_index + 1
            return self.files[next_index] if next_index < len(self.files) else None
    
        def GetDown(self, root, userdata, dummy_file):
            return None
    
        def GetId(self, root, userdata, dummy_file):
            return id(dummy_file)
    
        def GetName(self, root, userdata, dummy_file):
            return dummy_file.file_name
    
        def IsSelected(self, root, userdata, dummy_file):
            return False
    
        def GetColumnWidth(self, root, userdata, dummy_file, column_id, area):
            if column_id == ID_FILE_NAME:
                return area.DrawGetTextWidth(dummy_file.file_name) + 24
            if column_id == ID_IMPORT_OPTION:
                return 120
            return 96
    
        def GetDropDownMenu(self, root, userdata, dummy_file, column_id, menu_info):
            if column_id != ID_IMPORT_OPTION:
                menu_info["state"] = c4d.LV_CHECKBOX_HIDE
                return
    
            if not dummy_file.file_name.lower().endswith(".stp"):
                menu_info["state"] = c4d.LV_CHECKBOX_HIDE
                return
    
            options = {
                ID_IMPORT_OPTION_DEFAULT: "Default",
                ID_IMPORT_OPTION_HIGH: "High",
                ID_IMPORT_OPTION_MEDIUM: "Medium",
                ID_IMPORT_OPTION_LOW: "Low",
            }
            for option_id, label in options.items():
                menu_info["menu"].SetString(option_id, label)
            menu_info["entry"] = next(
                option_id for option_id, label in options.items()
                if label == dummy_file.import_option
            )
            menu_info["state"] = c4d.LV_CHECKBOX_ENABLED
    
        def SetDropDownMenu(self, root, userdata, dummy_file, column_id, entry):
            if column_id != ID_IMPORT_OPTION:
                return
    
        #this is logical but does not do the trick ....
    
            if not dummy_file.file_name.lower().endswith(".stp"):
                return
    
            options = {
                ID_IMPORT_OPTION_DEFAULT: "Default",
                ID_IMPORT_OPTION_HIGH: "High",
                ID_IMPORT_OPTION_MEDIUM: "Medium",
                ID_IMPORT_OPTION_LOW: "Low",
            }
            dummy_file.import_option = options.get(entry, dummy_file.import_option)
            self.dialog.tree_view.Refresh()
    
    
    class ListViewDropdownDialog(c4d.gui.GeDialog):
        def __init__(self):
            self.tree_view = None
            self.file_list_view = DummyFileListView(self)
    
        def CreateLayout(self):
            self.SetTitle(PLUGIN_NAME)
    
            tree_view_settings = c4d.BaseContainer()
            tree_view_settings.SetBool(c4d.TREEVIEW_BORDER, c4d.BORDER_THIN_IN)
            tree_view_settings.SetBool(c4d.TREEVIEW_HAS_HEADER, True)
            tree_view_settings.SetBool(c4d.TREEVIEW_HIDE_LINES, True)
            tree_view_settings.SetBool(c4d.TREEVIEW_RESIZE_HEADER, True)
            tree_view_settings.SetBool(c4d.TREEVIEW_FIXED_LAYOUT, True)
            tree_view_settings.SetBool(c4d.TREEVIEW_ALTERNATE_BG, True)
            if c4d.GetC4DVersion() >= 24000:
                tree_view_settings.SetInt32(c4d.TREEVIEW_VERTICAL_SPACE, 4)
    
            self.tree_view = self.AddCustomGui(ID_TREE_VIEW, c4d.CUSTOMGUI_TREEVIEW, "", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 500, 220, tree_view_settings, )
            if not self.tree_view:
                return False
    
            layout = c4d.BaseContainer()
            layout.SetLong(ID_FILE_NAME, c4d.LV_TREE)
            layout.SetLong(ID_IMPORT_OPTION, c4d.LV_DROPDOWN)
            self.tree_view.SetLayout(2, layout)
            self.tree_view.SetHeaderText(ID_FILE_NAME, "Dummy file")
            self.tree_view.SetHeaderText(ID_IMPORT_OPTION, "STP import option")
            self.tree_view.SetRoot(self.tree_view, self.file_list_view, None)
            return True
    
        def InitValues(self):
            self.tree_view.Refresh()
            return True
    
    if __name__ == "__main__":
        dialog = ListViewDropdownDialog()
        dialog.Open(c4d.DLG_TYPE_MODAL, 0, -1, -1, 500, 220)
    
  • RE: c4d.RSCAMERAOBJECT_COLOR_CONTROLS_CURVE_RGB

    Hey @lasselauch,

    no, that is unfortunately not possible. Unlike for the other big custom data type of Redshift RSFILE, the curve data type RSPFXCURVE does not implement Get/SetParameter to access internals of the data type, as you can for the file type with REDSHIFT_FILE_PATH.

    It also stands a bit to question how such lower desc level access should work here? Maybe as a lower level which can read/write the curve as SplineData? But I am not sure if this type would be faithfully convertable to SplineData`.

    I cannot fix this as Redshift is not part of the Cinema code base where the Python API lives. I gave one of the RS developers a bump so that they maybe can implement Get/SetParameter for that custom data type.

    Cheers,
    Ferdinand

  • RE: Change render Space (Color Profile) - how?

    You likely have to call UpdateOcioColorSpaces, just follow the example. There is btw no guarantee at all that DOCUMENT_COLOR_MANAGEMENT entails a render space of ACEScg. That is just the default, the user could have changed that.

    I am also not sure what all that RDATA_IMAGECOLORPROFILE code is meant to do. It depends a bit on what your plugin does and what self.IsForceLinear is meant to express. Only so much: An OCIO document does not necessarily entail a bitmap with a non-linear color profile, and OCIO also does not mean that the bitmap has to be 32bit. You are however missing UNDOTYPE_PRIVATE_DOCUMENTDATA undo management for setting the color management.

  • RE: Change render Space (Color Profile) - how?

    I do not quite understand your question. A node (e.g., an object) will always hold its color parameters in render space. The only exception is NodeData.Init and it is explained in the example.

  • RE: Change render Space (Color Profile) - how?

    Yes, OCIO having become the standard color management entailed some changes. In case your plugin is some kind of NodeData, you should also look at ocio_node_2025.

  • RE: Change render Space (Color Profile) - how?

    Hey @mogh,

    you cannot do that, because we do not provide access to GUIs as always, only to the data structures that stand behind them. When you see this dropdown in a document, it means it is in OCIO mode. Which in turns means all colors are in render space; which is the main idea of OCIO that all computations happen in render space. All color read and write operations happen in render space, i.e., ACEScg by default. You can use a color converter to convert a color from for example sRGB to render space. But there is no color space setting for a color, that is just UI fluff. See GetSetColorValuesInSceneElements.

    I would recommend to read:

    Cheers,
    Ferdinand

  • RE: Change render Space (Color Profile) - how?

    Hey @mogh,

    the answer can be found in the OCIO examples, specifically here. In the example I do the exact opposite from what you want to do, I convert a scene from legacy/basic mode to OCIO. Its inverse would look somewhat like what I show below. I hope this helps.

    Cheers,
    Ferdinand

    """Demonstrates how to convert a document from OCIO color management to basic color management.
    """
    import c4d
    
    
    op: c4d.BaseObject | None # The primary selected object in the scene, can be None.
    doc: c4d.documents.BaseDocument # The currently active document.
    
    def main() -> None:
        """Runs the example.
        """
        # The document is already in basic mode, so no conversion is needed.
        if doc[c4d.DOCUMENT_COLOR_MANAGEMENT] == c4d.DOCUMENT_COLOR_MANAGEMENT_BASIC:
            return c4d.gui.MessageDialog("The document is already in basic mode. No conversion is needed.")
    
        # Get the converter, and the active render space, which by default will be ACEScg.
        converter: c4d.modules.render.SceneColorConverter = c4d.modules.render.SceneColorConverter()
        renderSpace: str = doc.GetOcioRenderingColorSpaceNames()[0]
    
        # Initialize the converter with:
        #              doc, from-low   , from-high   , to
        converter.Init(doc, renderSpace, renderSpace, "scene-linear Rec.709-sRGB")
    
        # Convert everything in the document (we pass the document itself as the second argument). The
        # undo management is only needed so that our DOCUMENT_COLOR_MANAGEMENT below is reversible. The
        # ConvertObject call creates undo steps on its own with the default flag we pass. 
        doc.StartUndo()
        doc.AddUndo(c4d.UNDOTYPE_PRIVATE_DOCUMENTDATA, doc)
        if not converter.ConvertObject(doc, doc):
            print(f"Failed to color convert document '{doc}'.")
    
        # Finally, set the color management mode to basic/legacy. It is absolutely important that we do
        # things in this order, otherwise SceneColorConverter will not work correctly.
        doc[c4d.DOCUMENT_COLOR_MANAGEMENT] = c4d.DOCUMENT_COLOR_MANAGEMENT_BASIC
        doc.EndUndo()
        c4d.EventAdd()
        
    if __name__ == "__main__":
        main()
    
  • RE: Using SetWeightMap() multiple times can lead to inexplicable changes in weight values

    Hey @chuanzhen,

    thanks for the update. I can reproduce the issue.

    The cause is that some frontend systems can work in a higher precision than the weighting backend can. We use there for some reason UInt16 in the character animation backend to store weights, while the smooth tool for example operates in Float64. Python operates always in 64bit with float. The error is caused by UInt16 normalization (make the value fit into one of the 65535 value bins there are in 16 bit for the range [0, 1]).

    I did not trace down why this happens not at once but in multiple steps, but the bottom line is that sooner or later weights are forced into a 16 bit format. You as a user cannot do anything about it, but it also is not really an issue. This is not a loss of data, the character weights internally use 16bit. It is more that some of the newer tools built around them provide more precise data than the old character animation core can handle.

    Cheers,
    Ferdinand

  • RE: MergeDocument() crash C4D

    (As an aside, I found this issue in one of my plugins (which uses MergeDocument). This plugin was developed in C4D 2024, and the same code worked in older versions but crashes in 2026. Even with the same script code and merge same file, it works normally in 2024 but crashes in 2026)

    things can change in the backend of Cinema, without concrete code (the plugin) and example files, I cannot help you much. It could very well be that we added some corner case bug.

  • RE: MergeDocument() crash C4D

    @chuanzhen said in MergeDocument() crash C4D:

    But I still have a question. If it's a plugin issue ( CopyTo Read Write function is not implemented), then why can the Merge command in C4D merge files normally?

    What I meant was this: Imagine you have an ObjectData plugin Foo which has a class instance attribute called _data. Many of Foo's methods rely on _data, as for example GetVirtualObjects, GetDDescription, etc. When you now copy an instance of Foo, Cinema will copy its data container but not _data when you have not implemented CopyTo. On the copied instance of Foo, the _data attribute will either not exist at all or be in uninitialized state. Cinema can then for example crash or freeze when you raise an AttributeError (because you try to access a non-existing _data; or any other error) in a GetDDescription call in some corner cases. _data being misaligned with the data container of a node could also lead to all sorts of bugs when your code assumes that they are somehow aligned.

    In short, Cinema can always read, write, and copy nodes, no matter what you do. But with CopyTo you can make sure that data outside of the data container of the node (BaseList2D.GetDataInstance) is also correctly copied. The lesson here is that when you have fields such as self._my_data on a node, and that field cannot be reestablished on the fly, you must implement Read, Write, and CopyTo, so that _my_data can be written, read, and copied from/to/between scene files. You therefore also usually implement all three of these methods and not just one of them when you need them.

    Cheers,
    Ferdinand