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

    Spline linked to Polygon points?

    Scheduled Pinned Locked Moved PYTHON Development
    9 Posts 0 Posters 730 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

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 22/08/2012 at 17:10, xxxxxxxx wrote:

      Could anyone help me work out this simple problem I have. I'm obviously not getting something right?

      import c4d
      #Welcome to the world of Python
        
        
      def main() :
          ob = op.GetObject()    #Polygon Child
          spline = ob.GetUp()    #Spline Parent
        
          for i in xrange(spline.GetPointCount()) :
              polypoints = ob.GetPoint(i)
              point = c4d.Vector(polypoints.x, polypoints.y, polypoints.z)
              spline.SetPoint(i, point)
        
              ob.Message(c4d.MSG_UPDATE)
              c4d.EventAdd() 
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 23/08/2012 at 01:43, xxxxxxxx wrote:

        Do you call the main function with

        if __name__=='__main__':
            main()
        

        ?

        Why do you do

        ob = op.GetObject()
        

        ?

        Before the loop, you should resize the spline calling

        spline.ResizeObject(ob.GetPointCount())
        

        Also, you should loop over the polygon points

        for i in xrange(ob.GetPointCount())
        

        The c4d.MSG_UPDATE message has to be sent to the modified spline

        spline.Message(c4d.MSG_UPDATE)
        

        The update message sent to the spline and the global C4D event added should be sent once (not for each polygon point) after the loop.

        And to get a good result you can use c4d.utils.Neighbor class to get more information on the polygon points order, connections etc.

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 23/08/2012 at 13:08, xxxxxxxx wrote:

          Thank you for your reply Yannick.
          The script was on a python tag so thats why I did:

          ob = op.GetObject()
          

          Is that not right?

          I dont understand how once I looped through the polygon points I then go back and fix the spline points to them?
          I also tried the spline.Message(c4d.MSG_UPDATE) and just lost the spline out of the scene completely.

          This is the xpresso setup I am trying to convert into python basically as a 'learning from' exercise, but I am getting very lost.
          http://dl.dropbox.com/u/2802779/Xpresso_Setup.png

          This is where up to at the moment

          import c4d
          #Welcome to the world of Python
          #Python Tag on Polygon Child
            
          def main() :
              polygon = op.GetObject()    #Polygon Child with 17 points
              spline = polygon.GetUp()    #Spline Parent with 8 points
              spline.ResizeObject(spline.GetPointCount())
            
              for i in xrange(polygon.GetPointCount()) : #Get the 17 points of the polygon
                  polygonpoint = polygon.GetPoint(i)
                  point = c4d.Vector(polygonpoint.x, polygonpoint.y, polygonpoint.z)
                  
              for s in xrange(spline.GetPointCount()) : #Get the 8 points of the Spline
                  spline.SetPoint(s, point)
            
              spline.Message(c4d.MSG_UPDATE)
              c4d.EventAdd() 
            
          if __name__=='__main__':
              main()
          

          Would appreciate any further help.

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 23/08/2012 at 14:52, xxxxxxxx wrote:

            Hello hypoly,
            _
            spline.ResizeObject(spline.GetPointCount())_
            This doesn't make any sense and has no effect. Try to translate it into normal language and you'll understand why. "We will make the spline have as many points as it currently has." Huh?

            for i in xrange(polygon.GetPointCount()) : #Get the 17 points of the polygon
            You don't actually get all 17 points, you just iterate from 0 to 16.
            _
            for i in xrange(polygon.GetPointCount()) : #Get the 17 points of the polygon
              polygonpoint = polygon.GetPoint(i)
              point = c4d.Vector(polygonpoint.x, polygonpoint.y, polygonpoint.z)_
            The last line is redundant. The value returned by GetPoint() is a vector.

            The correct version would be

                pcount = polygon.GetPointCount()  
              spline.ResizeObject(pcount)  
              for i in xrange(pcount) :  
                  point = polygon.GetPoint(i)         
                  spline.SetPoint(i, point)
            

            I suggest you to read some introduction to programming or specifically to Python. The official Python tutorial is a good start.

            -Niklas

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 23/08/2012 at 15:34, xxxxxxxx wrote:

              Hello Niklas,

              Thank you for your reply. I am well aware my programming knowledge is thin side to say the least, and will continue to read up on it. I think I was just getting overly confused with what was what and got tripped up. I find it easier learning form actually trying, and in doing so, making mistakes along the way, so thank you for correcting my silly errors.
              I have amended the script.

              import c4d
              #Python Tag on Polygon Child
                
              def main() :
                  polygon =    op.GetObject()
                  spline =     polygon.GetUp()
                  pcount =     polygon.GetPointCount()
                  
                  spline.ResizeObject(pcount)
                  
                  for i in xrange(pcount) :
                      point = polygon.GetPoint(i)       
                      spline.SetPoint(i, point)
                      
                  spline.Message(c4d.MSG_UPDATE)
                  c4d.EventAdd()
              
              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 23/08/2012 at 16:33, xxxxxxxx wrote:

                When I first used that script it seemed to work fine, I then copy and paste the same script to another scene with similar set up and get unexpected results? The scene file is here : http://dl.dropbox.com/u/2802779/SplineAttachedToPolygon.c4d.zip
                I don't understand why it worked on that one situation and not others?

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

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 23/08/2012 at 16:41, xxxxxxxx wrote:

                  It does work. But you have rotated the polygon-object. The position of the points is stored relative to the object's axis. You either have to multiply each point you obtain from the polygon-object with the matrix of the polygon-object, or change the matrix of the spline-object to match exactly the matrix of the polygon-object.

                  -Niklas

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

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 23/08/2012 at 16:49, xxxxxxxx wrote:

                    I just noticed that, sorry. Thanks again Niklas.

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

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 23/08/2012 at 17:03, xxxxxxxx wrote:

                      Np. 😉

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