Linear Array Script.

richardandtracyrichardandtracy Posts: 5,667
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

 

Linear Array R01.png
1200 x 800 - 1M
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: 5,667
    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: 5,667
    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: 24,243
    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,053

    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: 808

    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,760

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

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

  • lukon100lukon100 Posts: 808

    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.
Sign In or Register to comment.