View Full Version : storing data within scene for ca's...
Im using appdata to store array values for a ca to access and edit:
test =#(#(1,2,3),#(2,3,4))
n = stringstream ""
for v in test do print v to:n
setAppData $point01 1 n
when getting it back:
test=#()
gpn = StringStream (getAppData $point01 1 )
data_values = #()
whilenot eof gpn do
(
append test (readvalue gpn)
)
format "\t%\n" gpn
messagebox (test as string)
This works kinda but i get #(1,2,3,4,5,6) instead of this #(#(1,2,3),#(4,5,6)) ?
Btw, is this a good way to go or should i use strings to hold the array values? or say a struct with the empty arrays in the startup folder?
eek
|
|
Wahooney
11-30-2005, 07:33 AM
I use the rootnode and apply ca's to that. That way you can store any variable you like without having to do string conversions.
yes this is what im kinda doing, but i want the scene to remeber array data after i load and save it.
eek
Wahooney
11-30-2005, 08:04 AM
ca's in the rootnode are loaded and saved with the scene
root node being like an object or a global track?
eek
Wahooney
11-30-2005, 08:32 AM
rootnode (or $<root>) is the max keyword for the scene, it the object that unparented objects are linked to. It is essentially the scene.
magicm
11-30-2005, 04:42 PM
Only 1-dimensional arrays can be stored within CA's though, so you might need multiple parameters to store your data. Or find another way to deal with the nested arrays.
- Martijn
ahhh Martin, thank you.
Thats exactly the problem. But what about AppData, cant it hold #(#(1,2),#(,2,3)). Im only using the ca access this appdata,so that you press a button, it accesses the appdata and populates a listbox and some empty arrays - which the ca access. This actually happen when the rollout is opened.
I might have to use a scene struct instead. Ok yep that seems better.
eek
on doing:
struct mystruct_c
(
testarray=#()
)
mystruct = mystruct_c()
works, but is there a way of append this and keeping it with the scene? I mean is it best to hold nested arrays with a text file and auto load it, when the scene is opened?
eek
Martin Andersen
12-01-2005, 09:21 PM
Edit: Blahhhh.... off topic, sorry:hmm:
--------------------------------
Well.. here is how I'm doing in a script i'm writing on at the moment:
I have a Save button, if the user want anything to be saved, he HAS to click on the save button.
When he does that, there is a pop-up (yes/no) box, telling him that "The XXX script will now create a Point/dummy object named "TheXXXscriptDataStoreDummy"where alle the The XXX information is saved. Do Not delete this dummy if you want to use the data later on."
good things:
- we tell the user where the information is stored
- the Dummy point can be merged
- no extra files to keep track of
if Anyone disagree.. please tell, I like to hear your oppinions
well this is with appdata:
setAppData $XXX 1 -- 1 for id
Well im doing the same just trying to store in on the node that has the ca on it. But i just cant get it to work. I cant get appdata to hold nested arrays:
nestedarray = #(#(1,2,3),#(1,2,3)) if put this on a node with appData. Then get the data back you get:
#(1,2,3,4,5,6)
so i tried this:
a =10
b =20
c= 30
val = [a,b,c]
then append this to an array:
append nestedarray val
so you get #([10,20,30])
this works i can get the data back, but i still get the a error saying its undefined. Ill post up the source.
What ryan told me may be the best solution: to append the array one by 1 like so:
test = #(1,2,3,4,5,6)
then to get the values via the selection in the listbox (what ive got)
so:
x_val = test[ (list.selection*3+1)]
y_val = test[ (list.selection*3+2)]
y_val = test[ (list.selection*3+3)]
but you would need an if to check the first call, because to get the val of x from the first selection you dont wont 2 you want 1, so:
if list.selection == 1 then
(
x_val = test[(list.selecition+1)]
y_val = test[(list.selecition+2)]
z_val = test[(list.selecition+3)]
etc,etc
)
So im still looking into it. I may just pump the data out to a text file.
eek
RyanT
12-02-2005, 12:23 AM
If your going to make it text you my as well just make it a string stream and put that on the app data if thats what your going for. That way you wont have to have any external files.
-RyanT
yes, thats what im trying to do. Just cant get it to work atm
.. ill try when i get back home.
eek
galagast
12-02-2005, 03:57 AM
im not sure if this would help (or if its really relevant), i made a script which also needed nested arrays saved and loaded with the scene... and this array included nodes, so part of the only easiest way for me to maintain it per scene is to just set the variable as a persistent global...
Martin Andersen
12-02-2005, 08:53 AM
I don't know if this is for any help.. atm. I'm writing on a Copy Paste Vertexs positions script, (it is going to be mutch more than just copy paste). I just wrote the text file save / load... the output looks like this:
5,"test","test","test","test","test"
"p",2,[7,1,9],[9,9,7]
"p",3,[9,9,7],[0,2,5],[7,1,9]
"p",2,[0,2,5],[9,9,7] -----point3 values
"p",1,[0,2,5]
"p",1,[7,1,9]
"p",1,[9,9,7]
"s",10,23,54,54,543,54,54,32,59,97,98
"s",4,564,24,35,36
"s",3,54,54,84
"s",7,211,548,4,2,3,6,45
"s",3,4,2,6
"s",3,84,84,54
"s",5,73,19,64,58,96
"s",4,25,21,26,95
"End"
The first line: [number] defines how many string values there is in the first line "test","test"..etc
Then I've set it up so the script can filter all the lines with a Case of (in the Readfile)
"P".. followed by a number, the number defines how many data strings there is after the number in the line.
The Case of stops looking for strings when it sees the "End" string
Writer:
(
local NameArr = #("test","test","test","test","test")
local PosArr = #(#([7,1,9],[9,9,7]),#([9,9,7],[0,2,5],[7,1,9]),#([0,2,5],[9,9,7]),#([0,2,5]),#([7,1,9]),#([9,9,7]))
local SelArr = #(#(23,54,54,543,54,54,32,59,97,98),#(564,24,35,36),#(54,54,84),#(211,548,4,2,3,6,45),#(4,2,6),#(84,84,54),#(73,19,64,58,96),#(25,21,26,95))
-- creates the "CopyPasteVertsScriptFiles" Directory
finddir = getDirectories "scripts\\CopyPasteVertsScriptFiles"
print finddir
if finddir.count == 0 do ( makeDir "scripts\\CopyPasteVertsScriptFiles" )
-- Save file Start
out_name = "$scripts\\\\CopyPasteVertsScriptFiles\\testfil_output.txt"
out_file = createfile out_name
NameArrCount = NameArr.count -- add the first number in the first line
Format "%" NameArrCount to:out_file
for i = 1 to NameArr.count do ( -- add the Text strings
NameArrTmp = NameArr[i] as string
format ",\"%\"" NameArrTmp to:out_file
)
for i = 1 to PosArr.count do ( -- Add "p",[number of datagroups],data,data,data...
format "\n" to:out_file
format "\"p\"" to:out_file
PosArrTmp = PosArr[i].count
format ",%" PosArrTmp to:out_file
Counter = PosArr[i].count
iCounter = i
for x = 1 to Counter do (
tmp = PosArr[iCounter][x]
format ",%" tmp to:out_file
)
)
for i = 1 to SelArr.count do ( -- Add "S",[number of datagroups],data,data,data...
format "\n" to:out_file
format "\"s\"" to:out_file
SelArrTmp = SelArr[i].count
format ",%" SelArrTmp to:out_file
Counter = SelArr[i].count
iCounter = i
for x = 1 to Counter do (
tmp = SelArr[iCounter][x]
format ",%" tmp to:out_file
)
)
-- Add "End" in the end
format "\n\"End\"" NameArrTmp to:out_file
close out_file
)
-- Save file End
(
-- Description of reading the file it reads from:
-- the first line:
-- 4,"brow","mouth","cheek","eye"
-- the 4 defines the number of Text strings "brow" etc.
-- "p",[number of datas],(some data),(some data),(some data)
-- ex: "p",3,[9,9,7],[0,2,5],[7,1,9]
local NameArr = #()
local PosArr = #()
local SelArr = #()
in_name = "scripts\\testfil.txt"
in_file = openFile in_name
if in_file != undefined then
(
-- the first number defines the number of Text strings "brow" in the first line etc.
NoOfNames = readValue in_file
NameArr.count = NoOfNames
for i = 1 to NoOfNames Do (NameArr[i] = readValue in_file )
Runner = 1 -- is set to zero when the while loops hits the end of the file.
while runner == 1 do
(
TmpPosArr = #()
TmpSelArr = #()
ArrType = readValue in_file
case of
(
(ArrType == "p") : ( NoOfPos = readValue in_file -- reads the first number after the "p".. this number tells how many data there is after this one
for i = 1 to NoOfPos do (NewPos = readValue in_file
TmpPosArr[(TmpPosArr.count + 1)] = NewPos )
PosArr[(posArr.count + 1)] = TmpPosArr
)
(ArrType == "s") : ( NoOfSel = readValue in_file
for i = 1 to NoOfSel do (NewSel = readValue in_file
TmpSelArr[(TmpSelArr.count + 1)] = NewSel )
SelArr[(SelArr.count + 1)] = TmpSelArr
)
(ArrType == "end") : ( Runner = 0)
)
)
close in_file
)
print NameArr
print PosArr
print SelArr
)
I hope someone find it usefull :thumbsup:
I also hope that you others out there will share how you filter your stuff :)
Does that do what you want?
ar=#(1,2,#(3,4),5,6,#(7,8))
setAppData $ 1 (ar as string)
newAr=execute (getAppData $ 1)
#(1, 2, #(3, 4), 5, 6, #(7, 8))
Martin Andersen
12-02-2005, 12:54 PM
Fantastic code paul :love:
Thanks a lot, saved a lot of coding time:)
Thats amazing, i didnt even know you could execute appdata info like that!
Paul, you deserve a :beer: :bowdown:
Thankyou,
eek
Martin Andersen
12-05-2005, 03:57 PM
Hi all.. I got a problem with the setAppData $ 1 (ar as string)...
with a array like this:
#(#([1,1,1], [2,2,2],[3,3,3]),#([1,1,1], [2,2,2],[3,3,3]),#([1,1,1], [2,2,2],[3,3,3]))
it works well when there is only a few "strings" in the array, but it fails if there is a lot of "strings" in the array, then it adds "..." in the array
Like:
#([1,1,1], [2,2,2],[3,3,3],...)
When it adds the "..." I got problems..
Why does that happend?
How can I use the setAppData $ 1 (ar as string) without that problem?
Is this releated to Bit arrays?
---
and again Pen, thanks for the info, very usefull
This has been an on going problem that I have run into. If you print a large array in the listener it will do this and that is what is happening. I think that it only handled 20 items in an array no matter what was in each item. What you need to do is build the string manualy by reading in each element converting it to a string and adding it to the string that you are going to store. Have a look at PEN Attribute Holder for reference on this. I believe that I had to do this in that script. I'm storing the data in a parameter block but it is just the same for appData channels.
Martin Andersen
12-05-2005, 10:41 PM
Thanks a lot, good info :)
Now I've found plan A, and have to do a plan B for Plan A - hehehe... life is great :scream:
any news on max8 and this problem ?
Pen: building a string array, is the same thing i did in the code, I pasted earlier in this thread?
magicm
12-05-2005, 11:56 PM
Okay, I must admit the script turned out to be quite long, only to store multidimensional arrays :scream: but it works.
Running it creates a custom attribute that let's you store and retrieve a multidimensional array of floats. It can be easily adjusted to use integers instead of floats. See the comments at the top of the script for more info.
You obviously need to rename it to .ms and use open/run
- Martijn
CGTalk Moderation
12-05-2005, 11:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.