<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Comparing values in an array and getting only those within a range in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5456018#M14136</link>
    <description>&lt;P&gt;ahh, thanks very much indeed! Now i will trying to figure out how lol, or not, maybe just use it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks again&lt;/P&gt;</description>
    <pubDate>Wed, 31 Dec 2014 14:02:32 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-12-31T14:02:32Z</dc:date>
    <item>
      <title>Comparing values in an array and getting only those within a range?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5455509#M14132</link>
      <description>&lt;P&gt;&lt;SPAN&gt;hello&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to do a thing in MEL where i have a animated camera I'm using for game cut scenes. When the camera is doing a jump cut it just animates a big distance over 2 sequential frames. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to get all the ranges of frames for each shot to use for playblast / exporting tool etc. But I'm stuck with the best way to do it. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Obviosuly I can get all keyframe time values in an array just with `keyframe -q` but I'm trying all kinds of things now to get all the ranges that are begun and terminated by 2 sequential keyframes. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Eg a camera might have 2 shots which would be 1 cut but with some keys defining the motions within a shot&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So i would get values like 0,1,15,30,31,40,50,51&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And I want the script to return 1,30,31,50 (1:30,31:50 would be a nice format)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but i would also want 1,15,30,31,40,50 to get the same result&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TL:DR just give me the first and last value of any range that starts and ends with 2 seqeuntial values&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks all.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jan 2015 06:35:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5455509#M14132</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-08T06:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values in an array and getting only those within a range</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5455909#M14133</link>
      <description>&lt;P&gt;Not the most elegant solution, but anyway:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc float[] getRanges(float $list[])
{
	float $item, $prev, $last = $list[size($list)-1], $results[];
	int $index = 0;

	for ($item in $list)
	{
		if ($index == 0)
			$results[$index++] = ($list[1] == $item + 1) ? $list[1] : $item;
		else if ($item == $last)
			$results[$index++] = ($item == $prev + 1) ? $prev : $item;
		else if ($item - 1 == $prev)
		{
			$results[$index++] = $prev;
			$results[$index++] = $item;
		}
		else $prev = $item;
	}
	return $results;
}

float $list[] = {0,1,15,30,31,40,50,51}; // or {1,15,30,31,40,50}
getRanges($list);&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Dec 2014 08:05:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5455909#M14133</guid>
      <dc:creator>Swordslayer</dc:creator>
      <dc:date>2014-12-31T08:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values in an array and getting only those within a range</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5455953#M14134</link>
      <description>&lt;P&gt;Hey there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help, I wish i understood things more so I could see how you did it. One thing though, when I run your script i actually get this which which has 2 extra entries at the begining, it work fine with the smaller data set. Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;float $list[] = {0,1,15,30,31,40,50,51};&lt;BR /&gt;getRanges($list);&lt;BR /&gt;// Result: 1 0 1 30 31 50 // &lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Dec 2014 10:58:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5455953#M14134</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-31T10:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values in an array and getting only those within a range</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5456004#M14135</link>
      <description>&lt;P&gt;Sorry about that, different behavior across versions and too little testing. Initializing the $prev to something small enough should take care of that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc float[] getRanges(float $list[])
{
	float $item, $prev = `minint`, $last = $list[size($list)-1], $results[];
	int $index = 0;

	for ($item in $list)
	{
		if ($index == 0)
			$results[$index++] = ($list[1] == $item + 1) ? $list[1] : $item;
		else if ($item == $last)
			$results[$index++] = ($item == $prev + 1) ? $prev : $item;
		else if ($item - 1 == $prev)
		{
			$results[$index++] = $prev;
			$results[$index++] = $item;
		}
		else $prev = $item;
	}
	return $results;
}

float $list[] = {0,1,15,30,31,40,50,51};
getRanges($list);&lt;/PRE&gt;&lt;P&gt;If you are on some maya version that doesn't support the minint command, replace it with -2147483648. Or just -1 if you never start the animation at negative frames.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2014 13:36:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5456004#M14135</guid>
      <dc:creator>Swordslayer</dc:creator>
      <dc:date>2014-12-31T13:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing values in an array and getting only those within a range</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5456018#M14136</link>
      <description>&lt;P&gt;ahh, thanks very much indeed! Now i will trying to figure out how lol, or not, maybe just use it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks again&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2014 14:02:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/comparing-values-in-an-array-and-getting-only-those-within-a/m-p/5456018#M14136</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-12-31T14:02:32Z</dc:date>
    </item>
  </channel>
</rss>

