Basically what the macro is doing is finding the length of the spline section using the XSectionLength
variable and then dividing that by the spike's desired spacing distance to find out how many times the spike can be repeated between the existing evenly segments. The result is rounded down to the nearest whole number using the Floor command and assigned to a variable called NumReps
. Input1 is a numeric node with the size of the spacing. real numReps = floor(xSectionLength/Input1);
Now that we know how many division roughly fit into a section we can work out the spacing that needs to go between each spike. To do this we first need to deduct the size of the posts and the spike so that we're left with only the combined size of all the spaced needed. In the expression below Input2 is the X size of 1 post and Input3 is the X size of the spike.
As you can see below we use the overall spline section size, minus the size of a post, minus the size of all the spikes. We already know the number of spikes we'll be using from the previous variable: numReps. To find the size of each gap we can then divide the size of the section length minus the geometry by NumReps. real PaddingSize = (XSectionLength-Input2-((numReps-1)*Input3))/numReps;return PaddingSize;
This value can now be used to set the X Size of a null segment and alternate it with the spike to create the correct pattern. (it's easier than it sounds when you get the hang of it
Can I ask was I close to getting it the way I wanted or was my approach fundamentally floored since I would have needed this Macro in order to get the last step?
There are a lot of ways to create anything in RailClone, and there's nothing wrong with the approach you were taking. Using your techniques Rokas' suggestions would probably have put you more on the right track.
You could make it even easier by combining the Rail and the Spike and using it in the default input with Adaptive segments. You might get some slight scaling deformation, but it's the easiest solution using RailClone's core features. I've attached a sample file with this approach.
I hope that helps,
All the best,