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

    How to weld two points to the last selected point?

    Cinema 4D SDK
    windows s26 2023 python
    2
    5
    916
    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.
    • G
      Gaal Dornik
      last edited by

      Hello, currently this code welds two points in the middle, but i want it to weld to the last selected point, setting MDATA_WELD_TOPOINT to True doesn't help. How to solve this?

      import c4d, sys
      
      
      #
      # M A I N
      #
      def main():
          doc = c4d.documents.GetActiveDocument()
      
          settings = c4d.BaseContainer()
          settings[c4d.MDATA_WELD_TOPOINT] = True
          
          result = c4d.utils.SendModelingCommand(
                          command=c4d.ID_MODELING_WELD_TOOL,
                          list=[op],
                          mode=c4d.MODELINGCOMMANDMODE_POINTSELECTION,
                          bc=settings,
                          doc=doc,
                          flags=c4d.MODELINGCOMMANDFLAGS_CREATEUNDO)
      
          if not result:
              raise RuntimeError(f"Modelling command failed for {op}.")
      
          # Inform Cinema 4D that the document has been modified.
          c4d.EventAdd()
      
      
      # Execute main()
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • G Gaal Dornik deleted this topic on
      • ferdinandF ferdinand restored this topic on
      • i_mazlovI
        i_mazlov
        last edited by i_mazlov

        Hi @Gaal-Dornik ,

        Sorry for the delayed answer.

        The welding command was already comprehensively explained by Riccardo in this thread: ID_MODELING_WELD_TOO - Doesn't work [SOLVED].

        In addition, the undo issue was discussed in the following thread: Problem on AddUndo and SendModellingCommand (Weld Tool)

        As a compilation of both answers you can find the following code snippet (below) that welds currently selected points to the point with index pointIdx.

        Cheers,
        Ilia

        import c4d
        
        def main():
            doc = c4d.documents.GetActiveDocument()
            op = doc.GetActiveObject()
        
            pointIdx = 2  # FIXME: put here the index of the point you'd like to weld to'
        
            settings = c4d.BaseContainer()
            settings[c4d.MDATA_WELD_TOPOINT] = True
            settings[c4d.MDATA_WELD_POINTINDEX] = 2
            settings[c4d.MDATA_WELD_OBJECTINDEX] = op
            
            doc.StartUndo()
            doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
            
            result = c4d.utils.SendModelingCommand(
                            command=c4d.ID_MODELING_WELD_TOOL,
                            list=[op],
                            mode=c4d.MODELINGCOMMANDMODE_POINTSELECTION,
                            bc=settings,
                            doc=doc,)                
            doc.EndUndo()
            c4d.EventAdd()
        
        if __name__=='__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        G 1 Reply Last reply Reply Quote 0
        • G
          Gaal Dornik @i_mazlov
          last edited by

          @i_mazlov

          The problem with this code - it doesn't always work correctly. Sometimes it's not taking into account selection order - welds to the first selected point for example. Look at this preview.

          import c4d
          
          def main():
              doc = c4d.documents.GetActiveDocument()
              op = doc.GetActiveObject()
          
              lastPoint = op.GetPointS().GetLastElement()
          
              settings = c4d.BaseContainer()
              settings[c4d.MDATA_WELD_TOPOINT] = True
              settings[c4d.MDATA_WELD_POINTINDEX] = lastPoint
              settings[c4d.MDATA_WELD_OBJECTINDEX] = op
              
              doc.StartUndo()
              doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
              
              result = c4d.utils.SendModelingCommand(
                              command=c4d.ID_MODELING_WELD_TOOL,
                              list=[op],
                              mode=c4d.MODELINGCOMMANDMODE_POINTSELECTION,
                              bc=settings,
                              doc=doc,)                
              doc.EndUndo()
              c4d.EventAdd()
          
          if __name__=='__main__':
              main()
          
          G 1 Reply Last reply Reply Quote 0
          • G
            Gaal Dornik @Gaal Dornik
            last edited by

            Considering this thread it looks like getting points selection order is not trivial task for c4d api.

            1 Reply Last reply Reply Quote 0
            • i_mazlovI
              i_mazlov
              last edited by

              Yes, you found the thread about point selection just right!

              MAXON SDK Specialist
              developers.maxon.net

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