GetSegmentLength

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

On 08/10/2012 at 04:06, xxxxxxxx wrote:

Hy there,

the returned values of GetSegmentLength of the SplineLengthData seems to be wrong:

  
import c4d  
from c4d import utils  
#Welcome to the world of Python  
  
  
def main() :  
  print op.GetObject().GetName()  
  
  spline = op.GetObject()  
  
  spd = utils.SplineLengthData()  
  spd.Init(spline)  
  scnt = spline.GetSegmentCount()  
  
  segLength =  spd.GetSegmentLength(1,2)  
  print "Seg. Length: ", spd.GetSegmentLength(0,1)  
  print "Seg. Length: ", spd.GetSegmentLength(1,2)  
  print "Seg. Length: ", spd.GetSegmentLength(2,3)  

This code put on a spline with three segments with different lengths, will return the following:

Spline
Seg. Length:  1.0
Seg. Length:  698.168987717
Seg. Length:  0.0

So, it seems that the second number is the length of the first segment. It seems one needs to Init the spline with the second argument set to a certain segment index (here the segment was implicitly 0). Then the second returned value seems to be the length. How should I interpret these results?

Thank you,
maxx

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

On 08/10/2012 at 05:31, xxxxxxxx wrote:

Use GetRealSpline() to check any type of spline,
point splines and prim splines.

For strings (the print) use the py formatting
for speed and compatibility between scripts manager
and "real" code (plugins).

Cheers
Lennart

  
import c4d   
from c4d import gui,utils   
from c4d.utils import SplineLengthData   
  
def main() :   
    if not op or not op.GetRealSpline() :   
        print 'No Spline Object Selected'   
        return True   
       
    rs      = op.GetRealSpline()   
    scount = rs.GetSegmentCount()   
       
    prim    = SplineLengthData()   
    for seg in xrange(scount) :   
        prim.Init(rs,seg)   
        slength = prim.GetLength()   
        print 'Segm %(seg)s Length: %(slength)s' %locals()   
    prim.Free()   
  
if __name__=='__main__':   
    main()   

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

On 08/10/2012 at 05:59, xxxxxxxx wrote:

Thank you Lennart, this at least yields correct values. But its dead-slow for big splines, so I shortly wrote my own SplineLengthData.

What is the difference between the spline that I have and the spline I get through GetRealSpline()?

How did you figure this out? Anything in the docs?

Edit: Although I see now, that I was using a Spline-Primitive and not yet a "real" spline object, the methods still work kind of strange. The GetLength() method seems to return the length of the spline-segment that was initialized, not the length of the full spline and the GetSegmentLength() seems to return .. I dont konw 😉

Thank you,
André

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

On 08/10/2012 at 06:33, xxxxxxxx wrote:

You want the total length of the spline? (All segments)
Then in the for loop add the segment lengths.

Cheers
Lennart

PS If you found a faster spline length calculation, please let us know 🙂 DS

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

On 08/10/2012 at 07:45, xxxxxxxx wrote:

Ok, my first tests where not fair (sorry API). My approach is faster as I don't need to subdivide the spline and I don't need to care about other splines than linear. Like this a very simple sum-distances approach is of course superior.

But still, the problem of the SplineLengthData remains, that we have to call Init repeatedly and that GetSegmentLength does not return the correct values for different arguments (once initialized).

Cheers,
André