Linear Array Script.
richardandtracy
Posts: 7,077
I had a need to create an array of instances - hurdles on a race track.
I didn't feel like positioning them all by by hand, so I wrote a little script. Not perfected yet as the array isn't yet grouped together, and I am wondering whether to complicate things a bit by allowing a rotation of the array around the Y axis. It's also only for the X and Z axes, nothing in the Y axis, though that's only a small additional bit of code - not sure if it'd be useful.
At the moment I'm calling this the 'Monsterous Regiment' version as it really only makes regimented arrays of instances.
If anyone would find a script like this to be useful, let me know, and please make suggestions for what else may be useful in a similar script and I'll look into whether I can implement it.
Regards,
Richard


Comments
Would it help to align the array along a path (hurdles, trees lining a walk, et c)? Or would that be another mean bit of code?
Sounds great, wish I could do that sort of thing. Used to do Basic programming, and Basis codes for Medusa CAD, but got out of practice years ago.
To select any or all x, y, and/or z coordinates randomly each time from a set range of values each might come in handy for things like water droplets and such to form mists and things, particularly if the scale of the object could be changed to increase randomness. Might work for making forests and rock piles too, with a set floor value, or maybe a three dimensional surface to do hills. If you could do it and polish it a good bit, it might be a saleable item (I hated talking myself out of a potential freebie, but what's true is true).
Don't know if what I suggested is worth anything, but, good luck with it.
After having a other thought on it. Streams of bubbles along a path line could be used for bubble pipes for kids. or eruptions of bubbles (or a small cloud of bubbles filling a definded volume of space) coming from a culdron or pot. Breaking the cloud into seperate parts, again by random, could allow different colors. Just couple of added ideas. Again, good luck.
There is a script a bit like that called 'UltraScatter', which can do the fancy stuff. It's paid for, which is why I regard it as a bit.. erm .. out of my reach at the moment. I just wanted something simple (and free, especially free) to do the equivalent of a linear array in CAD and if it can be expanded to cover other simple tasks I've not imagined, all the better. I imagine that I will end up doing the equivalent of a circular array too. Just a simple thing. Not sure how to enter elements to skip, but I can see that could well be useful, though it's possible to delete instances afterwards.
I really am not very proficient at this scripting lark - to give you an idea, it took me hours to find a way to enter the array spacing in each direction. I simply couldn't find away to convert a string into a number. In the end, I had to use a parameter slider widget [DzFloatSlider] as I couldn't find (or recognise) in the documentation how to do the equivalent of 'String.tofloat()' as can be found in many C++ libraries that would allow me to use a simple Edit Box. Ends up leaving me questioning if I have any business programming anything - though I am used to making my own tools, and software is a tool like any other. It is possible that the result was more intuitive and in keeping with DS users normal data entry methods, though.
I will investigate path following, though. Might be possible, probably not with this script, but I'll have a look.
Regards,
Richard.
I now have got the script largely working. The instance group origin and bounding box is not completely correct, but it works well enough to be useful for the purpose I wrote the script for, and may be useful to you.
You need to specify the X and Z number of rows and columns, and the spacing in each direction in cm. There is a limit of 100 instances in each direction (10,000 instances max), though you could edit the script if need be to increase the limits.
The image below shows a simple 4x3 array of a character. Props behave in the same way too. Each instance is named by its location, making it easier to find each one in the scene tree.
Richard
works very well
here's a short coder-user script i wrote to place light balls randomly on a surface vertices
it could be adapted for creation of the instances instead of placement of exising things in a null/group
( the forum's code-box doesnt work )
One more reason it would be nice if DS had spline tools.
i have a few scripts that can do tubes or extrusions along null-node paths
mcjRibbons and mcjPathTube, the very powerful mcjBuilderA, and well mcjLathe, and others i forgot about
it's all static geometry though, nothing realtime
oh and with mcjBuilderA you can place and rotate objects in the scene in very complex ways
for instance
Cool. It would have been great for when I made this picture:
https://www.deviantart.com/luqu/art/Dialectical-Materialists-879661545
Oh yes, will be great also when i've did this:
https://www.deviantart.com/lord-crios/art/Far-far-west-814815915
Yes, but I wonder whether the animals in the herd can be moved to stagger them after the script has placed the instances in the array.
I know, I'm very slow, but I have finally got around to extending the Linear Array Script into the third dimension with the Linear Array 3D Script. Works in the same way as the previous script, but allows layers of instances to be created.
Hope someone finds it useful, one day. When you need it, I doubt if anything else will do the job.
Regards,
Richard
First of all, many thanks for this, and all your other great freebies.
A while back you said, "please make suggestions for what else may be useful in a similar script and I'll look into whether I can implement it." so I'm just wondering if it would be possible to add some sort of randomiser to this script, so that you could use it to create things like scattered leaves,or flowers in a meadow (using X and Z) and also (adding Y) falling leaves, swarms of birds, butterflys and so on?
Thank you for this script. I rendered it for trial. It is very helpful in making instances of the same prop or character. Each instance can be independently repositioned or rotated to various positions.
I appreciate what you said about the freebies I issue, it's nice to hear that they are useful.
In response to your suggestion. I have a couple of problems with it, some technical & some political, as described below:
I have recently been thinking a little 'Instance to Mesh' script for single instances might be useful. Totte's product 'Instances to Object' script works with large numbers, but as far as I can see from the product blurb, it doesn't appear to work with a single selected instance (if I'm wrong, maybe someone could correct me, it's an older Outlet product, and if it does single conversions it'd be worth the price - I never need conversion to export large numbers of objects). The sort of use I was thinking of was as below, soldiers on parade all with exactly the same pose except one that's broken rank somehow. The instance to mesh script would make it fairly quick to select an instance, convert it to an object to allow it to be posed individually without the pose being promulgated to all instances - really all it would be is a low effort/quick duplicate & position of the instance root node.
Regards,
Richard
Thanks for your comments, Richard. I know nothing about scripting, so I didn't know how difficult it might be. I had a look at Ultrascatter, but apart from being a bit pricey for me, it seems to be more complex than I was envisioning. I think I'll stick with instancing, using your scripts, and just manually move things round a bit when I want a more random look!