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
    • Recent
    • Tags
    • Users
    • Login

    detecting spline object segment start/end points

    Scheduled Pinned Locked Moved PYTHON Development
    12 Posts 0 Posters 952 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 15/10/2015 at 12:04, xxxxxxxx wrote:

      Hello Mohamed
      Can you post or show picture with structure of spline op or list as segments?
      I do not clearly understand what kind object it is?!

      for me, like

      +null

      > pyeffector (effect at connector as points mod)
      >
      > + connect op (connect splnes)
      >
      > > +cloner
      >
      > > > spline
      >

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

        On 15/10/2015 at 13:07, xxxxxxxx wrote:

        Hi Ilya,

        +spline
        +null
              pyeffector
              +cloner (clone on object "spline")
                    cube

        the spline can contain many segments "like hair for example, but it is a spline object, segments don't have the same vertex count" , for example:

        a spline which contains 4 segments,
        segment 0: 10 points
        segment 1: 4 points
        segment 2: 13 points
        segment 3: 6 points

        so it is totally random, what I need to know is:
        from the above example: the spline contains 33 points (10 + 4 + 13 + 6) , if I iterate over all points, how to know if this point is the end of a segment?

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

          On 16/10/2015 at 00:06, xxxxxxxx wrote:

          Hello
          "speed" dirty test for 4 seg. with:

          import c4d  
          import math  
            
          def main() :  
            op = doc.GetActiveObject()  
            if not op: return  
            sc = op.GetSegmentCount()  
            pnt = op.GetPointCount()  
            pntl = []  
            for i in xrange(sc) :  
                for p in xrange(0, pnt, pow(sc, 3)) :  
                    pos = op.GetSplinePoint(p, i)  
                    null = c4d.BaseObject(c4d.Onull)  
                    null.SetAbsPos(pos)  
                    null[c4d.NULLOBJECT_DISPLAY]=13  
                    pntl.append(pos)  
                    doc.InsertObject(null)  
            c4d.EventAdd(c4d.EVENT_0)  
            print pntl  
              
          if __name__=='__main__':  
            main()
          


          http://imhocloud.com/image/7yAf

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

            On 16/10/2015 at 03:48, xxxxxxxx wrote:

            thanks Ilya, this helped!
            now the last question:
            how to delete a clone? "inside mograph"

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

              On 16/10/2015 at 03:58, xxxxxxxx wrote:

              i can not say about "delete"

              But take to look at python sdk - \examples\scenes\ push_apart_effector.c4d

              Per-Edwards showed in this sample how to control visibility of clone

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

                On 16/10/2015 at 04:02, xxxxxxxx wrote:

                thanks Ilya

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

                  On 16/10/2015 at 09:31, xxxxxxxx wrote:

                  Hi guys,

                  there's a small bug in Ilya's code, which will produce extra Null objects, if the point count on the spline segments is high enough. And actually there's no need for the pow(sc, 3) construct (which actually gave me some headache, what the script is actually doing...).
                  The point is, GetSplinePoint()'s first parameter is a float ranging from 0.0 to 1.0. 0.0 addressing the beginning of the segment, 1.0 then end. Ilya's script misused the power function (step parameter of the xrange) to loop exactly twice (and with higher point counts this failed and the loop was executed more times).
                  Simply change the inner loop to:

                  for p in xrange(0, 2) :
                  

                  p will only be zero or one, the loop is executed only twice and everything's fine.

                  Or to answer Mohamed's question directly:

                  op.GetSplinePoint(0.0, segmentIndex) # Beginning of segement
                  op.GetSplinePoint(1.0, segmentIndex) # End of segement
                  

                  Regarding the MoGraph question:
                  I don't think, it's possible to remove a clone. So visibility will most likely be your friend.

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

                    On 16/10/2015 at 09:46, xxxxxxxx wrote:

                    Hello Andreas
                    Thank you that bring the light!

                    woohoo! me was silly, sorry, I get some code from head, different projects from gis(messing with it).
                    GetSplinePoint used as some-how GetPoint

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

                      On 17/10/2015 at 04:24, xxxxxxxx wrote:

                      Hi Andreas,

                      I knew this 🙂 "about the xrange and the power" , just took the idea to get the last point as needed.

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

                        On 18/10/2017 at 12:36, xxxxxxxx wrote:

                        I figured out a pretty clean way to do this without using floats

                        def FindSegmentPoints(spline) :
                            
                            scnt = spline.GetSegmentCount()     #get segment count
                            sarr = []                           #array to contain segment start/end dict data                                   
                            cnt = 0                             #var to help us keep track of count position
                            
                            for i in xrange(0, scnt) :                        #iterate through segments
                                c = spline.GetSegment(i)['cnt']              #find current segment count
                                sarr.append({'start':cnt, 'end':cnt+c-1})    #add data to array as dict
                                cnt = cnt + c                                #update count
                                
                            return sarr                         #return array
                        

                        It returns an array where each of the indices is a dict of the start/end points

                        For a rough example, to access the end point of the 3rd segment of 'spline' (a SplineObject) you would do:
                        FindSegmentPoints(spline)[2]['end']

                        I hope this helps 🙂

                        Jenny

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

                          On 18/10/2017 at 13:40, xxxxxxxx wrote:

                          Here's an additional extension of the previous function.

                          This one can find which segment a point index belongs to, given a SplineObject and the point index

                          #Find segment a point index belongs to
                          def FindSegmentByPoint(spline, index) :      #spline, point index (int)   
                              
                              scnt = spline.GetSegmentCount()         #get segment count
                              cnt = 0                                 #var to help us keep track of count position
                              
                              if index > spline.GetPointCount() :      #if index is out of range,
                                  print 'index out of range'          #  return -1
                                  return -1
                              
                              for i in xrange(0, scnt) :               #iterate through segments
                                  c = spline.GetSegment(i)['cnt']     #find current segment count
                                  if cnt < index < (cnt+c-1) :
                                      break
                                  cnt = cnt + c                       #update count
                                  
                              return i                                #return segment index
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post