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 keep the point coordinates of a polygonObject up to date in Python code

    General Talk
    python
    2
    3
    911
    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.
    • S
      SteveJLV
      last edited by

      Hello, I try to manipulate a polygon point in Python with the SetPoint() command.
      So for instance I want to double the Values for X,Y en Z of point[0] = testPnt (for instance Vector(1,1,1))
      I use the values of the point to double them. (I used the '×' to indicate multiplication the '*' messes up the post)
      op.SetPoint(0,c4d.Vector(testPnt.x×2,testPnt.y×2,testPnt.z×2))
      If later somewhere else in my code I change these values again, say I triple them
      op.SetPoint(0,c4d.Vector(testPnt.x×3,testPnt.y×3,testPnt.z×3))
      and print the values I still get the unchanged values. i.e. Vector(1,1,1)
      I want to get (6,6,6) at the end.

      Here my testing code:

      def main():
          op = doc.GetActiveObject() #select a polygon object with Point[0] at (1,1,1) as example
          puntenLijst = op.GetAllPoints()
          testPnt = puntenLijst[0]
          print 'pnt0 at start: ' ,testPnt     # check the coordinates before manipulation 
          *#prints: pnt0 at start: Vector(1,1,1) ok*
          op.SetPoint(0,c4d.Vector(testPnt.x*2,testPnt.y*2,testPnt.z*2))
          print 'pnt0 after SetPoint:' ,testPnt
          *#prints: pnt0 after SetPoint: Vector(1,1,1) not ok, got to send Message(c4d.MSG_UPDATE)*
          op.Message (c4d.MSG_UPDATE)
          print 'pnt0 after MSG_UPDATE' ,testPnt
          *#prints: pnt0 after MSG_UPDATE: Vector(1,1,1) not ok, got to do the c4d.EventAdd()*
          c4d.EventAdd()
          print 'pnt0 after c4d.EventAdd():' ,testPnt
          *#prints: pnt0 after c4d.EventAdd(): Vector(1,1,1) not ok, got to do ??*
          op.SetPoint(0,c4d.Vector(testPnt.x*3,testPnt.y*3,testPnt.z*3))
          print testPnt
          # hoping for Vector(6,6,6) but nope got Vector(1,1,1)
      

      finaly in the Structure Manager after running this code the point has coordinates (3,3,3) and not (6,6,6) the last SetPoint used the startingpoint(1,1,1) and I want to continue with the changed values i.e. (2,2,2)

      S 1 Reply Last reply Reply Quote 0
      • S
        SteveJLV @SteveJLV
        last edited by

        I figured out how to do it.

        It's fairly simple. I just have to reassing the pointvalues after the Update

        so if I insert a new

        puntenLijst = op.GetAllPoints()
        testPnt = puntenLijst[0]
        

        the 'testPnt' has updated values.

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

          Hi @SteveJLV welcome in the plugincafe community,

          I would like to point you to some rules:

          • Read Before Posting. Nothing wrong here, but just in case.
          • Q&A New Functionality. I've setup your topic correctly.

          As you already figured it out, you never assign a new value to the variable. In Python, everything is passed by value by default in 90% of the time.
          Meaning when you do x = y will actually copy y to x, so afterward if you do x + 10 it will not affect y value.

          If you have more questions, don't hesitate.
          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

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