VectorPosition on Spline?



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

    On 22/06/2011 at 02:41, xxxxxxxx wrote:

    Does any kind soul know how to get the vector position for a spline using Py?
    I have spent all night without any luck and cannot for the life of me
    manage to get it.
    In coffee I do as shown but whatever I try in Python can't get past
    the init part as I don't understand what class does what.

      
    var splineobject = object(); // a selected splineobject   
    var realspline   = splineobject->GetRealSpline(); // the realspline   
    var sldata       = new(SplineLengthData); // the data to use   
        sldata->Init(realspline,0); // the init spline first segment   
    var pos          = realspline->GetSplinePoint(0.5,0); // The vector position in space at 50% of segment   
    

    Cheers
    Lennart



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

    On 22/06/2011 at 02:59, xxxxxxxx wrote:

    I don't see the difference between a SplineObject and a LineObject, but they can both be used with the c4d.utils.SplineHelp class.
    Try this:

    import  c4d  
    from    c4d.utils    import SplineHelp  
      
    def main() :  
      if op is None:  
          print "No object selected."  
          return  
      
      if not op.CheckType(c4d.Ospline) :  
          print "No splineobject. Retrieving Cache ..."  
          globals()["op"]     = op.GetCache()  
      
      if not op.CheckType(c4d.Oline) and not op.CheckType(c4d.Ospline) :  
          print "Cache is not a line- or splineobject."  
          return   
      
      
      shelp   = SplineHelp()  
      shelp.InitSpline(op)  
      
      _range  = 20  
      _range  = float(_range)  
      for i in xrange(int(_range) + 1) :  
          i   = i / _range  
          pos     = shelp.GetPosition(i)  
          print str(i).ljust(5), ":", pos  
      
    main()
    

    Cheers,
    Niklas



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

    On 22/06/2011 at 03:04, xxxxxxxx wrote:

    Thanks Niklas, will look into it right away.
    (Also many thanks for the Cyclebutton example earlier,
    now I get attributes to work instead of using Userdata!)

    Cheers
    Lennart



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

    On 22/06/2011 at 04:05, xxxxxxxx wrote:

    Oh, I got it (Needed some sleep :) )
    I didn't realize that I needed to import SplineLengthData from c4d.utils.

    Niklas, I think what you wonder is within SplineLengthData()
    as it gets whatever spline is thrown at it.

    Now it works the same as my coffee example.

      
    import c4d   
    from c4d import utils   
    from c4d.utils import SplineHelp, SplineLengthData   
      
    def main() :   
        obj = op.GetObject()   
        rs = obj.GetRealSpline()   
        if rs is False:   
            print 'No'   
            return False   
           
        sdata = SplineLengthData()   
        sdata.Init(rs,0)   
        pos = rs.GetSplinePoint(0.5,0)   
        sdata.Free()   
        print pos   
    

    Cheers
    Lennart



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

    On 22/06/2011 at 04:09, xxxxxxxx wrote:

    Corrected code for checking if spline object, should be "None", not False.

      
    import c4d   
    from c4d import utils   
    from c4d.utils import SplineHelp, SplineLengthData   
      
    def main() :   
        obj = op.GetObject()   
        rs = obj.GetRealSpline()   
        if rs is None:   
            print 'Not a Spline'   
            return False   
           
        sdata = SplineLengthData()   
        sdata.Init(rs,0)   
        pos = rs.GetSplinePoint(0.5,0)   
        sdata.Free()   
        print pos   
    

    Cheers
    Lennart


Log in to reply