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
    1. Maxon Developers Forum
    2. SteveLim
    3. Best
    S
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Best 1
    • Controversial 0
    • Groups 0

    Best posts made by SteveLim

    • RE: Setting coordinates for selected faces (Python - Beginner)

      @zipit

      Thank you so much for this Zipit. I hope that I did undertstand some of the points made to an extent. For the purposes of learning, I tried to modify part2 and part3 such that the selected points were only scaling on the local Z for example.

      The code works however I had to do silly things - hack transforms of rotation and translation to zero manually to get them to play nice. (*hides). I suspect I am supposed to call direct the 'utils' for positioning directly instead of RotY first then inheriting it and setting transform.off and transform.v3 later.

      Utimately, I am trying to get a bunch of polygons (or points in your case) to be coplanar. My idea was to scale them to zero in their local Z axis (the selection's normal not the objects local Z). My current code is working except it is scaling the points to the local objects Z=0 insteal of the axis of the selection's normal .

      In my original post. I normally do this via GUI using a custom workplane set to selection whereby I can simple set size in Y to zero. The net effect is the same. ( I know I cannot do this so simply as the coordinate manager cannot be accessed directly)

      scale to 0

      
      def part_3():
      
          transform = c4d.utils.MatrixRotY(math.pi * 0)
          transform.off = c4d.Vector(0, 0, 0)
          transform.v3 *= 0
          points = op.GetAllPoints()
      
          selection = op.GetPointS()
          state = selection.GetAll(len(points))
          print "selection state:", state
      
          selected = [i for i, value in enumerate(state) if value]
          print "selected point ids:", selected
      
          for index in selected:
              points[index] *= transform
      
          op.SetAllPoints(points)
          op.Message(c4d.MSG_UPDATE)
          c4d.EventAdd()
      
      
      def main():
      
          if not isinstance(op, c4d.PolygonObject):
              msg = "Requires a PolygonObject. Received: {type}"
              raise TypeError(msg.format(type=type(op)))
      
      
          part_3()
      
      if __name__ == "__main__":
          main()
      
      posted in General Talk
      S
      SteveLim