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

    Count segment point

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 450 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 09/05/2017 at 01:03, xxxxxxxx wrote:

      Hello,

      I am working on a python script which constrains the points of a spline. (fixed position for the first and last point, position limit for the other points). I have it working when I have a single spline.

      Now my issue is when I add another spline in the same spline object, my last point is no more the last ID point but the last point of the segment starting with the point ID 0.

      So what I need is to get the point ID of the last point of the segment starting with the point ID 0.
      What I would need then is to get the number of points of my first segment. Can anyone help me with that? (I search the documentation but couldn't find it...)

      Here is my code so far (working with a single segment spline but not working with a multi segement spline object) which stands on a python tag of the spline object:

      def main() :
          obj=op.GetObject()
          pointCount=obj.GetPointCount()-1
          #Lock base points
          obj.SetPoint(0, c4d.Vector(-.5,0,-.5))
          obj.SetPoint(pointCount, c4d.Vector(.5,0,-.5))
          #Points constraints
          for i in range(1,pointCount) :
              point=obj.GetPoint(i)
              if point.x<-.5:
                  pointX=-.5
              elif point.x>.5:
                  pointX=.5
              else:
                  pointX=point.x
              
              if point.z<-.5:
                  pointZ=-.5
              elif point.z>.5:
                  pointZ=.5
              else:
                  pointZ=point.z
              
              obj.SetPoint(i, c4d.Vector(pointX,0,pointZ))

      Many thanks,
      H.

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

        On 09/05/2017 at 01:57, xxxxxxxx wrote:

        Hello Hadrien!

        Here is a way counting through the segments of the spline.
        Result is a array with first and last point of a segment per row.

          
            seg_list = []   
            pnt_cnt = 0   
            seg_cnt = spline.GetSegmentCount()   
            for i in range(0, seg_cnt) :   
                segment = spline.GetSegment(i)   
                seg_list.append([pnt_cnt+i, segment["cnt"]-1+pnt_cnt+i])   
                pnt_cnt += segment["cnt"]-1   
                  
            for row in seg_list:   
                print str(row[0]) + " - " + str (row[1])   
        

        Cheers,
        Mark.

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

          On 13/05/2017 at 05:15, xxxxxxxx wrote:

          Hi Mark,
          Thank you for your help, it works perfect!


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