Notifications
Clear all

[Closed] Saving Help

Hello guys i am a bit new at maxscript and im working on script
when i press btn i want max to save the obj position and rotation
and the other btn should load im still thinking on the right way to do it but how can i save the obj position and rotation with having the save name dialog to appear i dont know if there is something to save other than getsavefilename
sorry for the long Q

11 Replies

Write the transform of the object to an ini file, txt file, xml file and then read that information when you want to load it?

Some info on ini format:
http://www.scriptspot.com/forums/3ds-max/general-scripting/reading-from-ini-file

Some info on xml format:
http://www.paulneale.com/tutorials/dotNet/xml/xml.htm
http://www.paulneale.com/tutorials/dotNet/xml/xmlReading.htm

Some info on write and read for .txt files
http://www.scriptspot.com/forums/3ds-max/general-scripting/maxscript-write-and-read-txt-file

I prefer ini for simple things and XML for more elaborate data writting.

thanx for replying so fast now im stuck at this
every time i transform to zero in 3ds max the Dropdwonlist Rests and the script works fine if its on Attribute Holder any idea why ??

ca = attributes L_Leg_Postion_Controls
(

rollout pose “L Leg Pose” width:200 height:600
(

dropdownlist Pose "test" items:#("Zero")  height:6
button btn_test "get selection"

	

fn Pose_Selected itm =--we pass the argument passed to the handler

(
format “You selected %
” itm–and do something inside

)

on pose selected sel do

(

)


on btn_test pressed do

(
Pose.items = append Pose.items (“Pose “+ (Pose.items.count+1) as string)

Pose_Selected (Pose.selection = Pose.selection + 1 )


)

)
)

custAttributes.add $.modifiers [1] ca

1 Reply
(@momo2012)
Joined: 10 months ago

Posts: 0

I personally use an array to store data ,whatever type of it:

need_save=#(1,2,3,4,5,900)
Fn savedata filename data=
(
f = CreateFile filename
for i=1 to data.count do format "%
" data[i] to:f
close f	
)
Fn loaddata filename=
(
	f=openFile filename
	tmp_array=#()
	while not eof f do 
	(
	read=readline f	
	if read!="" then append tmp_array read
	)
	close f	
	tmp_array 
)
savedata "C:\Data_test.txt" need_save
--readdata=loaddata "C:\Data_test.txt" 
--print readdata
--output will be strings
--if you need integer or float,you can change the strings to them
--for i=1 to readdata.count do print (readdata[i] as integer)

And your code,seems rollout name and dropdownlist name use the same,it would be better below:

ca=attributes L_Leg_Postion_Controls
(
rollout pose_roll "L Leg Pose" width:200 height:600
(
dropdownlist Pose "test" items:#("Zero") height:6
button btn_test "get selection"
fn Pose_Selected itm =--we pass the argument passed to the handler
(
format "You selected %
" itm--and do something inside
)
on pose selected sel do
(
)
on btn_test pressed do
(
Pose.items = append Pose.items ("Pose "+ (Pose.items.count+1) as string)
Pose_Selected (Pose.selection = Pose.selection + 1 )
)
)
)
custAttributes.add $.modifiers[1] ca

thnx man for the quick respond so i have this cod which is working fine as long i keep 3dsmax open and when i restart everything goes back to zero
should i try to save everything or what should i do ??

ca = attributes L_Leg_Postion_Controls
(
parameters Postion rollout:Mega
(Pose_items type:#index ui:pose default:0
)
rollout Mega “L Leg Pose” width:200 height:600
(
– locals for L Lg

– local to dropdwon
global Drop =“0”
global Kmal =#(Drop)
global Monaka
global Dirt = 0
– locals
local SelNumb =1
Local savemap =1
local koka = “D:\3D\New folder\3ds max\Girl Motion\Script\Post\0”
local moka = “D:\3D\New folder\3ds max\Girl Motion\Script\Back.jpg”
– Buttons
bitmap bmp1 “Bitmap” pos:[0,80] width:200 height:200 fileName:Moka
dropdownlist Pose “test” items:Kmal height:6
button btn_test “get selection”
button Rest_All “” width:200 height:200
button Past “Past” pos:[37,10] width:111 height:50

global dsl

-- igot this one from maz function for the piker 
fn Pose_Selected itm =--we pass the argument passed to the handler

(
format “You selected %
” itm–and do something inside

)

	 fn Save_Leg =
	 (
		
		 
		 LegIK_R   = in coordsys parent $Anim_L_Leg_IK01.rotation 
 LegIK_P = in coordsys parent $Anim_L_Leg_IK01.pos  

FootBend_Roll = $Anim_L_Leg_IK01.modifiers[#Extra_Controls].FootBend_Roll

	 )
	 
	
	 
on Mega  open do (
	
	  print "LOLO Open"
	 

)

  
  on Mega rolledUp state do

if drop==0 then ( print “Rolled Down!”)
else( print “Rolled Up!”)

on Pose selected selection do

(

dsl =  selection

	if selection == 1 then	( bmp1.filename="D:\3D\New folder\3ds max\Girl Motion\Script\Back.jpg"	) 

if selection >= 1 then ( 	bmp1.fileName=Koka  + selection   as string +  ".jpg"  ) 

)

	on Past pressed  do

(

if Pose.selection ==1 then ( print "Nelson Sayas HAHA"
			
			)
	

if Pose.selection  == 2 then (

in coordsys parent $Anim_L_Leg_IK01.rotation = LegIK_R02
in coordsys parent $Anim_L_Leg_IK01.pos = LegIK_P02

	 $Anim_L_Leg_IK01.modifiers[#Extra_Controls].FootBend_Roll = FootBend_Roll02 

print “LEsh 02”

)

if Pose.selection  == 3 then (

in coordsys parent $Anim_L_Leg_IK01.rotation = LegIK_R03
in coordsys parent $Anim_L_Leg_IK01.pos = LegIK_P03

	 $Anim_L_Leg_IK01.modifiers[#Extra_Controls].FootBend_Roll = FootBend_Roll03 

print “7esh 03”

)
if Pose.selection == 4 then (
in coordsys parent $Anim_L_Leg_IK01.rotation = LegIK_R04
in coordsys parent $Anim_L_Leg_IK01.pos = LegIK_P04

	 $Anim_L_Leg_IK01.modifiers[#Extra_Controls].FootBend_Roll = FootBend_Roll04 

print “im Blue dada 04”

)

)

on btn_test pressed do
(

 -- 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 savemap = (savemap+1 ) 
     
 

--gw.setPos 0 0 spn_width.value spn_height.value	-- View Port Size 
gw.setPos 0 0 200 200	-- View Port Size 

Pose.items = append Pose.items (“Pose “+ (Pose.items.count+1) as string)

Pose_Selected (Pose.selection = Pose.selection + 1 )

			bmpGrab = gw.getViewportDib    vfb:on
		
			bmpGrabSaveFile = true
			
			
			
			bmpGrab.filename=Koka  + Pose.items.Count    as string +  ".jpg"
				

			save bmpGrab
		
				Rest_All.images = #(bmpGrab, undefined, 1,1,1,1,1 )
			
			
			
			

			
			
		SelNumb = (SelNumb + 1)
	
				if Pose.items.Count==2 then (
			
				
				
						global LegIK_R02   = in coordsys parent $Anim_L_Leg_IK01.rotation 
 global LegIK_P02 = in coordsys parent $Anim_L_Leg_IK01.pos  

global FootBend_Roll02 = $Anim_L_Leg_IK01.modifiers[#Extra_Controls].FootBend_Roll

	Print "Count 02"
				
			)
			
		
			
						if Pose.items.Count==3 then (
			
				
				                                         
						global LegIK_R03   = in coordsys parent $Anim_L_Leg_IK01.rotation 
global LegIK_P03 = in coordsys parent $Anim_L_Leg_IK01.pos  

global FootBend_Roll03 = $Anim_L_Leg_IK01.modifiers[#Extra_Controls].FootBend_Roll

				Print "Count 03"
				
				
				
			)
			
						if Pose.items.Count==4 then (
			
				
				
					global	 LegIK_R04   = in coordsys parent $Anim_L_Leg_IK01.rotation 
global LegIK_P04 = in coordsys parent $Anim_L_Leg_IK01.pos  

global FootBend_Roll04 = $Anim_L_Leg_IK01.modifiers[#Extra_Controls].FootBend_Roll

				Print "Count 04"
				
				
			)

)
on Mega close do (

	Drop =Pose.items
--dirt = Pose.items.Count
--Print  Pose.items.Count
--Pose.items.count=Pose.items.count
--Print Drop
Print Kmal
) 

)

)
–createDialog Pose
custAttributes.add $.modifiers [1] ca

1 Reply
(@momo2012)
Joined: 10 months ago

Posts: 0

Because your code DOES NOT have a load function to load value,when you run the codes,the global or local value will be assigned to default again each time unless you load it,just add a function to check whether a value need to load or use default,in your codes,something could like this to save and load:
1.First,you need define a value to store all the data values.

global storedata=#()        --all data store in this value
Fn savedata filename data=  --save data function
(
f = CreateFile filename
for i=1 to data.count do format "%
" data[i] to:f
close f	
)
Fn loaddata filename=       --load data function
(
	f=openFile filename
	tmp_array=#()
	if f!=undefined then
	(
		while not eof f do 
		(
		read=readline f	
		if read!="" then append tmp_array read
		)
		close f	
	)
	tmp_array 
)
fn Check_need_load filepath=
(
	storedata=#()
	if doesFileExist filepath then  --check if a saved data file exsit
    (
		storedata=loaddata filepath 
	)
	storedata
)
fn use_load_or_default load_num default_v=
(	
	if storedata.count !=0 then need_load=storedata[load_num] else need_load=default_v
)

2.Before you run your codes,you should check and load value:

storedata=loaddata @"C:\Data_test.dat"

global Drop =use_load_or_default 1 "0" --if saved file exsit,then load storedata[1] else use default "0"
global Kmal =#(Drop)
global Dirt =(use_load_or_default 2 0) as integer

local SelNumb =(use_load_or_default 3 1) as integer
Local savemap =(use_load_or_default 4 1) as integer
-----------------------your codes start here------------------------------
--...

3.Then,you need a save function to save all value to a file when the rollout close,so next time you can read it:

-----------------------------put into your Mega colse function----------------------

on Mega close do ( 
Drop =Pose.items
--dirt = Pose.items.Count
--Print Pose.items.Count
--Pose.items.count=Pose.items.count
--Print Drop
Print Kmal
	
--save all your value to a file when close rollout
need_save=#("0",0,1,1) --Drop,Dirt,SelNumb,savemap
storedata @"C:\Data_test.dat" need_save
) 

This is not the best way to save and load value,but you can understand how to do it from those functions,hope this can help you.

Thanx alot for your help i redid almost everything to save and load
and i do have a small wall when i make the DropdownList it rests it goes like this
ca = attributes L_Leg_Postion_Controls
(
parameters Pos rollout:Mega
(Pos_selected type:#index ui:Pos default:0
)
rollout Mega “L Leg Pos” width:200 height:600
(
dropdownList Pos “test” items:#(“”)
button btn_test “get selection”
fn Pos_Selected itm =
(
format “You selected %
” itm
)
on btn_test pressed do
(
Pos.items = append Pos.items (“Pos “+ (Pos.items.count+1) as string)
Pos_Selected (Pos.selection = Pos.selection + 1 )

	)

)
)
custAttributes.add $.modifiers [1] ca

Which value should you need to save?

so im trying to make the dropdownlist items that im adding with other button to save when i save the maxfile

It should be something like this:

--initilize default data
need_save=#("0",0,1,1,"",1) --Drop,Dirt,SelNumb,savemap,Pos.items,Pos.selection(1 as default,0 will be nothing selected)

--check whether need to load or use default
P_items=use_load_or_default 5 1
P_selection=(use_load_or_default 6 1) as integer

-------------------------------------------------------------
--...
dropdownList Pos "test" items:P_items selection:P_selection
button btn_test "get selection" 
--...

-------------------------------------------------------------
on Mega close do ( 
--...
	
need_save=#("0",0,1,1,P_items,P_selection) --Drop,Dirt,SelNumb,savemap
storedata @"C:\Data_test.dat" need_save
)

i do think what i need here is much simpler maybe got something to do with the UI or the Parameters of the Custom Holder i got this from, the maxScript Help with it u can add items to the ListBox But Every time u deselect it it rest back to its original form

ca = attributes L_Leg_Postion_Controls
(
parameters Postion rollout:Mega
(Pose_items type:#index ui:testList default:0
)

rollout MEGa “Test”
(
listBox testList items:#(“Item 1”,“Item 2”)
button addToList “Add Item To End Of List” width:180
button insertToList “Insert Before Current Item” width:180
button removeFromList “Remove Current Item” width:180
–Append a new Item to the array. Since append returns the resuling array,
–it is OK to assign the result directly to the .items property
on addToList pressed do
testList.items = append testList.items (“Item “+ (testList.items.count+1) as string)
–Instert new item before current item
on insertToList pressed do
(
–Check whether current item selection exists (greater than 0)
if testList.selection > 0 do
(
–Because insertItem returns OK instead of the resulting array,
–you cannot assign the result of the expression directly to the property.
–Instead, you have to get a copy of the items array in a local variable…
temp_array = testList.items
–…perform the insertion with the temp. array in the local variable…
insertItem (“Item “+ (testList.items.count+1) as string) temp_array testList.selection
–…and assign back the temp. array to the .items property
testList.items = temp_array
)
)
–Remove currently selected item from the list:
on removeFromList pressed do
(
–Check whether there are any items left and there is a valid selection.
–Then delete the current item. DeleteItem returns the resulting array,
–so you can assign the result directly to the .items property
if testList.items.count > 0 and testList.selection > 0 do
testList.items = deleteItem testList.items testList.selection
)
)

)

custAttributes.add $.modifiers [1] ca

thanx you i finally done it all i had to do is add Persistent global myArray to my array :ٍ]