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
    S
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Best 1
    • Controversial 0
    • Groups 0

    SteveLim

    @SteveLim

    1
    Reputation
    8
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    SteveLim Unfollow Follow

    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

    Latest posts made by SteveLim

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

      Thank you for your reply. It seems the one thing I chose to try out is too big a mountain to climb for the forseeable future. I will keep at it and try to pick up snippets here and there from other useful threads.

      Thanks again for your patience and time.

      posted in General Talk
      S
      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
    • RE: Setting coordinates for selected faces (Python - Beginner)

      @SteveLim

      I found another thread where the code seems to work except its for World Space and also it affects all points as opposed to selected polys as in my use case.

      I tried my luck to modify the code using GetMl instead.. but no dice 😃

      def set_Y_vector(obj, value):
      
          oldLocalPoints = obj.GetAllPoints()
          obj_mat = obj.GetMg()
          inv_obj_mat = ~obj_mat
      
          # Non-preallocation penalty is neglectable 
          newLocalPoints = [] 
          for p in oldLocalPoints:
              # get the world position of the current point
              worldpoint = obj_mat * p
             # set the local position on the new point by setting the y-coordinate to the desired value and transform by the inverted matrix
              newLocalPoint = inv_obj_mat * c4d.Vector(worldpoint[0], value, worldpoint[2] )
              # just append
              newLocalPoints.append(newLocalPoint)
      
          # set the new points
          obj.SetAllPoints(newLocalPoints)
          
          # notify Cinema 
          obj.Message (c4d.MSG_UPDATE) 
          c4d.EventAdd()
      
      posted in General Talk
      S
      SteveLim
    • RE: Setting coordinates for selected faces (Python - Beginner)

      Thank you for replying.

      I spent the day looking at your code and other examples. Sad to say it seems I am in quite a bit in over my head.
      I was just trying to scale some selected polygons in the Y-Axis... I never knew it would be this complicated.

      It is indeed rather disheartening.. are there some beginner examples? I have seen many that try to move selected objects.. but hardly any with selected components + scaling.

      Appreciate any small example code.. hopefully I can deduce my way around it. 😰

      posted in General Talk
      S
      SteveLim
    • Setting coordinates for selected faces (Python - Beginner)

      Hi all,

      Just starting out with Python Coding in C4D.

      I have watched some tutorials and have basic code that can zero out objects etc.

          objList = doc.GetActiveObjects(True)
          for obj in objList:
              obj.SetRelPos(c4d.Vector(0,0,0))
          c4d.EventAdd()
      
      • I am looking to take the current selection of polygons.

      • set the current coordinate manager to world mode

      • set the size of them in a particular axis (y) to zero

      Thanks in advance for any help you can offer.

      posted in General Talk python
      S
      SteveLim