SOLVED How to get spline offset by spline point index ?

How to get spline offset(0-1) by spline point index ? i want know offset between points to caculate the value points should be.
hope for your help!

Hi Mike, thanks for writing us.

With regard to your question, if I properly understood you, you can use the SplineHelp Class and its SplineHelp::GetPosition() method to retrieve the spline's points value given a certain offset.

Something like this:

import c4d

# Main function
def main():
    if op is None:
    realSpline = op.GetRealSpline()
    if realSpline is None:
    splineH = c4d.utils.SplineHelp()
    if splineH is None:
    samples = 10
    for sample in range(0, samples):
        offset = float(sample) / samples
        print splineH.GetPosition(offset)

# Execute main()
if __name__=='__main__':

Best, Riccardo

Hi @r_gigante,
Thank you for replying. I'd like to know more about this topic: if I only know the Control Point Index from PointObject.GetPoint(id) of a spline, how could I get the Spline Position of this point?

@r_gigante Thank you for your help! i have another problem that if i only know the spline point index ,how do i get the offset where point locate? just take sample like 1000 and find the nearest sample to the point position?or have faster way in SDK?

@eziopan For new questions please open a new thread. Thanks.

@mike What do you mean with "how do i get the offset where point locate?"

You want the offset for a point with a given index? The C++ version of SplineHelp has the function GetSplinePointSegment() which can be used to get the offset for a given index. Unfortunately, this function is not available in the Python API.

best wishes,

@s_bach Thank you for your patient answer.

@s_bach thank you for your answer! I think I have the same question as mike do, so it has been solved now. Thank you again!