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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    select objects one by one

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 610 Views
    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.
    • H Offline
      Helper
      last edited by

      On 09/11/2016 at 07:08, xxxxxxxx wrote:

      Is it possible to select objects one by one?

      I want that because i want  the script to select 1st object,do something(a code which i will put there)
      than 2nd one - do that something,3rd and so one.

      Here is my problem:

      I have let's say a bunch of cubes and i want to transform in shapes like these ones

      https://s17.postimg.org/fbq0nogov/image.jpg

      I have this code for point selection by index

      import c4d
      #Welcome to the world of Python
      
      
      def main() :
          PointList=[1,3,7]
          #base_select_object
          obj = op.GetObject()
          points =obj.GetPointS()
          for i in PointList :
              points.Select(i)
      

      unfortunately this works now only for python tag,I understand that is better in this case to make it work through Script Manager,but i don't know how to make it work there
      Someone suggested that I would have to put these lines above the code

      objects = doc.GetActiveObjects(1)**

      **
      for a in objects :**

      **
      So the steps would be the script first to select the points 1 and 3,Weld them and then points 5 and 7,Weld them also

      But now it selects the points from all cubes and weld them all together,like this

      https://s12.postimg.org/gw5toqytp/image.jpg

      PS:Can I upload images here only by Url?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 09/11/2016 at 11:35, xxxxxxxx wrote:

        It doesn't seem like the weld command can be called programmatically as it requires user input to decide which point "wins" in the welding. I've implemented what you described as a script that uses the Optimize command to get the same effect as the weld command.

          
        """Weld Cube Points   
        Welds cube points together.   
          
        Usage Instructions:   
        1. Create some cubes.   
        2. Make them editable   
        3. Run this script.   
        """   
          
        import c4d   
          
        def SquishPoints(cube) :   
            """Welds the top 4 points of a polygon Cube."""   
               
            if (cube is None) or (not cube.IsInstanceOf(c4d.Opolygon)) :   
                return   
          
            points = cube.GetAllPoints()   
            point_id_groups = [[1,3],[5,7]] # Split into sub-lists so each can be welded in turn.   
               
            # Go through each set of points to weld.   
            for point_id_group in point_id_groups:   
                # Weld command isn't easily called via script, so we'll move the points we want to weld   
                # to the same position, then call the Optimize command.   
                  
                # Calculate the center of the points   
                point_position_sum = c4d.Vector(0.0)   
                for point_id in point_id_group:   
                    point_position_sum += points[point_id]   
                       
                number_of_points = len(point_id_group)   
                center_point = point_position_sum / number_of_points   
                  
                # Move points to the center   
                for point_id in point_id_group:   
                    points[point_id] = center_point   
          
            # Store the changed points   
            cube.SetAllPoints(points)   
          
        def main() :   
            # Get a list of active objects.   
            active_objects = doc.GetActiveObjects(flags=c4d.GETACTIVEOBJECTFLAGS_0)   
               
            # Start recording changes you'll later want to undo.   
            doc.StartUndo()   
               
            # Squish together the points for all selected objects   
            for obj in active_objects:   
                doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)   
                SquishPoints(obj)   
               
            # Use the optimize command to weld them   
            c4d.CallCommand(14039, 14039) # Optimize...   
               
            # Let C4D know that something has happened and it should redraw.   
            doc.EndUndo()   
            c4d.EventAdd()   
               
        if __name__=='__main__':   
            main()   
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 09/11/2016 at 11:36, xxxxxxxx wrote:

          I've saved it as a GitHub Gist so it's easier to read:
          https://gist.github.com/donovankeith/3c30a5bb22e3ba0f99af5b6e5cc73aeb

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 09/11/2016 at 12:33, xxxxxxxx wrote:

            That's Awesome!!! Thank You Very Much!

            But can i ask you something more 🙂

            Can you do something like this

            https://s21.postimg.org/kdqrhl5hj/image.jpg

            or at least like this

            https://s18.postimg.org/a26qopc2x/image.jpg

            You know - I extruded the top polygon of the cube and then would follow the process from your script,obviously for right(different) points now - this is for the second image(simpler model)

            for the first image would be more steps:
            i selected left and right extruded polygons,disconnected them,
            then select the lower edges from these polygons,making the distance between them larger with scale tool
            after that,select the front and back edges from these polys and also make the same with scale tool

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 09/11/2016 at 12:36, xxxxxxxx wrote:

              You might want to look into c4d.utils.SendModelingCommand() to accomplish what you want.

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 09/11/2016 at 12:40, xxxxxxxx wrote:

                Ok Thank You again,I would look on this Command,but nothing promising from me,I'm very newbie

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