detecting spline object segment start/end points

On 15/10/2015 at 02:42, xxxxxxxx wrote:

Hi,

I got a spline object, which contains many different segments.

the spline object is used as a Mograph object "inside the cloner". , so clones are cloned exactly on spline points "only points"

I want to create an effector which can scale clones depending on the point , for example if this point is the end of a segment, scale it., I couldn't find what I want from SplineHelp class nor SplineObject "I can't choose points?? just %t which is kinda weird.."

any ideas?
summary of what I want:
1- iterate over all spline points, detect this point "index inside segment"
2- a method to delete clones? "may be with a generator Python object if the effector won't work in this case (and I expect it to not work as it is somehow called once per clone) , or a tag? "tag will be better than a generator"

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
>

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?

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

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

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

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

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

thanks Ilya

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.

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

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.

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

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