Linear Array Script.

richardandtracyrichardandtracy Posts: 7,077
edited February 2022 in Freebies

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

 

Post edited by richardandtracy on

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?

  • Not sure how to extract a direction from a selected edge. Or whether it's even possible to select an edge. Regards, Richard.
  • BronzeDragonBronzeDragon Posts: 381
    edited February 2022

    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.

    Post edited by BronzeDragon on
  • 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.

  • richardandtracyrichardandtracy Posts: 7,077
    edited February 2022

    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.

    Post edited by richardandtracy on
  • richardandtracyrichardandtracy Posts: 7,077
    edited February 2022

    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.

    Regards,

    Richard

    Linear Array Ad.png
    800 x 800 - 683K
    zip
    zip
    Linear Array.zip
    322K
    Post edited by richardandtracy on
  • mCasualmCasual Posts: 4,607
    edited February 2022

    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 )

     

    txt
    txt
    placeAtVertices.txt
    666B
    Post edited by mCasual on
  • barbultbarbult Posts: 26,156
    The HedgeMaker product places instances along a path that you define with markers you place in your scene. It can handle curves and terrain with hills and valleys.
  • GordigGordig Posts: 10,597

    richardandtracy said:

    Not sure how to extract a direction from a selected edge. Or whether it's even possible to select an edge. Regards, Richard.

    One more reason it would be nice if DS had spline tools. 

  • mCasualmCasual Posts: 4,607
    edited February 2022

     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

    Gordig said:

    richardandtracy said:

    Not sure how to extract a direction from a selected edge. Or whether it's even possible to select an edge. Regards, Richard.

    One more reason it would be nice if DS had spline tools. 

    brand_new_version_of_mcjbuildera_version_9_0_beta_by_mcasual_dbnkkdz.jpg
    800 x 800 - 54K
    Post edited by mCasual on
  • lukon100lukon100 Posts: 843

    Cool. It would have been great for when I made this picture:

    https://www.deviantart.com/luqu/art/Dialectical-Materialists-879661545

  • Ha, ha, ha. Looks perfect for that kind of thing. Regards, Richard.
  • CriosCrios Posts: 2,964

    Oh yes, will be great also when i've did this:

    https://www.deviantart.com/lord-crios/art/Far-far-west-814815915

  • lukon100lukon100 Posts: 843

    Crios said:

    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.

  • That's great Crios. Lukon - the position of each instance can be moved individually once the array is created. Regards, Richard.
  • richardandtracyrichardandtracy Posts: 7,077
    edited June 4

    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 

    Linear Array 3D Promo.jpg
    800 x 800 - 123K
    zip
    zip
    Linear Array 3D.zip
    301K
    Post edited by richardandtracy on
  • StargazeyStargazey Posts: 270

    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?

  • Payat ParinPayat Parin Posts: 1,168
    edited June 5

    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.

     

    banan array.jpg
    3500 x 2500 - 3M
    Post edited by Payat Parin on
  • richardandtracyrichardandtracy Posts: 7,077
    edited June 5

    Stargazey said:

    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?

    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:

    1. First Technical. I don't - at the moment - know how to make things drop to the surface below the instance. It is a soluble problem. 
    2. Second Political. There is already a really good product for sale  at DAZ to do that (UltraScatter) and I doubt if DAZ would appreciate hosting a freebie that has a moderate functional subset of a product they sell.  I suspect a random volume scatter (eg blown leaves or butterflies) might be OK, but I wouldn't be comfortable doing anything more sophisticated and hosting it here.

    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

    Parade.jpg
    1080 x 567 - 295K
    Post edited by richardandtracy on
  • StargazeyStargazey Posts: 270

    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!

Sign In or Register to comment.