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

    SplineData: Sort knots by x-value

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 250 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 25/03/2016 at 12:31, xxxxxxxx wrote:

      Hello everybody,

      I´d like to imitate the behavior of SplineData by manually changing x-values of knots with python. Meaning, if I pick up a knot by hand and drag it over/under the x-value of another knot, the line of spline will be set well from one to the other knot. If I use python the line will be broken.

      spl = op[c4d.ID_USERDATA,1]  
        spl.SetKnot(0, c4d.Vector(0.5,0,0))  
        op[c4d.ID_USERDATA,1] = spl
      

      I already tried to sort the list of splinedata.GetKnots() by knots["vPos"].x ...

      for i, knot in enumerate(sorted(op[id].GetKnots(), key=lambda k: k['vPos'].x)) :  
                spl.SetKnot(index=i,   
                            vPos=knot["vPos"],   
                            lFlagsSettings=knot["lFlagsSettings"],   
                            bSelect=knot["bSelect"],   
                            vTangentLeft=knot["vTangentLeft"],   
                            vTangentRight=knot["vTangentRight"],   
                            interpol=knot["interpol"])
      

      ... but the result is equal SplineData.SortKnots() and so not what I´m looking for.

      Finally I´ve found the following note in the SDK >

      Note
      Also contains the point index ID. The ID can be accessed using these functions:

      def SplineKnotGetID(flags) :
      return ((flags >> 16) & 0x0000ffff)

      def SplineKnotSetID(flags, flag_id) :
      flags = (flags & 65535) | ((flag_id & 0x0000ffff) << 16)

      Important
      This means that the flags must only be accessed using '|=' and ' &=' (a good advice for any set of flags, for maximum forward compatibility).

      ... but I really don´t know how to use this function rigth.

      Does anyone knows a solution?

      Thx and greetings
      rownn

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

        On 28/03/2016 at 02:18, xxxxxxxx wrote:

        Hi,

        Have you tried to swap the active and next knots? The spline shouldn't brake.

        Don't worry about the spline knot ID. This is set at the creation of a knot. To add a knot to the spline use SplineData.InsertKnot().
        In your case you don't need to create a new knot, just swap 2 existing ones.

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