Duplicate a box to different sizes using table data.

Hi!
Need to duplicate a box many times.
Each new box has different dimensions and associated name.
Each new box will be saved in new separate file.

This is a small sample of data that will be used (total table has 280 lines):
box name - legth - width - height
LB2043 - 5 - 2.5 - 2.5
SL2566 - 1.0625 - 1.0625 - 3.35

This code needs to run once for each box:
[CODE]
modPanel.setCurrentObject $.baseObject --entering sub object level
--set box dimensions
$.length = 6 -- how to get data from array in here???
$.width = 3 -- how to get data from array in here???
$.height = 6.2865 -- how to get data from array in here???
--center box in scene
$.pos = [-0,0,0.11938] --x,y,z
--save as a new file
sceneName = maxFilePath + "boxName" --how to put the "box name" here (example: LB2043) ???
saveMaxFile sceneName --save the file "boxName".max
[/CODE]
How can this code execute, each time with new "boxName" and "box dimensions"?

This is my first attempt at max script. Any advice is welcomed.
Thank you!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Lvu's picture

miauu, thanks for your help!

miauu, thanks for your help! It is a great feedback, and a chance to compare to my trial code.

Befor seeing your solution, I wrote this version:

modPanel.setCurrentObject $.baseObject  --entering sub object level
l = #(2.5625, 1.375, 3.0625)
w = #(0.5625, 1.375, 3.0625)
d = #(3.8125, 4.375, 2.8125)
nam = #("SL3012", "SL3013", "SL3014")
--counter to asist with index identification
for i=1 to 3 do
--set box dimensions with index from counter
(
	$.length = l[i]
	$.width = w[i]
	$.height = d[i]
	--center box in scene
	$.pos = [-0,0,0.047] --x,y,z
	--zoom to extents
	max zoomext sel all
	max izoom in
--save as a new file with new name from array
	sceneName = maxFilePath + nam[i] --put the file name code here
	saveMaxFile sceneName --save the file "boxName".max
)
miauu's picture

.

Try this:

(
	local tableDataFile = openFile "D:\\tableData.txt"
	local boxObj = objects[1]
	if classOf boxObj == Box then
	(
		while not eof tableDataFile do
		(
			txt = readLine tableDataFile
			dataArr = filterString txt " -" 
			boxObj.length = dataArr[2] as float
			boxObj.width = dataArr[3] as float
			boxObj.height = dataArr[4] as float
			--center box in scene
			boxObj.pos = [0, 0, 0]
			--save as a new file
			sceneName = maxFilePath + dataArr[1] + ".max"
			saveMaxFile sceneName
		)
	)
	else
		messagebox "There is no BOX object in the scene" title:"WARNING"
)
Michele71's picture

Nice solution Miauu :)

Nice solution Miauu :)

miauu's picture

.

Thank you. :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.