PDA

View Full Version : Set specific data in a string (or stringstream)...


Njen
04-10-2009, 06:26 PM
Hello all, I was looking for a solution to set specific data in the user properties of an object (I know how to use setUserPropBuffer, etc). For example, I have the following data:

scene=sc01
shot=sh01
version=01
width=1920
height=1080

I figured out a way to get the data by turning it into a stringstream, using the following example:

foo1 ="scene=sc01\r\nshot=sh01\r\nversion=01\r\nwidth=1920\r\nheight=1080" as stringstream
skiptostring foo1 "scene="
myScene = readLine foo1 as string
skiptostring foo1 "shot="
myShot = readLine foo1 as string

But I don't know how to set the data. Could anyone help me with the syntax for changing the separate bits of data? Say, changing the version only?

djlane
04-10-2009, 06:29 PM
unless I'm missing something isnt it as simple as:


yourNewValue = 10;
setuserprop $your_obj "version" yourNewValue

Njen
04-10-2009, 06:34 PM
Wouldn't that replace all of the data with just the version? What I am trying to do is change this:

scene=sc01
shot=sh01
version=01
width=1920
height=1080

to this:

scene=sc01
shot=sh01
version=10
width=1920
height=1080

ZeBoxx2
04-10-2009, 07:37 PM
njen :)

Not sure why you would want to set this on a stream itself; usually this sort of data comes from the aforementioned user properties buffer, in which case you can get/set individual properties and their values anyway?

but if you must parse the stream, something like this *could* work - but there's plenty of caveats (e.g. '=' signs in the data values and such).


fn setStreamVarValue stream var val = (
streamStr = stream as string
newStream = stringStream ""
myLines = filterString (streamStr as string) "\r\n"
for myLine in myLines do (
myLineData = filterString myLine "="
myVar = myLineData[1]
myValue = myLineData[2]
if (myVar == (var as string)) then (
myValue = (val as string)
)
format "%=%\r\n" myVar myValue to:newStream
)
newStream
)



foo1 = "scene=sc01\r\nshot=sh01\r\nversion=01\r\nwidth=1920\r\nheight=1080" as stringstream
StringStream:"scene=sc01
shot=sh01
version=01
width=1920
height=1080"
result = setStreamVarValue foo1 "version" 2
StringStream:"scene=sc01
shot=sh01
version=2
width=1920
height=1080
"

djlane
04-10-2009, 08:32 PM
Wouldn't that replace all of the data with just the version? What I am trying to do is change this:

scene=sc01
shot=sh01
version=01
width=1920
height=1080

to this:

scene=sc01
shot=sh01
version=10
width=1920
height=1080

If you have already populated your user prop buffer with your string stream code, then :

setuserprop $your_obj "version" yourNewValue


Should do what your after (it seems to be doing it ok in Max9),go on give it a go. You know you want too...

Njen
04-11-2009, 09:09 AM
Thanks very much to both ZeBoxx2 and djlane! I have not gotten into stringstreams before, and I can see the possibilities with them. Many thanks for helping to wrap my head around this problem.

Cheers!

CGTalk Moderation
04-11-2009, 09:09 AM
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.