# Script to place a selected object multiple times

Hi

Im not involved in 3D graphics but would like to produce images based upon some on some mathematics.

Basically I would like to have a file which can be rendered to produce images of translucent spheres at particular co-ordianates. (Think of marbles on a table making a pretty pattern)

I have a an Excel file (or CSV) which gives the x,y coordinates, the size of the sphere and its colour.

I wish to be able to run the script numerous times to produce different patterns and would like to be able to do something similar to shapes that are not spheres.

Id be happy to pay for such a script but am unsure how much it might cost.

Any advice or persons willing to take on this work would be appreciated.

Best wishes,
Nick

## Comment viewing options

### Marbles on an invisible convex disc

Thanks le1se for taking the time to do this.

I suspect the script you have written will probably do most of what I would ideally like. I will be asking others to run the script. Im Linux based and have never used any 3d software before starting this project. 20 hours into trying to learn Blender and Im fairly sure that without a miraculous revelation I will remain clueless.

I have been making 2d abstract images (mainly out of large dots) arranged in a pattern derived from a spreadsheet and have amended that spreadsheet and attached it to this post. The dots are arranged around a center and for objects that are not circular the column "rotationX" would make them point out from the center.

The spread sheet has a title line and then each row shows (size;x,y,z;r,g,b;rotationx,rotationy)

the size of the object compared to the original (assuming the original object to have a size of 1 unit).

the x,y,z coordinates of the center of the copy of the starting object.

the R,G.B of the object to be placed.

It then shows two columns "RotaionX" and "RotationY" the rotation of the object, this was not mentioned before because I am unsure how to express it for the 3d world, but for objects that are not symmetrical it would be good to be able to rotate them about 2 axis.(This Rotation aspect is a nice to have thing and wouldn't greatly effect me at this stage, In fact in the CSV the Rotation Y is set to zero for all the rows.)

If my understanding is correct if we started off with a clear glass sphere as our original object; your script together with this csv should place objects pretty much in one plane - like marbles on a disc (except the tops of the marbles are alligned rather than the bottoms) with each marble coloured. The marbles nearer the centre would be smaller than those further away.

Also attached is a photograph of one that I made from real marbles.

What I was after was a realistic image similar to the real marbles, showing colours both reflected and passing thru the marbles but with variation in marble sizes but the allure of being able to work in 3d has led me to want to be able to put the marbles onto a curved plane like a section of a sphere.

I hope this makes sense and appreciate the time and help you have given.

Best wishes
Nick

AttachmentSize
img_4363_small.jpg 185.27 KB
test.csv2_.obj 2.62 KB

### nicksoph, i have roughly

nicksoph, i have roughly done the script. its not cleaned up and optimized yet..

script, demo-csv and mini-tut-animgif is attached. have fun.

```rollout csvCloner "csvCloner" width:180 height:250 (

local origObj

local clones = #()
local matrix = #()

local fileName

pickbutton chooseObjBtn "Pick Object" width:140 tooltip:"pick the object to be cloned"

label lab010 ""
button createClonesBtn "Create Clones" width:140 tooltip:"create the clones"
button undoBtn "Delete Clones" width:140 tooltip:"delete clones" enabled:false

label lab020 ""
label lab030 ""
button scaleUpBtn "Scale Clones Up" width:100 tooltip:"scale up clones"
button scaleDownBtn "Scale Clones Down" width:100 tooltip:"scale down clones"

label lab40 ""
label lab50 "beta version" align:#right

fn parseFile = (

fileName = getOpenFileName types:"CSV Files (*.csv)|*.csv|Text File (*.txt)|*.txt|All Files (*.*)|*.*|"

if fileName != undefined AND doesFileExist fileName do (

matrix = #()

local File = openfile fileName mode:"rt"

while (not eof File) do (

filterString LineData ";"

append matrix LineData

)
close File

)

) -- end fn

fn createClones = (

for c=1 to clones.count do (
delete clones[c]
)

clones = #()

for i=1 to matrix.count do (

newClone = instance origObj
tmpBlocks = filterString matrix[i] ";"

tmpScale = tmpBlocks[1]
tmpPos = filterString tmpBlocks[2] ","
tmpColor = filterString tmpBlocks[3] ","
newClone.pos = [tmpPos[1] as float,tmpPos[2] as float,origObj.pos[3]]

tmpScaleValue = tmpBlocks[1] as float/100

scale newClone [tmpScaleValue,tmpScaleValue,tmpScaleValue]

-- make materials:
baseMat = getMeditMaterial 1

newMat = copy baseMat
newMat.name = baseMat.name+"_"+ i as string
newMat.diffuse = (color (tmpColor[1] as float) (tmpColor[2] as float) (tmpColor[3] as float))

newClone.material = newMat

append clones newClone
)

undoBtn.enabled = true

)

fn scaleClones scaleDir = (

if scaleDir == "upDir" do (
scaleSize = [1.1,1.1,1.1]
) -- end if

if scaleDir == "downDir" do(
scaleSize = [0.9,0.9,0.9]
) -- end if

if (clones.count >=1) do (

for c=1 to clones.count do (
scale clones[c] scaleSize
)

)

) -- end fn

on createClonesBtn pressed do (

if ( (origObj == undefined) or (fileName == undefined) ) then (

) else (

createClones()

)

) -- end on

on matrixImportBtn pressed do (

parseFile()

) -- end on

on chooseObjBtn picked obj do(

if obj != undefined do(

obj.wirecolor = red
origObj = obj

chooseObjBtn.text = obj.name

origObjScale = origObj.scale

) --end if
) --end on

on undoBtn pressed do(

for c=1 to clones.count do (
delete clones[c]
)

clones = #()

undoBtn.enabled = false
) -- end on

on scaleUpBtn pressed do (
scaleDir = "upDir"
scaleClones scaleDir
) -- end on

on scaleDownBtn pressed do (
scaleDir = "downDir"
scaleClones scaleDir
) -- end on

)

createdialog csvCloner

-- script by le1setreter```
AttachmentSize
ms_csvcloner_01.ms 4.02 KB
matrix_float2.zip 275 bytes
csvcloner_tut.gif 189.27 KB

### hi nicksoph, sounds like this

hi nicksoph,

sounds like this script should not be that big deal... at least the needs you described.

but what do you mean with "I wish to be able to run the script numerous times to produce different patterns[...]". do you want to load other excel/csv files?

mostly when it comes to adding more features and error validating these kind of scripts can take some more time than supposed at the beginning.

anyway, i think this script is easy. i would do it for free as a little practice and i believe other people in here think the same.

just post an example of your excel file and a demo max scene with the desired look (a part or some other image reference would also be fine) and especially some info on the material you would like to have. also try to clarify your needs as detailed as possible.

this would be a good way to start.

with best regards
-le1se