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

    Setting `coordinate system` using `MCOMMAND_MIRROR`

    Cinema 4D SDK
    python r20
    2
    3
    1.1k
    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.
    • K
      kisaf
      last edited by kisaf

      Hi there, I'm trying to mirror object via SendModelingCommand(c4d.MCOMMAND_MIRROR, ..)
      But I cann't understand how to change a coordinate system.
      According to the documentation this options is called MDATA_MIRROR_SYSTEM and it's int type.
      Its description says Coordinate system. (See dialog.)
      I believe it is the dialog:
      0_1551264099400_mirror.PNG

      It seems like 0 means Object, 1 - World, 2 - Screen.
      I tried different values from 0 to 30, but it didn't take any effect.

      The code I'm using:

      settings = c4d.BaseContainer()
      settings[c4d.MDATA_MIRROR_SYSTEM] = 0
      
      res = utils.SendModelingCommand(c4d.MCOMMAND_MIRROR,
                                [obj],
                                c4d.MODELINGCOMMANDMODE_ALL,
                                settings,
                                doc)
      

      I cannot change MDATA_MIRROR_PLANE either.
      There is no additional information in the documentation.
      Drag'n'drop for these fields doesn't work. It's strange, because it works perfectly for other tools.

      I found this post (from 2011) https://developers.maxon.net/forum/topic/5497/5516_mirror-tool-bug
      It seems that bug is still alive 😞

      Version: R20
      Platform: Windows

      Cheers

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi @kisaf,

        MCOMMAND_MIRROR is indeed a bit special because when you click on the Apply button from the GUI, it does send a message to some c4d elements, then these elements read MDATA_MIRROR_VALUE, MDATA_MIRROR_SYSTEM and MDATA_MIRROR_PLANE calculates values for MDATA_MIRROR_POINT and MDATA_MIRROR_VECTOR and then call the SendModelingCommand. Unfortunately, there is no way for you to send this message, and the best way to do it is to recalculate the stuff as bellow.

        import c4d
        
        
        def main():
            # Checks if selected object is valid
            if op is None:
                raise ValueError("op is none, please select one object.")
        
            # Defines some general settings, take care MDATA_MIRROR_VALUE, MDATA_MIRROR_SYSTEM and MDATA_MIRROR_PLANE
            settings = c4d.BaseContainer()
            settings[c4d.MDATA_MIRROR_DUPLICATE] = True
            settings[c4d.MDATA_MIRROR_SELECTIONS] = True
            settings[c4d.MDATA_MIRROR_ONPLANE] = True
            settings[c4d.MDATA_MIRROR_WELD] = True
            settings[c4d.MDATA_MIRROR_TOLERANCE] = 0.01
        
            # Corresponds to MDATA_MIRROR_VALUE, MDATA_MIRROR_SYSTEM and MDATA_MIRROR_PLANE
            value = 1000.0
            system = 0 # 0 = Object, 1 = World
            plane = 1 # 0 = XY, 1 = ZY, 2 = XZ
        
            if not 0 <= system < 2:
                raise ValueError("System can only be 0 or 1")
        
            # Buffer position vector
            pos = c4d.Vector()
        
            # Calculates Local (Object) coordinates
            if system == 0:
                globalMatrix = op.GetMg()
                if plane == 0:
                    pos = globalMatrix.v3
                elif plane == 1:
                    pos = globalMatrix.v1
                elif plane == 2:
                    pos = globalMatrix.v2
        
                settings[c4d.MDATA_MIRROR_POINT] = globalMatrix.off + pos * value
                settings[c4d.MDATA_MIRROR_VECTOR] = pos
        
            # Calculates World coordinates
            elif system == 1:
                if plane == 0:
                    pos = c4d.Vector(0.0, 0.0, 1.0)
                elif plane == 1:
                    pos = c4d.Vector(1.0, 0.0, 0.0)
                elif plane == 2:
                    pos = c4d.Vector(0.0, 1.0, 0.0)
        
                settings[c4d.MDATA_MIRROR_POINT] = pos * value
                settings[c4d.MDATA_MIRROR_VECTOR] = pos
        
            # Send the Modeling Operation
            res = c4d.utils.SendModelingCommand(c4d.MCOMMAND_MIRROR,
                                                [op],
                                                c4d.MODELINGCOMMANDMODE_ALL,
                                                settings,
                                                doc)
        
            c4d.EventAdd()
        
        
        if __name__ == "__main__":
            main()
        
        

        Hope it solves your issue, if you have any question, please let me know.
        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        K 1 Reply Last reply Reply Quote 4
        • K
          kisaf @m_adam
          last edited by

          Hi @m_adam
          Thank you for your reply. It works perfectly!

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