How to use 'path.Split' properly?

I have been trying out the new path.Split method a bit and noticed that it behaves a bit differently from a usual vector.

Example: path.Split(0) does not return the first element of the path, but the entire vector. To get the first element, path.Split(0).front has to be used.

Copying to a vector helps. After vec.assign(tab.path.Split) the first element can be accessed via vec(0).

Is this the intended way of using it?

Seems OK from this quick test:

Does it depend where the Path object came from?

Oh, if you are doing path.split(0) then that is not returning the 0th item of the vector returned by split, it is calling split with 0 as the first argument, which is optional and specifies the starting component. That then returns a vector.

By default all components of the path are returned, but you can optionally provide the index of the first component and also the number of components to return.

Split is a method not a property, so it needs to be called with () (at least in some languages) even if no arguments are being given to it.

You'd want path.split()(0) to get the first item of the vector in that way.

1 Like

Ok, thanks, makes sense. I had started trying things like DOpus.Output(tab.path.Split.count) and then got confused when DOpus.Output(tab.path.Split(0)) wouldn't work.

1 Like