[RoutineDef,CheckMemBlock,//routine to check for the memblock [If,[MemGetSize,IJ_frontBtn],//try to give memblocks unique names so they don't conflict with other plugins/zscripts //the memblock has a size so we do nothing ,//else we create the memblock [MVarDef,IJ_frontBtn,10,0]//create memblock for 10 variables and inialize each to 0 ] ] //In order to store the data from more than one button you only need one memblock - //you just make it big enough to store the extra data... //So for two buttons each with 10 values you would use [MVarDef,IJ_frontBtn,20,0] //Three buttons would be [MVarDef,IJ_frontBtn,30,0] and so on //Then you just have to make sure you are storing and setting the transform values //using the correct index (adding ten each time). //Choose document size [IButton,"1K","1024 X 1024", [ISet,Document:Pro,0] [ISet,Document:Width,1024] [ISet,Document:Height,1024] [IPress,Document:Resize] [CanvasZoomSet,0.87] ,,0.2 ] [IButton,"4K","4096 X 4096", [ISet,Document:Pro,0] [ISet,Document:Width,4096] [ISet,Document:Height,4096] [IPress,Document:Resize] [CanvasZoomSet,0.22] ,,0.2 ] [IButton,"FRONT","Store Front Camera", [RoutineCall,CheckMemBlock] //when the button is pressed: [If, [MVarGet,IJ_frontBtn,0] == 0, //the first variable is used to check if we have stored the values or not [MVarSet,IJ_frontBtn,0,1]// we are storing values so our 'check' variable is set to one //now get the current transform values into the list [MTransformGet,IJ_frontBtn,1]//store all nine transform values starting at second variable (index starts at 0) ,//else we have stored values so we need to set the new position [MTransformSet,IJ_frontBtn,1]//set model's transform from memblock starting at second variable ] ,,.5 // button width ]//end button //Clear stored views [IButton,"Clear View","Clear View", [RoutineCall,CheckMemBlock] //clear data from front button [If,[MVarGet,IJ_frontBtn,0] == 1,//then [MVarSet,IJ_frontBtn,0,0]//clear first variable in memblock to 0 ]//end if ,,0.5 //clear all button width ] //end clear all button [IButton,"Save Data","Save stored values to disk", [If,(([MemGetSize,IJ_frontBtn])&&([MVarGet,IJ_frontBtn,0] == 1)),//if we have a memblock and some values [VarSet,err,[MemSaveToFile,IJ_frontBtn,"FrontBtnData.dat",1]]//store data to a file called "FrontBtnData.dat" in the same location as this zscript [If,err>0,[Note,"Data stored to disk"]] ,//else [Note,"No data to store"] ]//end if ,,0.5] //end memblock save button [IButton,"Load Data","Load stored values from disk", [If,[FileExists,"FrontBtnData.dat"],//if there is a file [MemDelete,IJ_frontBtn]//get rid of an existing memblock if there is one [VarSet,err,[MemCreateFromFile,IJ_frontBtn,"FrontBtnData.dat"]]//create memblock from the file //if the memblock is created successfully the value of err will be the size of the memblock //when using [MVarDef] each variable is 4 bytes, so the memblock in this case will be 40 bytes in size [If,(err > 0), [If,(err != 40),//if err is not equal to 40 [Note,"Memblock is incorrect size. Data discarded."] [MemDelete,IJ_frontBtn]//we've a problem so delete the memblock ,//else [Note,"Data loaded"] ] ,//else an error... [Note,"No data loaded"] ]//end if err ,//else no file [Note,"No data file"] ]//end if file exists ,,0.5] //end memblock load button