macroScript SimClothPRESETS category:"ChaosGroup"
(
------------------------------------------
--SimClothMod PRESETS
--Version 0.1
--Started: 4/3/2000
--Edited: 4/5/2000
--by Borislav Petrov
--http://gfxcentral.com/bobo/
------------------------------------------


global simcloth_presets

fn collect_presets =
(
names_array = #()
preset_files = getFiles (scriptspath+"\\SimCloth\\*.scm")
for i = 1 to preset_files.count do
(
names_array[i] = getfilenamefile preset_files[i]
)
names_array
)

fn save_simcloth_presets work_object file_name =
(
try 
(
modobj = work_object.simclothmod 
test_for_files = getFiles (scriptspath+"\\SimCloth\\"+file_name+".scm")
print test_for_files.count 
if test_for_files.count == 1 then
	(
	txt = "Presets File "+file_name+".scm already exists.\nOverwrite?" 
	q = querybox txt title:"SimClothMod Presets"
	)
	else
	(
	q = true
	)
if q then
(	
out_file = createfile (scriptspath+"\\SimCloth\\"+file_name+".scm")
format "%\n" "[SimClothMod Presets Version 1.0]" to:out_file
format "%\n" modobj.Bounce to:out_file
format "%\n" modobj.Slip to:out_file
format "%\n" modobj.Warps to:out_file
format "%\n" modobj.Tightness to:out_file
format "%\n" modobj.Tightness_bias to:out_file
format "%\n" modobj.React_to_delfectors to:out_file
format "%\n" modobj.Spread_force to:out_file
format "%\n" modobj.Keep_speed to:out_file
format "%\n" modobj.Bond_range to:out_file
format "%\n" modobj.Max_steps to:out_file
format "%\n" modobj.max_force to:out_file
format "%\n" modobj.Max_velocity to:out_file
format "%\n" modobj.Self_deflect to:out_file
format "%\n" modobj.Self_deflect_range to:out_file
format "%\n" modobj.Fold_size to:out_file
format "%\n" modobj.Deflect_distance to:out_file
format "%\n" modobj.Rel__deflect_pos to:out_file
format "%\n" modobj.Correct_face_edge_deflection to:out_file
format "%\n" modobj.VertVertDeflection to:out_file
format "%\n" modobj.VertEdgeDeflection to:out_file
format "%\n" modobj.VertFaceDeflection to:out_file
format "%\n" modobj.EdgeVertDeflection to:out_file
format "%\n" modobj.EdgeEdgeDeflection to:out_file
format "%\n" modobj.FaceVertDeflection to:out_file
format "%\n" modobj.Bound__box_divs to:out_file
format "%\n" modobj.Max__constraints to:out_file
--GLOBAL settings
format "%\n" modobj.Start_time to:out_file
format "%\n" modobj.End_time to:out_file
format "%\n" modobj.Redraw_views to:out_file
format "%\n" modobj.Air_resistance to:out_file
format "%\n" modobj.Gravity to:out_file
format "%\n" modobj.Detect_intersection to:out_file
format "%\n" modobj.Min_samples to:out_file
format "%\n" modobj.Max_samples to:out_file
format "%\n" modobj.Speed_threshold to:out_file
close out_file
)--end if q
)
catch()
)--end fn



fn load_simcloth_presets work_object file_name load_mode=
(
--try (
in_file = openfile (scriptspath+"\\SimCloth\\"+file_name+".scm")
modobj = work_object.simclothmod 
version_line = readline in_file
if findstring version_line "SimClothMod" != undefined then
(
if load_mode != 2 then
(
modobj.Bounce = execute (readline in_file)
modobj.Slip = execute (readline in_file)
modobj.Warps = execute (readline in_file)
modobj.Tightness = execute (readline in_file)
modobj.Tightness_bias = execute (readline in_file)
modobj.React_to_delfectors = execute (readline in_file)
modobj.Spread_force = execute (readline in_file)
modobj.Keep_speed = execute (readline in_file)
modobj.Bond_range = execute (readline in_file)
modobj.Max_steps = execute (readline in_file)
modobj.max_force = execute (readline in_file)
modobj.Max_velocity = execute (readline in_file)
modobj.Self_deflect = execute (readline in_file)
modobj.Self_deflect_range = execute (readline in_file)
modobj.Fold_size = execute (readline in_file)
modobj.Deflect_distance = execute (readline in_file)
modobj.Rel__deflect_pos = execute (readline in_file)
modobj.Correct_face_edge_deflection = execute (readline in_file)
modobj.VertVertDeflection = execute (readline in_file)
modobj.VertEdgeDeflection = execute (readline in_file)
modobj.VertFaceDeflection = execute (readline in_file)
modobj.EdgeVertDeflection = execute (readline in_file)
modobj.EdgeEdgeDeflection = execute (readline in_file)
modobj.FaceVertDeflection = execute (readline in_file)
modobj.Bound__box_divs = execute (readline in_file)
modobj.Max__constraints = execute (readline in_file)
)
else
(
for c = 1 to 26 do readline in_file
)

--GLOBAL settings
if load_mode < 3 or load_mode == 5 then
(
modobj.Start_time = execute (readline in_file)
modobj.End_time = execute (readline in_file)
modobj.Redraw_views = execute (readline in_file)

modobj.Air_resistance = execute (readline in_file)
modobj.Gravity = execute (readline in_file)
modobj.Detect_intersection = execute (readline in_file)

modobj.Min_samples = execute (readline in_file)
modobj.Max_samples = execute (readline in_file)
modobj.Speed_threshold = execute (readline in_file)
)

select work_object
close out_file

)--end if version

--)catch()
)--end fn

rollout simclothpresets_roll "SimClothMod Presets"
(
group "Save/Rename Preset"
(
edittext save_file_name text:"Preset1"
button save_preset "SAVE PRESET TO DISK" width:150
button rename_preset "Rename Preset" width:150
)
group "Messages:"
(
edittext messages_line text:"Ready."
)

group "Load Presets"
(
listbox presets_list items:#() height:7
button load_preset "LOAD PRESET" width:150 height:30
dropdownlist assign_mode items:#("All Settings->All Cloths","Global Settings->All Cloths","Local Settings->All Cloths","Local Settings->Selected","All Settings->Selected") default:2
)

on rename_preset pressed do
(
test = renameFile (scriptspath+"\\SimCloth\\"+presets_list.selected+".scm") (scriptspath+"\\SimCloth\\"+save_file_name.text+".scm")
if test then
	(
	presets_list.items = collect_presets ()
	messages_line.text = "Preset Renamed."
	)
	else
	(
	messages_line.text = "Renaming FAILED!"
	)

)

on save_preset pressed do
(
if selection.count == 1 and save_file_name.text != "" then
	(
	try
		(
		modobj = $.simclothmod
		save_simcloth_presets $ save_file_name.text
		presets_list.items = collect_presets ()
		presets_list.selection = presets_list.items.count
		save_file_name.text = ("Preset"+(presets_list.items.count + 1) as string)		
		)
		catch
		(
		messages_line.text = "SimClothMod not found!"
		)
	)
	else
	(
	messages_line.text = "Select exactly ONE object!"
	)
)--end on


on load_preset pressed do
(
if assign_mode.selection < 4 then obj_array = geometry as array else obj_array = selection as array
if assign_mode.selection == 2 and obj_array.count > 1 then obj_array = #(obj_array[1])
for i in obj_array do
(
try
	(
	load_simcloth_presets i presets_list.selected assign_mode.selection
	)
	catch()
)--end i loop
)--end on

)--end rollout


try(closerolloutfloater simcloth_presets)catch()
simcloth_presets = newrolloutfloater "SimCloth Presets" 200 400 100 100
addrollout simclothpresets_roll simcloth_presets
makeDir (scriptspath+"\\SimCloth")
simclothpresets_roll.presets_list.items = collect_presets ()
simclothpresets_roll.save_file_name.text = ("Preset"+(simclothpresets_roll.presets_list.items.count + 1) as string)
)