Notifications
Clear all

[Closed] storing data within scene for ca's…

 eek

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.selection3+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

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

 eek

yes, thats what im trying to do. Just cant get it to work atm

… ill try when i get back home.

eek

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…

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\	estfil_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 "
" 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 "
" 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 "
\"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\	estfil.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

I also hope that you others out there will share how you filter your stuff

 PEN

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))
 

Fantastic code paul :love:

Thanks a lot, saved a lot of coding time:)

 eek

Thats amazing, i didnt even know you could execute appdata info like that!

Paul, you deserve a :bowdown:

Thankyou,

eek

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

 PEN

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.

Page 2 / 3