Auto save

Could someone please edit this so that while I am editing boxes, it will autosave to the text file when changes are made.

(
txtFile = "C:\Users\YourName\Desktop\boxInfo.txt"

if doesFileExist txtFile then
theFile = openFile txtFile mode:"at"
else
theFile = createFile txtFile

fn print_data_to_file obj=
(
format "\n\n%\n%\n%\n%\n%\n%\n%\n%\n%\n%\n" obj.name obj.length obj.width obj.height obj.position.x obj.position.y obj.position.z \
(obj.rotation as EulerAngles).x (obj.rotation as EulerAngles).y (obj.rotation as EulerAngles).z to:theFile
)--end fn

for theBox in $Box* do print_data_to_file theBox
close theFile
)

Comments

Comment viewing options

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

This is your script

It is better to use *.ini for this then *.txt
*.ini will be created in directory where is the this script placed.
Run script, press "Record" checkbutton and change some paremeters on the your boxes. When you change selections the props are saved automatically.

global aprRoll
if aprRoll  != undefined do try (destroyDialog aprRoll) catch()
rollout aprRoll " AutoPropsRecorder"
(
	local recorder = false
	checkbutton rec "R E C O R D" width:120 highlightcolor:[150,10,10]
	fn saveINISettings = 
	(
		local iniFile = getFilenamePath (getSourceFileName()) + "boxInfo.ini"
		for obj in $Box* as array do
		(
			local sectionName = obj.name, p = obj.pos, r = quatToEuler2 obj.transform.rotation
			local propsNames = #("Length", "Width", "Height", "PosX", "PosY", "PosZ", "RotX", "RotY", "RotZ")
			local propsValues = #(obj.length as string, obj.width as string, obj.height as string, \
			p.x as string, p.y as string, p.z as string, r.x as string, r.y as string, r.z as string)
			for i in 1 to propsNames.count do (setINISetting iniFile sectionName propsNames[i] propsValues[i])
		)
	)
	on rec changed state do
	(
		if state then
		(
			callbacks.removeScripts #selectionSetChanged id:#record
			if ($Box* as array).count == 0 then (messagebox "Create some boxes" title:"RecorderWarning" beep:false ; rec.checked = false)
			else ( callbacks.addscript #selectionSetChanged "aprRoll.saveINISettings()" id:#record ; recorder = true)
		)
		else (callbacks.removeScripts #selectionSetChanged id:#record ; recorder = false)
	)
	on aprRoll close do (if record == true do (callbacks.removeScripts #selectionSetChanged id:#record) ; gc())
)
createdialog aprRoll 130 30 style:#(#style_titlebar, #style_sysmenu, #style_toolwindow)

barigazy

Comment viewing options

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