<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Adventures in Keyframes and Code &#187; Functions</title>
	<atom:link href="http://www.keyframesandcode.com/code/category/development/maxscript/functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.keyframesandcode.com/code</link>
	<description>MaxScript, ActionScript, PHP &#38; JavaScript</description>
	<lastBuildDate>Wed, 06 Oct 2010 23:49:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>&#8220;List&#8221; struct</title>
		<link>http://www.keyframesandcode.com/code/development/maxscript/list-struct/</link>
		<comments>http://www.keyframesandcode.com/code/development/maxscript/list-struct/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 18:21:21 +0000</pubDate>
		<dc:creator>Dave Stewart</dc:creator>
				<category><![CDATA[For Scripters]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[MaxScript]]></category>

		<guid isPermaLink="false">http://www.keyframesandcode.com/code/development/maxscript/for-scripters/list-struct/</guid>
		<description><![CDATA[As 3dsmax doesn&#8217;t allow for either associative arrays or dynamically-set object properties, it can be difficult to store unstructured, arbitrary variables.
Sometimes you just want to store lists of name/value pairs, to keep track of a few settings throughout your script, without relying on a host of variables, resorting to .ini files, or custom attributes.
Therefore, I [...]]]></description>
			<content:encoded><![CDATA[<p>As 3dsmax doesn&#8217;t allow for either associative arrays or dynamically-set object properties, it can be difficult to store unstructured, arbitrary variables.</p>
<p>Sometimes you just want to store lists of name/value pairs, to keep track of a few settings throughout your script, without relying on a host of variables, resorting to .ini files, or custom attributes.</p>
<p>Therefore, I set about writing a basic Dictionary, or List struct, similar to VB and other languages.</p>
<h3>Example code</h3>
<p>Here&#8217;s a really basic example of storing 5 named variables within a List:</p>
<pre>names = #("five", "four", "three", "two", "one")
values = #(5,4,3,2,1)
lst = List()

for i = 1 to 5 do lst.addItem names[i] values[i]</pre>
<p>So let&#8217;s get some data back out:</p>
<pre>lst.getValue "two"
-- 2

lst.getIndex "two"
-- 4

lst.getValues()
-- #(5, 4, 3, 2, 1)</pre>
<p>Or print the whole lot:</p>
<pre>lst.print() -- unsorted

five:	5
four:	4
three:	3
two:	2
one:	1</pre>
<p>How about some sorting:</p>
<pre>lst.sort() -- by name, alphabetically

five:	5
four:	4
one:	1
three:	3
two:	2

lst.sort field:#value -- by value

one:	1
two:	2
three:	3
four:	4
five:	5</pre>
<p>As you can see, it&#8217;s pretty straightforward stuff!</p>
<h3>Properties and Methods</h3>
<blockquote>
<h3>Properties</h3>
<ul>
<li>&lt;array&gt; <strong>items</strong> &lt;name&gt; &lt;value&gt; &#8211; the key/value pairs.
<ul>
<li>Names can be a #name, &#8220;string&#8221;, or even an index</li>
<li>Values can be any MaxWrapper value (i.e. anything)</li>
</ul>
</li>
</ul>
<h3>Setters</h3>
<ul>
<li>&lt;ListItem&gt; <strong>addItem </strong>&lt;name&gt; &lt;value&gt; &#8211; adds an item to the List, and if it already exists</li>
<li>&lt;ListItem&gt; <strong>setItem </strong>&lt;name&gt; &lt;value&gt; &#8211; synonym for the above</li>
</ul>
<h3>Getters</h3>
<ul>
<li>&lt;value&gt; <strong>getValue </strong>&lt;name&gt; &#8211; returns the value of the named item</li>
<li>&lt;index&gt; <strong>getIndex </strong>&lt;name&gt; &#8211; returns the index of the named item</li>
<li>&lt;name&gt; <strong>getName </strong>&lt;value&gt; &#8211; returns the name of the first item that matches the supplied value</li>
<li>&lt;ListItem&gt; <strong>getItem </strong>&lt;name&gt; &#8211; returns the List item corresponding to the supplied name (typically, you wouldn&#8217;t use this, as you know the name component already, it&#8217;s just included for completeness)</li>
<li>&lt;array&gt; <strong>getItems()</strong> &#8211; returns all items as an array of ListItem structs</li>
<li>&lt;array&gt; <strong>getNames()</strong> &#8211; returns all names as an array</li>
<li>&lt;array&gt; <strong>getValues() </strong>- returns all values as an array</li>
</ul>
<h3>Clear or delete</h3>
<ul>
<li>&lt;array&gt; <strong>clear()</strong> &#8211; clears the lit of all items, and returns the empty ListItems array</li>
<li>&lt;boolean&gt; <strong>deleteItem </strong>&lt;name&gt; &#8211; deletes the named item from the list, and returns it</li>
<li>&lt;boolean&gt; <strong>deleteIndex </strong>&lt;index&gt; &#8211; deletes the item at the index, and returns it</li>
</ul>
<h3>Utilities</h3>
<ul>
<li>&lt;array&gt; <strong>sort</strong> field:&lt;name&gt; order:&lt;name&gt; func:&lt;function&gt; &#8211; sorts the list in a variety of ways, even supply a comparison function (see the max help on qsort)</li>
<li>&lt;string&gt; <strong>print()</strong> &#8211; prints the List items to the Listener</li>
</ul>
</blockquote>
<h3>Next version</h3>
<p>Possible improvements in the next version might be:</p>
<ul>
<li>.ini file integration, with <strong>save()</strong> and <strong>load()</strong> methods</li>
<li>Support for hierarchical Lists, perhaps <strong>getValue #(#parent, #child, #grandchild, &#8230;)</strong></li>
</ul>
<h3>Download</h3>
<p>Download <a href="http://www.keyframesandcode.com/resources/maxscript/Functions/List.struct.ms">List.struct.ms</a> here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyframesandcode.com/code/development/maxscript/list-struct/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Time Stamper</title>
		<link>http://www.keyframesandcode.com/code/development/maxscript/time-stamper/</link>
		<comments>http://www.keyframesandcode.com/code/development/maxscript/time-stamper/#comments</comments>
		<pubDate>Fri, 09 May 2008 15:12:16 +0000</pubDate>
		<dc:creator>Dave Stewart</dc:creator>
				<category><![CDATA[For Scripters]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[MaxScript]]></category>

		<guid isPermaLink="false">http://www.keyframesandcode.com/code/uncategorized/time-stamper/</guid>
		<description><![CDATA[This struct basically makes timing things much easier by packaging a few useful methods together.
Now, instead of writing and retrieving timestamp variables, and formatting strings to the listener, you simply call struct methods such as start(), end(), and print(), or see a report of the process with getReport().
Example Code
Create a new Time Stamper, assigning a [...]]]></description>
			<content:encoded><![CDATA[<p>This struct basically makes timing things much easier by packaging a few useful methods together.</p>
<p>Now, instead of writing and retrieving <strong>timestamp</strong> variables, and formatting strings to the listener, you simply call struct methods such as <strong>start()</strong>, <strong>end()</strong>, and <strong>print()</strong>, or see a report of the process with <strong>getReport()</strong>.</p>
<h3>Example Code</h3>
<p>Create a new Time Stamper, assigning a task name:</p>
<pre>ts = timeStamper "Testing"</pre>
<p>Time something, and alert the results in a messagebox:</p>
<pre>ts.start()
-- your code here
ts.alert()</pre>
<p><img src="http://www.keyframesandcode.com/resources/maxscript/For%20Scripters/Time%20Stamper/img/time-stamper-alert.gif" class="no-border" /></p>
<p>Benchmark a series of tests, and print the results to the listener when completed:</p>
<pre>for i = 1 to 10 do (
	ts.start()
	-- your code here
	ts.end()
)
ts.print average:true</pre>
<pre>-- Average processing time for 'Testing' was 24.6162 seconds, based on 10 timed sessions.</pre>
<h3>Methods</h3>
<blockquote>
<h3>Starting and stopping</h3>
<ul>
<li><em>&lt;number&gt; </em><strong>start</strong>() &#8211; start timing. Returns start time</li>
<li><em>&lt;number&gt; </em><strong>end</strong>() &#8211; end timing. Returns last timing duration</li>
<li><em>&lt;void&gt; </em><strong>reset</strong>() &#8211; reset all timing data</li>
</ul>
<h3>Getting results in English</h3>
<ul>
<li><em>&lt;void&gt; </em><strong>print </strong>average:<em> &lt;boolean&gt;</em> difference:<em> &lt;TimeStamper&gt;</em> &#8211; end timing and print results to listener</li>
<li><em>&lt;void&gt; </em><strong>prompt </strong>average:<em> &lt;boolean&gt;</em> difference:<em> &lt;TimeStamper&gt;</em> &#8211; end timing and prompt results to notification area</li>
<li><em>&lt;void&gt; </em><strong>alert </strong>average:<em> &lt;boolean&gt;</em> difference:<em> &lt;TimeStamper&gt;</em> &#8211; end timing and alert the results in a messagebox</li>
</ul>
<blockquote><p>For the above methods, the following keyword arguments can be supplied:</p></blockquote>
<ul>
<li><strong>average</strong> <em>&lt;boolean&gt;</em> &#8211; returns the average result of all the timed tests since the TimeStamper was instantiated or last reset</li>
<li><strong>difference</strong> <em>&lt;TimeStamper&gt;</em> &#8211; returns the comparative difference between another TimeStamper, in English, e.g.<em>&#8220;Test 1&#8242; was 2.58 times quicker than &#8216;Test 2&#8242;&#8221;</em></li>
</ul>
<h3>Getting results as numbers</h3>
<ul>
<li><em>&lt;number&gt; </em><strong>getLast</strong>() &#8211; gets the last single timed session (alias for <strong>duration</strong> property<strong>)</strong></li>
<li><em>&lt;number&gt; </em><strong>getTotal</strong>() &#8211; gets the total of all timed sessions</li>
<li><em>&lt;number&gt; </em><strong>getAverage</strong>() &#8211; gets the average of all timed sessions</li>
<li><em>&lt;array&gt; </em><strong>getDifference</strong> difference: <em>&lt;TimeStamper&gt;</em> average:<em> &lt;boolean&gt;</em> &#8211; Returns a 3-element array representing how much quicker one time stamper is than another.</li>
</ul>
<blockquote><p>The array&#8217;s elements are ordered like so:</p>
<ol>
<li>&lt;number&gt; &#8211; how many times quicker the quickest Time Stamper was</li>
<li>&lt;string&gt; &#8211; the task name of the quicker time stamper</li>
<li>&lt;string&gt; &#8211; the task name of the slower time stamper</li>
</ol>
</blockquote>
<h3>Getting results as an Excel-compatible report</h3>
<ul>
<li><em>&lt;string&gt; </em><strong>getReport </strong>columns:<em>&lt;array&gt;</em> step:<em>&lt;number&gt;</em> output:&lt;string/name/windowstream/filestream&gt; &#8211; gets all timed sessions as a customizable report</li>
</ul>
<blockquote><p>The <strong>step</strong> property defines how many iterations to average/total values for, and defaults to 10.</p>
<p>The <strong>columns</strong> property can take any of the following name values:</p>
<ul>
<li><strong>#index</strong> &#8211; the numeric index of the row,<em> e.g. 1, 2, 3</em></li>
<li><strong>#step</strong> &#8211; the current step,<em> e.g. 1, 11, 21</em></li>
<li><strong>#stepaverage</strong> &#8211; the average of all measurements from the current step</li>
<li><strong>#steptotal</strong> &#8211; the total of all the measurements from the current step</li>
<li><strong>#slower</strong> &#8211; how much slower the current step was than the fastest step</li>
<li><strong>#quicker</strong> &#8211; how much quicker the current step was than the slowest step</li>
<li><strong>#total</strong> &#8211; the cumulative total from all measurements so far</li>
</ul>
<p>The <strong>output</strong> property defines where the generate report will be output to. Values can be:</p>
<ul>
<li><strong>No value</strong> &#8211; the report will be returned as a string</li>
<li><strong>&#8220;path/to/file.txt&#8221;</strong>  &#8211; a file path. If the file exists it will be overwritten, if not it will be created</li>
<li><strong>#window</strong> &#8211; a new script window</li>
<li>&lt;windowstream&gt; &#8211; a reference to a windowstream</li>
<li>&lt;stringstream&gt; &#8211; a reference to a stringstream</li>
</ul>
<p><a href="http://www.keyframesandcode.com/resources/maxscript/For%20Scripters/Time%20Stamper/docs/TimeStamper-report.xlsx">Download a report that was built using calls to getReport() in Excel 2007</a> or in <a href="http://www.keyframesandcode.com/resources/maxscript/For%20Scripters/Time%20Stamper/docs/TimeStamper-report.xls">Excel 2003</a></p></blockquote>
</blockquote>
<h3>Properties</h3>
<ul>
<li><strong>duration</strong> <em>&lt;number&gt;</em> &#8211; the duration of the last timed session</li>
<li><strong>durations</strong> <em>&lt;array&gt;</em> &#8211; an array of all timed sessions</li>
<li><strong>task</strong> <em>&lt;string&gt;</em> &#8211; the name of the current timed task</li>
</ul>
<h3>Demo and case study</h3>
<p>Check out a <a href="http://www.keyframesandcode.com/code/development/maxscript/time-stamper-meshopsattach-case-study/">case study</a> and download a demo script here:</p>
<p><a href="http://www.keyframesandcode.com/code/development/maxscript/time-stamper-meshopsattach-case-study/" class="plain"><img src="http://www.keyframesandcode.com/resources/maxscript/For%20Scripters/Time%20Stamper/img/time-stamper-graph.gif" /></a></p>
<h3>Download</h3>
<p>Download <a href="http://www.keyframesandcode.com/resources/maxscript/For%20Scripters/Time%20Stamper/TimeStamper.ms">TimeStamper.ms</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyframesandcode.com/code/development/maxscript/time-stamper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multimaterial From Folder</title>
		<link>http://www.keyframesandcode.com/code/development/maxscript/multimaterial-from-folder/</link>
		<comments>http://www.keyframesandcode.com/code/development/maxscript/multimaterial-from-folder/#comments</comments>
		<pubDate>Thu, 01 Jun 2006 00:00:00 +0000</pubDate>
		<dc:creator>Dave Stewart</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[Materials]]></category>
		<category><![CDATA[MaxScript]]></category>

		<guid isPermaLink="false">http://www.keyframesandcode.com/code/?p=146</guid>
		<description><![CDATA[This MAXScript entry has not yet been completed&#8230;

Create a set of multimaterials from a folder of textures
]]></description>
			<content:encoded><![CDATA[<p>This MAXScript entry has not yet been completed&#8230;<br />
<span id="more-146"></span><br />
Create a set of multimaterials from a folder of textures</p>
]]></content:encoded>
			<wfw:commentRss>http://www.keyframesandcode.com/code/development/maxscript/multimaterial-from-folder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

