Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    LayoutFlushGroup Causes Unexpected Changes in Another Group

    Cinema 4D SDK
    2025 python windows
    2
    3
    191
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Amazing_iKeA
      Amazing_iKe
      last edited by

      Hello,

      I’m encountering an issue when I call self.LayoutFlushGroup(self.SHOT_LIST_GROUP).

      After using this function to clear the SHOT_LIST_GROUP, another group in my layout, self.FOOTAGE_GROUP (with its own ID), unexpectedly changes its appearance or position.

      Image 1: This shows the layout before calling LayoutFlushGroup. Everything looks correct.

      Image 2: This shows the layout after calling LayoutFlushGroup. You can see that FOOTAGE_GROUP has changed unexpectedly.

      Has anyone experienced something similar? I suspect there may be some dependency between groups or an issue with how the layout hierarchy is managed.

      I would really appreciate any insights, suggestions, or recommended best practices to clear and rebuild a group safely without affecting unrelated groups.

      Thank you very much for your time and help!

      11194998c263410a9f84fe67678e8f46.png

      be56452df3564bf0f6c8fb7f88308f94.png

          # 添加位图卡片
          def add_bitmap_card(self, uid : int, path : str, display : str= ''):
              ua = KidooShotManagerUserArea()
              ua.load_card(path, display)
              self.bitmapItems.append(ua)
              self.AddUserArea(uid, c4d.BFH_LEFT | c4d.BFV_TOP)
              self.AttachUserArea(ua, uid)
              return ua
      
          # 创建Kidoo镜头管理器
          def redrawAllKidooShotCards(self):
      
              self.LayoutFlushGroup(self.SHOT_LIST_GROUP)  # 删除组内容
      
              if self.GroupBegin(self.ID_GROUP_UA_REDRAW, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=0, rows=2,
                                 title='重绘卡片组', initw=0, inith=0):
                  for i in range(10):
                      # 加载缩略图
                      self.add_bitmap_card(uid=self.SHOT_MANAGER_USER_AREA + i,
                                           path=r'C:\Users\19252\Desktop\test_image\Anime 3840x2160 BOCCHI THE ROCK! Ryo Yamada Gotou Hitori Nijika I.png',
                                           display='#0001')
      
      
                  self.GroupEnd()  # 明确对应结束此分组
      
              self.LayoutChanged(self.FOOTAGE_GROUP)
              self.LayoutChanged(self.SHOT_MANAGER_GROUP)
          # <<<<<<<<<<<<<<<<<Kidoo镜头管理器内容区域>>>>>>>>>>>>>>>>>>>>
      
          # 创建Layout 布局函数
          def CreateLayout(self):
              # 窗口初始化设置
              self.SetTitle('Kidoo-场景管理器' + f' V.{self.WINDOW_VERSION}' )
      
              # 创建Menu 菜单
              self.CreateMenu()
      
              # 创建完Menu后,刷新镜头数据
              self.Refresh_Kidoo_Shot_Data()
      
              # 总体布局
              if self.GroupBegin(self.MAIN_GROUP, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=0, rows=0,
                                  title="Kidoo-场景装配器",initw=0, inith=0, groupflags=c4d.BFV_GRIDGROUP_ALLOW_WEIGHTS):
      
                  # ——— 第一次打开时,初始化主组左右列权重:30% / 70% ———
                  if not hasattr(self, 'main_weights_saved'):
                      # 创建一个 BaseContainer 用于保存主布局的列权重
                      self.main_weights = c4d.BaseContainer()
                      # 告诉 C4D 这是两列的权重设置
                      self.main_weights.SetInt32(c4d.GROUPWEIGHTS_PERCENT_W_CNT, 2)
                      # 设置第一列占比:30%
                      self.main_weights.SetFloat(c4d.GROUPWEIGHTS_PERCENT_W_VAL + 0, 30.0)
                      # 设置第二列占比:70%
                      self.main_weights.SetFloat(c4d.GROUPWEIGHTS_PERCENT_W_VAL + 1, 70.0)
                      # 标记已初始化,后续就不会重复设置默认值
                      self.main_weights_saved = True
      
                  # 每次布局时,将保存的权重加载到 MAIN_GROUP 上,以保持用户上次的拖拽状态
                  self.GroupWeightsLoad(self.MAIN_GROUP, self.main_weights)
      
                  # ——— 左边组:FOOTAGE_GROUP ———
                  if self.GroupBegin(self.FOOTAGE_GROUP, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=0, rows=2,
                                  title="镜头",initw=100, inith=0):
                      border_space_pixels = 3
                      self.GroupBorderSpace(border_space_pixels, border_space_pixels, border_space_pixels,
                                            border_space_pixels)  # 设置边框空间
                      self.GroupBorderNoTitle(c4d.BORDER_BLACK | c4d.BORDER_ACTIVE_1)
      
                      # 创建控件
                      self.Kidoo_Shot_Manager_Title()
      
                      # 列表卡片图片
                      if self.ScrollGroupBegin(id=self.SHOT_LIST_GROUP,
                                               flags=c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT,
                                               scrollflags=c4d.SCROLLGROUP_VERT,
                                               initw=0,
                                               inith=0):
                          self.GroupSpace(10, 10)
                          self.GroupBorderNoTitle(c4d.BORDER_ACTIVE_4)
                          self.GroupBorderSpace(5, 5, 5, 5)
      
                          self.redrawAllKidooShotCards()
      
                      self.GroupEnd()
                  self.GroupEnd()
      
                  # ——— 右边组:TAB_GROUP(包含多个子 Tab) ———
                  if self.TabGroupBegin(self.TAB_GROUP , c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, c4d.TAB_TABS):
                      border_space_pixels = 3
                      self.GroupBorderSpace(border_space_pixels, border_space_pixels, border_space_pixels, border_space_pixels)  # 设置边框空间
                      self.GroupBorder(c4d.BORDER_BLACK | c4d.BORDER_ACTIVE_1)
      
                      # 创建SHOP组
                      if self.GroupBegin(id= self.SCENE_BUILDER_GROUP, flags=c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=1, rows=0,
                                         title="场景装配", initw=0, inith=0):
                          # 创建控件
                          self.Kidoo_Scene_Builder_Title()
                          self.Kidoo_Scene_Builder_Set_Scene()
                          # self.Kidoo_Scene_Builder_Camera()
                          # self.Kidoo_Scene_Builder_Asset()
      
                      self.GroupEnd()
      
                      # 创建SHOP组
                      if self.GroupBegin(id= self.SHOP_GROUP, flags=c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=0, rows=0,
                                         title="镜头", initw=0, inith=0):
                          ...
      
      
      
      
                      self.GroupEnd()
                      # 创建Asset组
                      if self.GroupBegin(id=self.ASSET_GROUP, flags=c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=0, rows=0,
                                         title="资产", initw=0, inith=0):
      
                          ...
      
      
                      self.GroupEnd()
                  self.GroupEnd()
              self.GroupEnd()
      
              return True
      
      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hey @Amazing_iKe,

        thank you for reaching out to us. With the 2025.3.0 SDK, I just published some new GUI examples, including py-cmd_gui_dynamic_2024, which does exactly what you want to do here.

        Without executable code I can only guess (please also keep in mind that we cannot debug full projects for users, for complex issues you should write a boiled down version). But when I look at your code two things stand out to me:

        1. Unlikely my code example, you already flush your layout when it is created as your CreateLayout just calls redrawAllKidooShotCards() which then calls self.LayoutFlushGroup(self.SHOT_LIST_GROUP) but that group has not yet been closed at that point in CreateLayout.
        2. You try to flush a ScrollGroup and not a Group. They are quite similar, but I am not 100% sure that scroll groups support flushing. That would be at least the first thing I would try when I encounter problems. The fix is simple: Just add a normal group there and then in the dynamic content, simple nest a scroll group into it as the root element.
        3. When FOOTAGE_GROUP would be a child of SHOT_LIST_GROUP, that would of course also explain it, but it is actually the other way around FOOTAGE_GROUP is the parent. The insertion pointer might be faulty in your case because due to (1) you flush your SHOT_LIST_GROUP before it has been fully created, and then the insertion pointer might accidently leak into the parent group or so.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        Amazing_iKeA 1 Reply Last reply Reply Quote 1
        • Amazing_iKeA
          Amazing_iKe @ferdinand
          last edited by

          @ferdinand Thank you very much for your response and suggestions.

          I’ll make sure to follow best practices and provide a minimal, testable code sample when posting questions in the future. I’ll also give embedding a group a try.

          Thanks again for your support!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post