//building a wall

//deactivate the scripting log so that it doesn't record ever cube made

SetValue("preferences.scripting.cmdlog", false, null);


//build the ppg with two parameters for inputs
var oppg = ActiveSceneRoot.AddProperty("CustomProperty" , false , "build wall" ) ;

oppg.AddParameter3( "wall_width" , siInt4 , 10 , 0 , 100 , false ) ;
oppg.AddParameter3( "wall_height" , siInt4 , 10 , 0 , 100 , false ) ;


InspectObj(oppg, null , "wall builder" ,  siModal) ;


//collect the values from the ppg

var owidth = oppg.wall_width.value ;
var oheight = oppg.wall_height.value ;



//run our wall building function

build_wall(owidth , oheight) ;


//clean up
//DeleteObj(oppg) ;
SetValue("preferences.scripting.cmdlog", true, null);






function build_wall(in_owidth , in_oheight)
{
//________________________________________________________
//do stuff with the input values



var onumBricks = in_owidth * in_oheight ;

//make a progressbar to show the progress of our script
var oProgressBar = XSIUIToolkit.ProgressBar 
oProgressBar.Maximum = onumBricks
oProgressBar.step = 1 ; 
oProgressBar.visible = true  ;
oProgressBar.caption = "Processing" ;
oProgressBar.minimum = 0 ;

var ocurrentProg = 0


//loop through the input values and build boxes as we go

outerLoop:
	for (var i = 1 ; i < onumBricks + 1 ; i+= in_owidth)
		{
		for (var j = 0 ; j < in_owidth ; j++)
			{
			if (oProgressBar.CancelPressed == true)
				{
				logmessage("you exited the tool")
				break outerLoop;
				}
			var obricknumber = i + j ;
			var orownum = i/in_owidth ;
	
			var ocube = CreatePrim("cube", "MeshSurface", "brick_" + obricknumber + "_row_" + orownum  , null );
	
			ocube.Kinematics.Local.Parameters("posx").value = j*10 ;
			ocube.Kinematics.Local.Parameters("posy").value = (i/in_owidth) * 10  ;
		
			oProgressBar.Value = ocurrentProg ;
			ocurrentProg++
			}	
		}
} // end of the function build_wall