PDA

View Full Version : Frame Range to sequence


JokerMartini
04-11-2012, 12:11 AM
Is there an easy way to turn a given input sequence to an array of numbers.
Same way max's render frame range is handled in the edittext.

--user input
--"30,36,22 - 20,-3 - 2"

--result wanted
-- #(-3,-2-1,0,1,2,20,21,22,30,36)

JokerMartini
04-11-2012, 12:50 AM
Seems like having those negative values really makes things confusing.

Bobo
04-11-2012, 01:42 AM
Seems like having those negative values really makes things confusing.

May I ask what you are trying to do? :)

EDIT:

Here is a possible solution for YOUR specific syntax (where the delimiter is " - " and not "-"):

fn getFramesArrayFromString theString =
(
theString = filterString (substituteString theString " - " "..") ","
theFrames = for i in theString where not matchPattern i pattern:"*..*" collect i as integer
for i in theString where matchPattern i pattern:"*..*" do
(
local thePair = (for j in filterString i "." collect j as integer)
local theStep = if thePair[1] > thePair[2] then -1 else 1
for k = thePair[1] to thePair[2] by theStep do appendIfUnique theFrames k
)
sort theFrames
)

getFramesArrayFromString "30,36,22 - 20,-3 - 2"
--> #(-3, -2, -1, 0, 1, 2, 20, 21, 22, 30, 36)

JokerMartini
04-11-2012, 03:57 PM
I'm making an attribute holder with a multilistview that contains (these time intervalsl created by the user) inwhich controls the birth frames of a particle system.

The list view has an input field for the user to insert frame ranges or individual frames.

Check out that attached file. It's just the attribute side of it right now.

Bobo
04-11-2012, 04:26 PM
The list view has an input field for the user to insert frame ranges or individual frames.

In that case, the code I posted won't do in its current form - you will need to expand it to perform a significant amount of sanity checks, ensuring the user is not entering garbage... ;)

JokerMartini
04-11-2012, 04:34 PM
I've wrote up so functions that check for that. It seems like it will work great for this. Thanks for you help Bobo.

CGTalk Moderation
04-11-2012, 04:34 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.