(edited by Manuel : I splited this thread from this one)

@m_magalhaes said in Post Deformer Spline:

SplineToLineIndex

Hi Manuel,

I am not the one who asked the original question, but your find of the `SplineToLineIndex()`

method in `SplineHelp`

is a good one!

I must have look at `SplineHelp`

's API over a dozen times and never noticed it was there. I thought one would have to traverse all of the `LineObject`

's points and correlate them with points on its parent `SplineObject`

based on position, in order to come up with the mapping from `SplineObject`

point index to `LineObject`

point index. So, this feature of `SplineHelp`

is really valuable, since it offers this very mapping as part of the core Python API.

I guess this also implies that there is always a 1:1 correspondence between a point of a SplineObject (which represents one or more B-Splines via formulas) and a point of its underlying LineObject which represents a bunch of line segments connected together. I wasn't sure if this was always guaranteed to be the case.

Now, for a somewhat related question to what has already been discussed, while we are on the topic of `SplineHelp`

, is there some top secret way to do the opposite of what the `GetPointIndex()`

method of `SplineHelp`

does, that is to get the offset (i.e., 0<=offset<=1.0) along a spline's `LineObject that a particular `

LineObject` point idx is located at? This would also be really helpful.

Let's look at an example:

Say you create a *Rectangle* parametric spline object that has a width and a height of 100 cm, so basically a square. We'll set the Intermediate Points setting to *None*, so that the spline object and its line object have identical point counts (i.e., four, for the four points that make up the corners of the square). Now, let's say you perform a *Make Editable* operation to convert the (parametric) Rectangle into an editable closed spline object, consisting of one segment with four points. If you go into the *Structure Manager*, you can see that the points are indexed 0-3 (since, there are four of them) and you see their coordinates, as well.

These points are located, with regard to offset, at 0%, 25%, 50%, and 75% of the length of the spline (or offsets of 0.000, 0.250, 0.500, and 0.750), respectively, since our original parametric spline shape was a square. Since this is a closed spline, `GetPointIndex()`

will return the (sentinel or logical) idx of 4 (i.e., the count of the number of points in that segment of the `LineObject`

) if asked for the nearest point to 100% of the length of the spline.

Now, given for example the point at Index #1, so the second point of the spline's LineObject, which is obviously 25% of the distance along the spline as previously mentioned, what method could you use on the `SplineObject`

, it's underlying `LineObject`

, or 'SplineHelp' to get a 0.25 offset value from that LineObject point index of 1.

The `GetPointIndex()`

member function of `SplineHelp`

takes a (Spline space) offset value and a segment idx, and returns the closest `LineObject`

point, by index, to that spline space offset value.

As described in the above example, how do you go in the opposite direction, from a `LineObject`

point, by index, to an offset value along the `LineObject`

in spline space?