Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Register
    • Login
    1. Maxon Developers Forum
    2. mogh
    M
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 39
    • Posts 169
    • Groups 0

    mogh

    @mogh

    Industrial Designer, Product Visualization, a slight itch for scripting.

    9
    Reputation
    103
    Profile views
    169
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online
    Location South Germany

    mogh Unfollow Follow

    Best posts made by mogh

    • RE: How to setup c4d.utils.ViewportSelect() and GetNearestPoint to work

      @m_magalhaes

      This morning: uff more learning and work.
      This Afternoon lets try this code ... mind blown ... thank you !

      I'll mark this as solved hence I think ist a good way to close a thread with a working prototype for others to learn.

      Thank You again, @zipit & @m_magalhaes
      mogh

      posted in Cinema 4D SDK
      M
      mogh
    • RE: Open source wrapper for Octane/Redshift/Arnold/Vray/Corona in Cinema 4D.

      Wow ... good stuff
      My c4d Programing slowed down this year, but this might be something I want to use some day ...

      posted in General Talk
      M
      mogh
    • RE: Table With TreeViewCustomGui with no Tree Icon

      @mikeudin

      In my case setting this to true hides them.

      customgui.SetBool(c4d.TREEVIEW_HIDE_LINES, True) # True if no lines should be drawn.

      kind regards
      mogh

      posted in Cinema 4D SDK
      M
      mogh
    • RE: Metadata Supported for FBX Imports?

      Just additional reinforcement.

      We talk here a lot of Metadata in CAD files for Digital Twins, so a universal handling of "additional" data not processed by cinema is an area to explore at Maxon !

      posted in General Talk
      M
      mogh
    • RE: Layers checker

      Beginner solution:
      If you do not need a certain layer you could also implement the call comand "Delete unused layers"
      Its not pretty but beats any convulated self written code if it is not called to often.

      c4d.CallCommand(100004760) # Remove unused layers

      cheers
      mogh

      posted in Cinema 4D SDK
      M
      mogh
    • RE: How can I make a simple input form for my Python script?

      ... while the Team probalby will ask you to provide more context / detail ... have you looked at the sdk examples ?

      https://github.com/PluginCafe/cinema4d_py_sdk_extended/tree/master/scripts/03_application_development/gui/dialog

      kind regards

      posted in Cinema 4D SDK
      M
      mogh
    • RE: Dialog Menu

      EDIT:
      Sorry this was not what I thought I have a dual Dialog example somewhere but not at hand ...

      *This is an Subdialog Example from the SDK.

      Github Subdialog

      hope that is in line what you are searching.*
      Cheers mogh

      posted in Cinema 4D SDK
      M
      mogh
    • RE: Quicktab SDK Example

      Here is my latest Example Code, I will check for R2023.1 on Monday.
      selecting FFFF and DDDD results in GUI weirdness ... on R20

      Update: Also on 2023.1 I get this UI glitch ... selecting KKKKK / LLLLLL (last ones)

      Update 2: fiddled a little bit with the IDs (the class has an offset now so the ids are unique) and Layoutchange() no updated on the glitch when selecting the KKKK + X elements.

      2023-03-27-Window_000269.png

      import c4d # pyright: ignore[reportMissingImports]
      import json
      import os
      from collections import OrderedDict
      
      DEBUG = True
      
      # Ids used in our Dialog
      ID_MAINGROUP = 1000  # ID used for the Group that holds all the other group representing the tab content
      ID_QUICKTAB_BAR = 1001  # ID for the quicktab customGui
      
      ID_LOADDEFAULT_MAT_ASIGN = 1003
      ID_CREATE_MATERIALS = 1004
      BUTTON_PRINT_TEXT = 1005  # ID used for the Print text Button
      BUTTON_PRINT_SELECTED = 1006  # ID used for the Print Selected Button
      BUTTON_FLUSH_ALL = 1007  # ID used for the Flush All Button
      BUTTON_ADD = 1008  # ID used for the Add Button
      BUTTON_REMOVE = 1009  # ID used for the Remove Button
      
      # Id used in our SubDialog
      ID_QUICKTAB_BASE_GROUP = 5000
      
      # Defines the ID for the string to be displayed
      CUSTOM_GROUP_ID_TEXT_BASE = 4000  
      
      DEFAULT_FLAGS = c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT
      DEFAULT_SPACE = (5, 5, 5, 5)
      DEFAULT_BORDER_STYLE =c4d.BORDER_NONE
      
      LAYOUT_DEBUG = True
      if LAYOUT_DEBUG is True:
          DEFAULT_BORDER_STYLE = c4d.BORDER_BLACK
      
      GENERATOR_START_ID = 2000
      def plusone_id():
          n = GENERATOR_START_ID
          while n < GENERATOR_START_ID+999:
              yield n
              n += 1
      
      some_json = '{"AAAAAAA 85": ["a part_num_1","a part_num_2","a part_num_3"],"BBBBB 40": ["b part_num_4","b part_num_5"],"CCCCCCC": ["c part_num_6","c part_num_7","c part_num_8","c part_num_9"],"DDDDDD": ["d part_num_6","d part_num_7","d part_num_8","d part_num_9"],"FFFFF": ["f Plane"],"GGGGGGG": ["g part_num_6","g part_num_7","g part_num_8","g part_num_9"],"HHHHHHHH": ["h part_num_6","h part_num_7","h part_num_8","h part_num_9"],"IIIIII": ["i part_num_6","i part_num_7","i part_num_8","i part_num_9"],"JJJJJJJJJ": ["j part_num_6","j part_num_7","j part_num_8","j part_num_9"],"KKKKKKKK": ["k part_num_6","k part_num_7","k part_num_8","k part_num_9"],"LLLLLLLLL": ["l part_num_6","l part_num_7","l part_num_8","l part_num_9"],"MMMMMM": ["m part_num_6","m part_num_7","m part_num_8","m part_num_9"]}'
      
      ### Json
      #####################################################################################
      
      def read_parts_json(json_file_path):
          #with open(json_file_path) as f: data = json.load(f)
          data = json.loads(some_json)
      
          materials = {}
          for material_id, part_numbers in data.items():
              materials[material_id] = part_numbers
          
          material_ids = list(data.keys())
          return material_ids, materials
      
      class CustomGroup(c4d.gui.SubDialog):
          """A SubDialog to display the passed string, its used as example for the actual content of a Tab"""
          
          def __init__(self, material, parts, offset):
      
              self._material = material
              self._parts = '\n'.join(parts)
              self.gui_id = CUSTOM_GROUP_ID_TEXT_BASE + offset
      
          def CreateLayout(self):
              
              self.GroupBegin(self.gui_id + 4, flags=c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=1, rows=2, title=self.gui_id)
              self.GroupBorder(DEFAULT_BORDER_STYLE)
              self.GroupBorderSpace(left=5, top=5, right=5, bottom=5)
              self.AddStaticText(self.gui_id + 1 , flags=c4d.BFH_LEFT | c4d.BFV_TOP | c4d.BFH_FIT | c4d.BFV_FIT, name=self._material)
              #self.AddStaticText(self.gui_id + 2 , flags=c4d.BFH_LEFT | c4d.BFV_TOP | c4d.BFH_FIT | c4d.BFV_FIT, name=self.gui_id)
              self.AddMultiLineEditText(self.gui_id + 3, flags=c4d.BFH_LEFT | c4d.BFV_TOP | c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, initw=0, inith=0, style=0)
              self.SetString(self.gui_id + 3, value=self._parts)
              self.GroupEnd()
              #for i, parts in enumerate(self._parts):
              #    self.AddStaticText(self.gui_id + i, c4d.BFH_SCALEFIT, name=parts)
              return True
      
      
      class MyDialog(c4d.gui.GeDialog):
      
          def __init__(self, items=[]):
      
              # this is from the linkbox example from ferdinand
              super(MyDialog, self).__init__() 
      
              # will be link box
              self._items = [] 
              self._doc = None 
              self._hasCreateLayout = False
              self.Items = items
      
              self._quickTab = None  # Stores the quicktab custom GUI
              self._tabList = OrderedDict()  # Stores the TabName and the SubDialog that represents each tab of the QuickTab
      
          def _DrawQuickTabGroup(self):
              """ Creates and draws all the SubDialog for each tab, 
                  take care it does not hide these according to a selection state.
      
              Returns: 
                  True if success otherwise False.
              """
      
              # Checks if the quicktab is defined
              if self._quickTab is None:
                  return False
      
              # Flush the content of the group that holds all ours SubDialogs
              self.LayoutFlushGroup(ID_MAINGROUP)
              #self.GroupBorderSpace(left=5, top=5, right=5, bottom=5)
      
              # Iterates over the number of tab to create and attach the correct SubDialog
              for tabId, (tabName, tabGui) in enumerate(self._tabList.items()):
                  self.AddSubDialog(ID_QUICKTAB_BASE_GROUP + tabId, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 0, 0)
                  self.AttachSubDialog(tabGui, ID_QUICKTAB_BASE_GROUP + tabId)
      
              # Notifies the content of the MainGroup has changed
              self.LayoutChanged(ID_MAINGROUP)
      
              return True
      
      
          def GetActiveTabs(self):
              """Retrieves two list of currently selected tabs from the self._quickTab.
      
              Returns:
                  list(int), list(name): The first list, contains tabs Id (from self._quickTab the dict) and the second list contains all names of the selected tabs.
              """
              # Checks if the quicktab is defined
              if self._quickTab is None:
                  return False, False
      
              returnIds = []
              returnNames = []
      
              for tabId, (tabName, tabGui) in enumerate(self._tabList.items()):
                  if self._quickTab.IsSelected(tabId):
                      returnIds.append(tabId)
                      returnNames.append(tabName)
      
              return returnIds, returnNames
      
      
          def DisplayCorrectGroup(self):
              """Hides all unused groups and display the correct one.
      
              Returns: 
                  True if success otherwise False.
              """
              # Retrieves the selected tab
              activeIds, activeNames = self.GetActiveTabs()
              
              print("Display Correct Group")
              print(activeIds)
      
              # Iterates each CustomGui and defines if they are hidden or not
              for tabId in range(len(self._tabList)):
                  toDisplay = tabId in activeIds
                  #print("activeIds: ", activeIds, "current: ", ID_QUICKTAB_BASE_GROUP, tabId, " -> toDisplay: ", toDisplay)
                  self.HideElement(ID_QUICKTAB_BASE_GROUP + tabId, not toDisplay)
      
      
              # Notifies the content of the MainGroup has changed
              self.LayoutChanged(ID_MAINGROUP)
              
              return True
      
          def AppendTab(self, tabName, content, active=True):
              """Appends a tab to the current quicktab with the associated content to be displayed.
      
              Args:
                  tabName (str): The name the tab should have.
                  content (c4d.gui.SubDialog): The SubDialog to be drawn/linked when the tab is selected.
                  active (bool, optional): If True, the inserted tab will be selected. Defaults to True.
      
              Returns:
                  True if success otherwise False.
              """
              # Checks if the quicktab is defined
              if self._quickTab is None:
                  return False
      
              # Adds the tab entry n the quicktab
              self._quickTab.AppendString(len(self._tabList), tabName, active)
      
              # Updates our current tabList with tabName and the Subdialog to be linked
              self._tabList.update({tabName: content})
      
              """ I uncommented below because it resulted in a lot of gui calls 
                  It seems to work fine just calling self.DisplayCorrectGroup() at the right places
                  not inside here hence this functionis called for each tab
              """
      
              # Retrieves the current selected tab
              #previousActiveId, previousActiveName = self.GetActiveTabs()
      
              # Draws the quicktab SubDialog (in order to have the new one drawn)
              #self._DrawQuickTabGroup()
      
              # Defines the just added tab according state
              #self._quickTab.Select(len(self._tabList) - 1, active)
      
              # Defines previous active tab
              #for tabId in previousActiveId: self._quickTab.Select(tabId, True)
      
              # Display only the selected tab and hides all others
              #self.DisplayCorrectGroup()
      
              return True
      
          def FlushAllTabs(self):
              """Removes all tabs and their content from the GUI.
      
              Returns: 
                  True if success otherwise False.
              """
              # Checks if the quicktab is defined
              if self._quickTab is None:
                  return False
      
              # Removes all the tabs
              self._quickTab.ClearStrings()
      
              # Removes all the customGui
              for tabId in range(len(self._tabList)):
                  self.RemoveElement(ID_QUICKTAB_BASE_GROUP + tabId)
      
              # Reinitializes the stored tablist to an empty dict
              self._tabList = OrderedDict()
      
              # Flush the content of the group that holds all ours SubDialogs
              self.LayoutFlushGroup(ID_MAINGROUP)
              # Notifies the content of the MainGroup has changed
              self.LayoutChanged(ID_MAINGROUP)
      
              return True
      
          def RemoveTab(self, tabNameToRemove):
              """Removes a tab by its name
      
              Args:
                  tabNameToRemove (str): The tab to remove.
      
              Returns:
                  True if success otherwise False.
              """
              # Checks if the quicktab is defined
              if self._quickTab is None:
                  return False
      
              # Copies the tabList
              newDict = OrderedDict(self._tabList)
      
              # Checks if the entry exist
              if tabNameToRemove not in newDict:
                  return True
      
              # Removes the entry we want to delete
              del newDict[tabNameToRemove]
      
              # Removes all groups
              self.FlushAllTabs()
      
              # Re-adds all the one from our copy
              for tabName, tabGui in newDict.items():
                  self.AppendTab(tabName, tabGui)
      
              return True
      
          def CreateLayout(self):
              """This Method is called automatically when Cinema 4D Create the Layout (display) of the Dialog."""
      
              # Creates a QuickTab Custom Gui
              bc = c4d.BaseContainer()
              bc.SetInt32(c4d.QUICKTAB_BAR, 0) # (0=off, 1=on, 2=non-bold, 3=special separator look)
              bc.SetString(c4d.QUICKTAB_BARTITLE, "Title")
              bc.SetBool(c4d.QUICKTAB_SPRINGINGFOLDERS, True) # if we can get link fields usefull
              bc.SetBool(c4d.QUICKTAB_SHOWSINGLE, False)
              bc.SetBool(c4d.QUICKTAB_NOMULTISELECT, False)
              bc.SetBool(c4d.QUICKTAB_SEPARATOR, True)
      
              self.GroupBegin(next(plusone_id()), c4d.BFH_SCALEFIT | c4d.BFV_TOP | c4d.BFV_FIT, 0, 0, 'ID_QUICKTAB_BAR', 0)
              #self.GroupBorderNoTitle(borderstyle=DEFAULT_BORDER_STYLE)
              self.GroupBorder(DEFAULT_BORDER_STYLE)
              self.GroupBorderSpace(left=5, top=5, right=5, bottom=5)
              self._quickTab = self.AddCustomGui(ID_QUICKTAB_BAR, c4d.CUSTOMGUI_QUICKTAB, 'the tabs', c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 0, 0, bc)
              #self.AddStaticText(id=next(plusone_id()), flags=c4d.BFV_CENTER | c4d.BFV_SCALE | c4d.BFH_CENTER | c4d.BFH_SCALE, name="tabs")
              #print("layout cusrom gui: ", self._quickTab)
              self.GroupEnd()
      
              # Creates a group that will contain all the group representing each tab
              self.GroupBegin(ID_MAINGROUP, flags=c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=10, rows=10, title='ID_MAINGROUP')
              #self.GroupBorderNoTitle(borderstyle=DEFAULT_BORDER_STYLE)
              self.GroupBorder(DEFAULT_BORDER_STYLE)
              self.GroupBorderSpace(left=5, top=5, right=5, bottom=5)
              self.AddStaticText(id=next(plusone_id()), flags=c4d.BFV_CENTER | c4d.BFV_SCALE | c4d.BFH_CENTER | c4d.BFH_SCALE, name="main")
              self.GroupEnd()
              
              # dummy group to spread vertically
              if self.GroupBegin(id=next(plusone_id()),  flags=c4d.BFH_FIT | c4d.BFV_FIT): #cols=1, rows=1,
                  self.GroupBorderSpace(left=0, top=0, right=0, bottom=0)
                  self.GroupBorderNoTitle(borderstyle=DEFAULT_BORDER_STYLE)
                  self.AddStaticText(id=next(plusone_id()), flags=c4d.BFV_CENTER | c4d.BFV_SCALE | c4d.BFH_CENTER | c4d.BFH_SCALE, name="")
                  self.GroupEnd()
      
              # Creates a group with button in order to do some operation with the QuickTab CustomGUI
              if self.GroupBegin(next(plusone_id()), c4d.BFH_SCALEFIT | c4d.BFV_BOTTOM, 4, 1, '', 0):
                  self.AddButton(ID_LOADDEFAULT_MAT_ASIGN, c4d.BFH_SCALEFIT, name="Populate")
                  self.AddButton(BUTTON_PRINT_TEXT, c4d.BFH_SCALEFIT, name="Print text")
                  self.AddButton(BUTTON_PRINT_SELECTED, c4d.BFH_SCALEFIT, name="Print Selected")
                  self.AddButton(BUTTON_FLUSH_ALL, c4d.BFH_SCALEFIT, name="Flush All")
                  #self.AddButton(BUTTON_ADD, c4d.BFH_SCALEFIT, name="Add")
                  #self.AddButton(BUTTON_REMOVE, c4d.BFH_SCALEFIT, name="Remove")
                  self.GroupEnd()
              
              return True
      
          def InitValues(self):
              """This Method is called automatically after the GUI is initialized."""
              # Creates the first Tab
              #cg1 = CustomGroup(["This is the first Tab", "Just dummy text here"])
              #self.AppendTab("First Tab", cg1, True)
      
              # Creates the second Tab
              #cg2 = CustomGroup(["This is the second Tab", "Just another dummy text here"])
              #self.AppendTab("Second Tab", cg2, False)
              #return True
          
              return super(MyDialog, self).InitValues()
      
          def Command(self, id, msg):
              """This Method is called automatically when the user clicks on a gadget and/or changes its value this function will be called.
               It is also called when a string menu item is selected.
      
              Args:
                  id: The ID of the gadget that triggered the event.
                  msg: The original message container
      
              Returns:
                  False if there was an error, otherwise True.
              """
      
              # If the user interacts with the quicktab, we make sure to display the CustomGUI linked to the active one
              if id == ID_QUICKTAB_BAR and self._quickTab:
                  print("user interacted with tab")
                  self.DisplayCorrectGroup()
                  c4d.EventAdd()
                  return True
      
              # Displays all the Tab name
              if id == BUTTON_PRINT_TEXT:
                  print([key for key in self._tabList])
                  return True
      
              # Displays the ID and name of the selected tab
              if id == BUTTON_PRINT_SELECTED:
                  print(self.GetActiveTabs())
      
              # Removes all tabs
              if id == BUTTON_FLUSH_ALL:
                  self.FlushAllTabs()
      
              """        
              # Adds a new Tab to the quicktab
              if id == BUTTON_ADD:
                  cg3 = CustomGroup(["This is the third Tab"])
                  self.AppendTab("Third Tab", cg3, True)
      
              # Removes the first tab of the quicktab
              if id == BUTTON_REMOVE:
                  self.RemoveTab("First Tab")
              """
      
              if id == ID_LOADDEFAULT_MAT_ASIGN:
                  self.Populate()
      
              return True
          
      
          def Populate(self):
              doc = c4d.documents.GetActiveDocument()
              directory, _ = os.path.split(__file__)
              poart_json_file = os.path.join(directory, "default_asignment.json")
              material_ids, materials_dict = read_parts_json(poart_json_file)
      
              self.FlushAllTabs() # clear the GUI
      
              print( str( material_ids))
              print("-"*80)
              
              offset=0
              
              for material_id in materials_dict:
                  part_list = materials_dict[material_id]
      
                  #print( str(material_id), str(part_list) )
      
                  ### Tabs
                  ##############################################
                  
                  tab_Content = CustomGroup(str(material_id), part_list, offset)
                  self.AppendTab(str(material_id), tab_Content, True)
                  offset += 10
              
              print("-"*80)
              self._DrawQuickTabGroup()
              c4d.EventAdd()    
            
      
      # Main function
      def main():
          
          if DEBUG:
              c4d.CallCommand(13957)  # clear console
          
          # Initializes a QuickTabDialogExample Dialog
          diag = MyDialog()
      
          # Opens the Dialog in modal mode
          diag.Open(dlgtype=c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=960, defaulth=600)
      
      
      # Execute main()
      if __name__ == '__main__':
          main()
      
      posted in Cinema 4D SDK
      M
      mogh
    • RE: How to create UV of obj.

      I use this to Thank You Ferdinand.

      This is how I imagine an SDK example should look like .... a simplest version , an altered simple version and a complex touching the boundaries of the subject.
      I am thankful and praise your work .... !

      cheers mogh

      posted in Cinema 4D SDK
      M
      mogh

    Latest posts made by mogh

    • RE: VS Code -> Cinema 4D Connector -> Agent

      I guess I asked a question I do not have the knowledge yet 😉

      In my ideal world:
      Agent -> python code -> plugin runs with console output (in the future executed by mcp) -> agents sees console output -> fixes bugs or verifies its code

      I also just could activate *.log writing and save the log in the repo ...

      thank you for your answer

      posted in General Talk
      M
      mogh
    • VS Code -> Cinema 4D Connector -> Agent

      Dear Developers,

      is it possible to provide Agents access to the Connector Debug output inside VScode ?
      running at ws://ip:port

      inside means not special tools or ports ... I have limited access to the machine.
      thank you

      posted in General Talk programming
      M
      mogh
    • RE: Performance / Viewport refresh Problems in 2026 - 2027.0.0

      I changed my message and mode functions to only react if the tool is actively used.
      it seems before 2026 and 2027 releases cal message / GetState calls where not that frequent or where blocked catched somewhere .... I can not explain the slowdown otherwise despite my poor coding. 😉

      I have not tested this extensively but my viewport stale / "freezes" are gone for now.

      anyway here are my methods if somebody finds it usefull:

      def GetState(self, doc):        
          if doc.GetMode() == c4d.Mpoints or doc.GetAction() == PLUGIN_ID:
              return c4d.CMD_ENABLED
          return False    
      
      def Message(self, doc, parameters, type, t_data)
          if type == c4d.MSG_DOCUMENT_MODE_CHANGED:
              if doc.GetMode() == c4d.Mpoints:
                  self.restore_xray_after_mode_change(doc)
              else:
                  self.suspend_xray_for_mode_change(doc, parameters)
              self.update_progressbar_help(doc)
              return None
          return True
      
      def FreeTool(self, doc, parameters):
          if self.status_help:
              c4d_progressbar(clear=True)
              self.status_help = None
          del self.lines[:]
          del self.arc_data[:]
          del self.movedpoints[:]
      
          self.parameters['optionkey'] = None
          self.xray_restore_link = None
          self.xray_mode_suspended = False
      
          self.xray_off(doc, parameters)
          return
      

      instead of reacting to messages the tool itsel checks:

      def Draw(self, doc, parameters, bd, bh, bt, flags):
             if doc.GetMode() != c4d.Mpoints:
                 return c4d.TOOLDRAW_NONE
      
      posted in Cinema 4D SDK
      M
      mogh
    • Performance / Viewport refresh Problems in 2026 - 2027.0.0

      Question: Did any implementation of GetState() , c4d.CMD_ENABLED GetMode() change in the SDK that i have to be aware of?

      I found a performance / Viewport update bug in my Plugin which was no bug in older C4D versions.
      These two methods make the viewport slow , and message "blocks" the update till i interact with the viewport.
      Tooldata - Point mode tool

      # Problematic in R2026
      def GetState(self, doc):
          if doc.GetMode() != c4d.Mpoints:
              c4d_progressbar(text="Go into Point Edit Mode!")
              return False
          elif len(doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)) != 1 : 
              c4d_progressbar(text="Only one Object allowed!")
              return False
          else:
              c4d_progressbar(clear=True)
          return c4d.CMD_ENABLED
      
      # Problematic in R2027
      
      def Message(self, doc, parameters, type, t_data):
          if doc.GetMode() != c4d.Mpoints:
              self.FreeTool(doc, parameters)
              return False
          return True
      

      thank you for your time
      mogh

      posted in Cinema 4D SDK 2026
      M
      mogh
    • RE: File import and doc merge -> InsertAfter or c4d.PREF_INTERFACE_I_BOTTOM

      Thank you all for your answers. Will test this.

      posted in Cinema 4D SDK
      M
      mogh
    • File import and doc merge -> InsertAfter or c4d.PREF_INTERFACE_I_BOTTOM

      Dear Team,
      I am trying to import files and place them in the object tree in the right order,

      i tried to set the preferences with c4d.PREF_INTERFACE_I_BOTTOM before import but it did not change my order.

              interface_preferences = c4d.GetWorldContainer()
              previous_insert_at = interface_preferences.GetInt32(c4d.PREF_INTERFACE_INSERTAT)
              interface_preferences.SetInt32(c4d.PREF_INTERFACE_INSERTAT, c4d.PREF_INTERFACE_I_BOTTOM, )
      

      Is there a convenient way or do i need to move the "node" manually to the bottom on each import ...
      or more universal for me is there a way to sort root nodes in the Object manager tree ? (only found an old coffee thread ... )
      thanks in advance ...
      mogh

      posted in Cinema 4D SDK python 2026
      M
      mogh
    • RE: TreeView DropDown Menu

      I am addiong to this thread hence it is related ... feel free to fork

      I am trying to only display a dropdown on certain rows ... is that possible ....?

      Here is a minimal dummy plugin where I only want to show the dropdown on "stp" files ....
      even though the dropdown gets no content it is still displayed ....

      thank you

      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:
      			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",
      		}
      		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
      		)
      
      	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
      
      
      class ListViewDropdownCommand(c4d.plugins.CommandData):
      	def __init__(self):
      		self.dialog = ListViewDropdownDialog()
      
      	def Execute(self, document):
      		return self.dialog.Open(
      			c4d.DLG_TYPE_ASYNC,
      			PLUGIN_ID,
      			defaultw=520,
      			defaulth=280,
      		)
      
      
      
      
      if __name__ == "__main__":
      	c4d.plugins.RegisterCommandPlugin(
      		id=PLUGIN_ID,
      		str=PLUGIN_NAME,
      		info=0,
      		icon=None,
      		help="TreeView dropdown.",
      		dat=ListViewDropdownCommand(),
      	)
      
      
      posted in Cinema 4D SDK
      M
      mogh
    • RE: Change render Space (Color Profile) - how?

      Ok i did not grasp that a node can also be an object ... thought about it as "texture node" ...
      There was no question ...

      I got doc[c4d.DOCUMENT_COLOR_MANAGEMENT] = c4d.DOCUMENT_COLOR_MANAGEMENT_BASIC

      to work but only after the document (new or freshly loaded) was rendered once .... did I find a bug or do i have to "save" the render / color settings after setting up ....

      I tried to insert an c4d.EventAdd() here and there but nothing helped ...

      executing / rendering a second time is totally fine ... !

              def colorspace(self, doc, rd, revert=False):
              #### Convert Color Space
              # 0 = c4d.DOCUMENT_COLOR_MANAGEMENT_BASIC = Legacy sRGB Linear
              # 1 = ACEScg
              # ['ACES2065-1', 'ACEScg', 'scene-linear DCI-P3 D65', 'scene-linear Rec.709-sRGB', 'scene-linear Rec.2020']
              
              # ATM this does not convert anything it just sets the C4D DOCUMENT_COLOR_MANAGEMENT to the legacy mode and back
      
              if self.IsForceLinear is True:
                  rd[c4d.RDATA_IMAGECOLORPROFILE] = c4d.bitmaps.ColorProfile.GetDefaultLinearRGB()
                  rd[c4d.RDATA_FORMATDEPTH] = 2 # 0=8Bit 1=16Bit 2=32bit
              else:
                  rd[c4d.RDATA_IMAGECOLORPROFILE] = c4d.bitmaps.ColorProfile.GetDefaultSRGB()
                  rd[c4d.RDATA_FORMATDEPTH] = 0
      
              print("Image:", rd[c4d.RDATA_IMAGECOLORPROFILE])
      
              ### Set Render Color Bit to 32 Bit
              doc[c4d.DOCUMENT_COLORPROFILE] = 1 # 0 sRGB 1 Linear 2 deactivated
      
              if c4d.GetC4DVersion() >= 250020:
                  if revert==True:
                      print("Revert Color Space triggered")
                      
                      doc[c4d.DOCUMENT_COLOR_MANAGEMENT] = 1 # 1 = ACEScg
                      pass
      
                  else:
                      print("Convert Color Space triggered")
                      if doc[c4d.DOCUMENT_COLOR_MANAGEMENT] == c4d.DOCUMENT_COLOR_MANAGEMENT_BASIC:
                          print("The document is already in basic mode.")
                      else:
                          print("Current Render Color Space: ",doc.GetOcioRenderingColorSpaceNames()[doc[c4d.DOCUMENT_COLOR_MANAGEMENT]])
                          doc[c4d.DOCUMENT_COLOR_MANAGEMENT] = c4d.DOCUMENT_COLOR_MANAGEMENT_BASIC
      
                      if doc[c4d.DOCUMENT_COLOR_MANAGEMENT] == c4d.DOCUMENT_COLOR_MANAGEMENT_BASIC:
                          print("-> Set to Basic Mode")
      
                      doc.ExecutePasses(
                          bt=None,
                          animation=False,
                          expressions=True,
                          caches=True,
                          flags=c4d.BUILDFLAGS_NONE
                      )
      
              c4d.EventAdd()
      

      thank you for your time and patience ...

      posted in Cinema 4D SDK
      M
      mogh
    • RE: Change render Space (Color Profile) - how?

      ok, no node here ...

      Objectcolor [c4d.ID_BASEOBJECT_COLOR] Vector(0.001, 0, 0.021) -> rendering pixelcolor should be Vector(0.001, 0, 0.021)

      Somewhere my colors are "transformed" I have to systematically rebuild it to find the "conversions" .... and how to prevent them ...

      posted in Cinema 4D SDK
      M
      mogh
    • RE: Change render Space (Color Profile) - how?

      Thank you,

      I guess i have to rewrite the color creation and profile settings of my plugin ... too many "this seemed to work sometime" code bits 😉

      posted in Cinema 4D SDK
      M
      mogh