<?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>Softimage Blog &#187; C++</title>
	<atom:link href="http://www.softimageblog.com/archives/category/scripting/c/feed" rel="self" type="application/rss+xml" />
	<link>http://www.softimageblog.com</link>
	<description>People and thoughts behind Softimage in production...</description>
	<lastBuildDate>Mon, 21 Jun 2010 20:40:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Slickening up the build cycle for compiled plugins</title>
		<link>http://www.softimageblog.com/archives/268#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=slickening-up-the-build-cycle-for-compiled-plugins</link>
		<comments>http://www.softimageblog.com/archives/268#comments</comments>
		<pubDate>Thu, 19 Jun 2008 11:16:24 +0000</pubDate>
		<dc:creator>Kim Aldis</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming / Scripting]]></category>

		<guid isPermaLink="false">http://www.xsi-blog.com/?p=268</guid>
		<description><![CDATA[1. compile with copy, 2. oops, error, file in use, 3. switch to XSI, 4. dig down and unload plugin, 5. switch to VS, 6. compile &#8230;&#8230;. yaddda &#8230;.. you know the drill. 
For years I&#8217;ve been doing this and for years I&#8217;ve been meaning to get around to making it slicker but somehow there [...]]]></description>
			<content:encoded><![CDATA[<p>1. compile with copy, 2. oops, error, file in use, 3. switch to XSI, 4. dig down and unload plugin, 5. switch to VS, 6. compile &#8230;&#8230;. yaddda &#8230;.. you know the drill. </p>
<p>For years I&#8217;ve been doing this and for years I&#8217;ve been meaning to get around to making it slicker but somehow there was never time. So the other day it rained &#8211; fit to burst &#8211; and I had a day inside with nothing else to do and this is what I ended up with.</p>
<p>Earlier attempts ended up in a puddle on the floor because for some reason the only links I could find to VSS command line building pointed me at VCBuild.exe, which is just a plain old mess. This time, though, I found a link to a list of command line options for devenv.exe &#8211; what you run to bring up the VS IDE &#8211; at the excelent <a href="http://www.codeproject.com/KB/dotnet/builditemincontextmenu.aspx">codeproject.com</a> and these are much more straightforward.</p>
<p>The process is fairly simple: </p>
<p>1. unload the plugin.<br />
2. run a command line build using system()<br />
3. copy over the dll (my build has this built in)<br />
4. reload the plugin.<br />
5. test<br />
6. package</p>
<p>Step 2 involves a little bit of wrastling with .bat command line, um, features but really the code (at the end of this article) is quite simple. Because it&#8217;s scripted you can build entire plugin sets and package them in one go. The whole process takes only seconds because it&#8217;s self contained and it&#8217;s dead easy to stuff in some test code. You can easily slip back to the IDE when you need it and it makes working with a preferred text editor easier if that&#8217;s your bag.</p>
<p>There&#8217;s also the advantage that the build inherits the paths to libraries from the XSI version you&#8217;re working with. No more .bat file wrappers. Neat!</p>
<p>This example code is just a list of functions:</p>
<p>Build( solutionName, PluginName, forceRebuild   ); // do the actual build.<br />
GetConfig(); //gets the platform type (32/64)<br />
Package(  PluginName );  // package. Output name is hard coded in the example. </p>
<p>I stuff the plugin names in an array so I can build a bunch of them in one.</p>
<p>I also have a custom property I use with a dropdown list of my main projects along with build and package buttons.</p>
<p>And finally, I figure I might, next time it rains, get this working alongside package location. Who knows.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> sPlugins <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;TinyCurveExtrude&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;TinyCap&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> slnName <span style="color: #339933;">=</span> sPlugins<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> sPluginName <span style="color: #339933;">=</span> slnName <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;Plugin&quot;</span><span style="color: #339933;">;</span>
&nbsp;
Build<span style="color: #009900;">&#40;</span> slnName<span style="color: #339933;">,</span> sPluginName<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">Package</span><span style="color: #009900;">&#40;</span> sPluginName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// build the solution. doRebuild is a boolean, forces a complete compile and build if true.</span>
<span style="color: #006600; font-style: italic;">//</span>
<span style="color: #003366; font-weight: bold;">function</span> Build<span style="color: #009900;">&#40;</span> slnName<span style="color: #339933;">,</span> sPluginName<span style="color: #339933;">,</span> doRebuild <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> oPlugin <span style="color: #339933;">=</span> Application.<span style="color: #660066;">Plugins</span><span style="color: #009900;">&#40;</span> sPluginName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> sPluginFileName <span style="color: #339933;">=</span> oPlugin.<span style="color: #660066;">FileName</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>oPlugin <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		logmessage<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Can't find plugin to unload: &quot;</span> <span style="color: #339933;">+</span> sPluginName<span style="color: #339933;">,</span> siError <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	Logmessage<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Unloading Plugin &quot;</span> <span style="color: #339933;">+</span> sPluginFileName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	Application.<span style="color: #660066;">UnloadPlugin</span><span style="color: #009900;">&#40;</span> sPluginFileName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> Cmd <span style="color: #339933;">=</span> BuildCmdRoot<span style="color: #009900;">&#40;</span> slnName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> sConfig <span style="color: #339933;">=</span> GetConfig<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> sOpt <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>doRebuild<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot; /rebuild &quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot; /build &quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> sConfig <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		system<span style="color: #009900;">&#40;</span> Cmd <span style="color: #339933;">+</span> sOpt <span style="color: #339933;">+</span> sConfig <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &amp;amp; pause&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		Logmessage<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Build Failed&quot;</span><span style="color: #339933;">,</span> siError <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	LogMessage<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;ReLoading Plugin: &quot;</span> <span style="color: #339933;">+</span> sPluginFileName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	Application.<span style="color: #660066;">LoadPlugin</span><span style="color: #009900;">&#40;</span> sPluginFileName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> 
<span style="color: #006600; font-style: italic;">// get the platform type, 32 or 64 bit. Release is hard coded</span>
<span style="color: #006600; font-style: italic;">//</span>
<span style="color: #003366; font-weight: bold;">function</span> GetConfig<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> sPlatform <span style="color: #339933;">=</span> Application.<span style="color: #660066;">Platform</span><span style="color: #339933;">;</span>
	Logmessage<span style="color: #009900;">&#40;</span> sPlatform <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> sPlatform.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/win64/i</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>Release x64|x64<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> sPlatform.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/win32/i</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>Release|Win32<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	Logmessage<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Unsupported Platform: &quot;</span> <span style="color: #339933;">+</span> sPlatform<span style="color: #339933;">,</span> siError <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// build the devenv.ex command line</span>
<span style="color: #006600; font-style: italic;">// NOTE: this is set to work on a 64 bit system. Take out the (x86) and spaces </span>
<span style="color: #006600; font-style: italic;">// for 32 bit. Cross compile works well enough but you'll need the 64 bit libs</span>
<span style="color: #003366; font-weight: bold;">function</span> BuildCmdRoot<span style="color: #009900;">&#40;</span> sTargetName <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> slnRoot <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;c:<span style="color: #000099; font-weight: bold;">\\</span>fatty<span style="color: #000099; font-weight: bold;">\\</span>DEV<span style="color: #000099; font-weight: bold;">\\</span>CPP&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> vcVars <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;call <span style="color: #000099; font-weight: bold;">\&quot;</span>C:<span style="color: #000099; font-weight: bold;">\\</span>Program Files (x86)<span style="color: #000099; font-weight: bold;">\\</span>Microsoft Visual Studio 8<span style="color: #000099; font-weight: bold;">\\</span>VC<span style="color: #000099; font-weight: bold;">\\</span>vcvarsall.bat<span style="color: #000099; font-weight: bold;">\&quot;</span> x86&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> slnPath <span style="color: #339933;">=</span> slnRoot <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span> <span style="color: #339933;">+</span> sTargetName <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span> <span style="color: #339933;">+</span> sTargetName <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;.sln&quot;</span>
	<span style="color: #003366; font-weight: bold;">var</span> Cmd <span style="color: #339933;">=</span> vcVars <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; &amp;amp; devenv &quot;</span> <span style="color: #339933;">+</span> slnPath<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> Cmd<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Package.</span>
<span style="color: #006600; font-style: italic;">// ToDo: rebuild for package location.</span>
<span style="color: #006600; font-style: italic;">//</span>
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #003366; font-weight: bold;">Package</span><span style="color: #009900;">&#40;</span> sPluginName <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	logmessage<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Packaging ... &quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> sOutputPath <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;C:/Fatty/Dev/CPP/Release&quot;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> sPlatform <span style="color: #339933;">=</span> Application.<span style="color: #660066;">Platform</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> oPlugin <span style="color: #339933;">=</span> Application.<span style="color: #660066;">Plugins</span><span style="color: #009900;">&#40;</span> sPluginName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> sPluginFileName <span style="color: #339933;">=</span> oPlugin.<span style="color: #660066;">FileName</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> oAddOn <span style="color: #339933;">=</span> Application.<span style="color: #660066;">CreateAddon</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	oAddOn.<span style="color: #660066;">AddItem</span><span style="color: #009900;">&#40;</span> siPluginAddonItemType<span style="color: #339933;">,</span> oPlugin.<span style="color: #660066;">FileName</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	oAddOn.<span style="color: #660066;">DefaultInstallationPath</span> <span style="color: #339933;">=</span> siUserAddonPath<span style="color: #339933;">;</span>
	oAddOn.<span style="color: #660066;">SubDirectory</span> <span style="color: #339933;">=</span> sPluginName<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> sPluginFileName <span style="color: #339933;">=</span> sOutputPath <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/&quot;</span> <span style="color: #339933;">+</span> sPluginName <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;_&quot;</span> <span style="color: #339933;">+</span> sPlatform <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;.xsiaddon&quot;</span>
&nbsp;
	oAddOn.<span style="color: #660066;">Save</span><span style="color: #009900;">&#40;</span> sPluginFileName <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	logmessage<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Packaged to: &quot;</span> <span style="color: #339933;">+</span> sPluginFileName  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<img src="http://www.softimageblog.com/?ak_action=api_record_view&id=268&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.softimageblog.com/archives/268/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using Assert for fast C++ Development</title>
		<link>http://www.softimageblog.com/archives/82#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-assert-for-fast-c-development</link>
		<comments>http://www.softimageblog.com/archives/82#comments</comments>
		<pubDate>Wed, 18 Jan 2006 16:53:58 +0000</pubDate>
		<dc:creator>Andrew Skowronski</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://www.xsi-blog.com/?p=82</guid>
		<description><![CDATA[Using Asserts are well known tool for debugging and maintaining C++ code.  This article shows how the assert is specifically useful for the XSI C++ API]]></description>
			<content:encoded><![CDATA[<p><strong>What is an &#8220;assert&#8221;</strong><br />
The assert() function is part of the C standard library.  It permits you to break into the debugger when a condition that you don&#8217;t expect occurs, and is only active in the debug configuration.  In the &#8220;ship&#8221; binaries, that end-users will see, the assert acts as an empty macro and does absolutely nothing.  On windows, if an assert fails, you will see a message box with a &#8220;retry&#8221; button that lets you get into the debugger.</p>
<p>It is considered good practice to sprinkle all C++ code with asserts.  But as a very brief overview a typical function might contain the following sorts of asserts:</p>
<ul>
<li>Confirm expected inputs (e.g. that an input string or array is not empty)</li>
<li>Confirm expected situations during the algorithm (e.g. confirm that a local variable is holding a valid value)</li>
<li>Confirm &#8220;post&#8221; conditions (e.g. that the algorithm did what is was supposed to)</li>
</ul>
<p>The following is a bit of a &#8220;contrived&#8221; example, but it shows these three different types of asserts.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Duplicate string multiple times</span>
CString DuplicateString<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> arg1, CString <span style="color: #000040;">&amp;</span> arg2 <span style="color: #008000;">&#41;</span> 
<span style="color: #008000;">&#123;</span>
   <span style="color: #666666;">// confirm rules for the expected inputs</span>
   <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> arg1 <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
   <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> arg2.<span style="color: #007788;">IsEmpty</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
&nbsp;
  CString retVal <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;&quot;</span> <span style="color: #008080;">;</span>
  <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> <span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> arg1 <span style="color: #008080;">;</span> i<span style="color: #000040;">++</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    retVal <span style="color: #000080;">=</span> retVal  <span style="color: #000040;">+</span> arg2 <span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// Check for unexpected situation during the algorithm</span>
    <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> <span style="color: #000040;">!</span>retVal.<span style="color: #007788;">IsEmpty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #666666;">// Post condition</span>
  <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> retVal.<span style="color: #007788;">GetLength</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> arg1 <span style="color: #000040;">*</span> arg2.<span style="color: #007788;">GetLength</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> retVal <span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>It is not important to test things that you really really know are going to be valid, but &#8220;if in doubt&#8221; put an assert.  </p>
<p>Asserts are an important maintenance tool, so even if there are no bugs in your code today, you can protect your code from future modifications by adding asserts.  For example, your code may crash if the caller passes 0 as an argument.  You may know that no caller ever does that.  But some &#8220;idiot&#8221; might add a new call tomorrow that does pass 0.  So, if your code includes a built-in check for that condition you might save yourself a lot of debugging and finger pointing.</p>
<p><span id="more-82"></span><strong>Asserts and XSI SDK</strong><br />
The XSI C++ SDK is a perfect case for needing asserts.   This is because the SDK is designed not to crash.  Even if you divide by zero XSI will often catch the error and just mention that your plugin wasn&#8217;t well behaved.  It is sometimes possible to crash, especially if you corrupt memory, but the overall behavior of the API is to try to keep going, no matter what.</p>
<p>One particular issue with this fail-safe attitude is the fact that if you have a bug you can end up working with an &#8220;invalid&#8221; object.  All the methods will still work but the object won&#8217;t really be pointing to a real XSI object.  So the methods won&#8217;t be doing anything.  This can mean that a bug early in a program can lead to head scratching much later when you are trying to figure out why some methods seem to do nothing at all.</p>
<p>As a very basic example consider:</p>
</pre>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">Parameter p <span style="color: #008080;">;</span>
p.<span style="color: #007788;">PutValue</span><span style="color: #008000;">&#40;</span> <span style="color:#800080;">4.0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>This code does nothing at all.  The variable p was never initialized to a real XSI object, so setting a value on it has no effect whatsoever.  </p>
<p>Here is another example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">Null AddNullToModelAndGroup<span style="color: #008000;">&#40;</span> Model <span style="color: #000040;">&amp;</span> inModel,<span style="color: #0000ff;">const</span> CString<span style="color: #000040;">&amp;</span> inGroupName,<span style="color: #0000ff;">const</span> CString<span style="color: #000040;">&amp;</span> inNullName <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	Null newnull <span style="color: #008080;">;</span>
	inModel.<span style="color: #007788;">AddNull</span><span style="color: #008000;">&#40;</span> inNullName, newnull <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>	
&nbsp;
	Group group <span style="color: #000080;">=</span> inModel.<span style="color: #007788;">GetGroups</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">GetItem</span><span style="color: #008000;">&#40;</span> inGroupName <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
&nbsp;
	CStatus st <span style="color: #000080;">=</span> group.<span style="color: #007788;">AddMember</span><span style="color: #008000;">&#40;</span> newnull <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> newnull <span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Now this function is straightforward, but there is a lot that can go wrong.  If you call this function but discover in later testing that the Null doesn't actually exist or wasn't added to the group then you will have to scratch your head, do some debugging or add some <code>LogMessage</code> calls to try to find the solution.</p>
<p>However my suggestion is that you should sprinkle assert calls in your code directly as you write it. </p>
<p>Here is the modified function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;">Null AddNullToModelAndGroup<span style="color: #008000;">&#40;</span> Model <span style="color: #000040;">&amp;</span> inModel,	<span style="color: #0000ff;">const</span> CString<span style="color: #000040;">&amp;</span> inGroupName,	<span style="color: #0000ff;">const</span> CString<span style="color: #000040;">&amp;</span> inNullName <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> inModel.<span style="color: #007788;">IsValid</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
    <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> <span style="color: #000040;">!</span>inGroupName.<span style="color: #007788;">IsEmpty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
    <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> <span style="color: #000040;">!</span>inNullName.<span style="color: #007788;">IsEmpty</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
&nbsp;
    Null newnull <span style="color: #008080;">;</span>
    inModel.<span style="color: #007788;">AddNull</span><span style="color: #008000;">&#40;</span> inNullName, newnull <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>	
    <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> newnull.<span style="color: #007788;">IsValid</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
&nbsp;
    Group group <span style="color: #000080;">=</span> inModel.<span style="color: #007788;">GetGroups</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">GetItem</span><span style="color: #008000;">&#40;</span> inGroupName <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
    <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> group.<span style="color: #007788;">IsValid</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
&nbsp;
    CStatus st <span style="color: #000080;">=</span> group.<span style="color: #007788;">AddMember</span><span style="color: #008000;">&#40;</span> newnull <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
    <span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> st.<span style="color: #007788;">Succeeded</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> newnull <span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Some example scenarios that these asserts will catch:</p>
<ul>
<li>Invalid arguments.  This function will tell you right away if the caller passes empty strings or a bogus Model.  If these asserts fail then you can immediately blame the calling code, rather than wondering if <code>AddNullToModelAndGroup</code> is wrong.  </li>
<li>Invalid group name.  One of the most likely failures would be the case where <code>inGroupName</code> doesn't actually correspond to a real group.  If <code>assert( group.IsValid() )</code>  fails we know that the model exists, we know that <code>inGroupName</code> is not empty, and we know that there is not group by that name.</li>
<li>Failure to create the Null.  If the <code>AddNull</code> call fails we'll know about it.  Its hard to think of any reason why it would fail, given that the name is not empty, but better safe than sorry.</li>
</ul>
<p>Here are some other typical asserts you might see in XSI C++ code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> x <span style="color: #000080;">&gt;</span> <span style="color:#800080;">0.0</span> <span style="color: #000040;">&amp;&amp;</span> x <span style="color: #000080;">&lt;</span> <span style="color: #000080;">=</span> <span style="color:#800080;">5.0</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
<span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> mynull.<span style="color: #007788;">GetName</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> L<span style="color: #FF0000;">&quot;MyNullName&quot;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
<span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> points.<span style="color: #007788;">GetCount</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span>  <span style="color: #008080;">;</span>
<span style="color: #0000dd;">assert</span><span style="color: #008000;">&#40;</span> myref.<span style="color: #007788;">IsA</span><span style="color: #008000;">&#40;</span> siParameterID <span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span></pre></td></tr></table></div>

<p><strong>Tips</strong></p>
<ul>
<li>You may want to create your own assert macro, possible with a shorter name if you don't like typing a lot.</li>
<li>You may also want to create macros that are shortcuts to testing CBase::IsValid and CStatus::Succeeded as these will be the most common asserts that you write.</li>
<li>Another useful macro is one to test two floating point values with a "fudge" factor to ignore rounding errors.</li>
<li>Asserts are not a replacement for error handling.  In some cases you may need both the "debug" and the "ship" version of the code to test input arguments, log error messages or tell the XSI user that they did something wrong.  Asserts are meant to test things that should "never" happen as a way of catching bugs, while error handling should cover the bad edge scenarios that "might" happen.</li>
<li>You can add extra context strings to your assert, for example <code>assert( x > 0 &#038;&#038; "Value read inside foo is wrong" ) ;</code>.  The string will appear as part of the message box.</li>
<li>If there is code that you believe is never executed, but are afraid to delete it, try putting <code>assert( !"This should never happen.  inform so and so immediately") ;</code> inside it.  If no one contacts you after testing you can be more confident to delete the code.</li>
<li>If you are given complex code that you didn't write, and have to make changes to it, first add a lot of asserts that verify the assumptions that you find.  Make sure these asserts are valid by testing, then start changing things. The asserts will help confirm that you really understand the code and that it wasn't actually more buggy than you might have thought.</li>
</ul>
<p><strong>Conclusion</strong></p>
<p>This is just a very brief  introduction to the concept of asserts. You can find lots more details in general (non-XSI) coding practice books  (for example in "Code Complete" by Steve McConnell). Its a concept that goes beyond and particular language or program, but it is specifically useful for the XSI C++ API.</p>
<p>I can say this because I've been involved with a large C++ API project recently and I can confirm that using asserts was a good practice for fast debugging and quick stabilization of complex code. We added many asserts and used it to get meaningful information from testers and also quick entry into the debugger when testing our work.  It's not the complete solution to everything, and we use other debugging tricks, but it should be part of any robust C++ development project.    </p>
<img src="http://www.softimageblog.com/?ak_action=api_record_view&id=82&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.softimageblog.com/archives/82/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting SDK help from an external editor</title>
		<link>http://www.softimageblog.com/archives/79#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=getting-sdk-help-from-an-external-editor</link>
		<comments>http://www.softimageblog.com/archives/79#comments</comments>
		<pubDate>Fri, 23 Dec 2005 12:01:04 +0000</pubDate>
		<dc:creator>Andy Nicholas</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.xsi-blog.com/?p=79</guid>
		<description><![CDATA[If your editor supports the launching of external programs and allows you to insert text to the command line based on your current selection, then you can get context sensitive help from the XSI SDK help file. This will work for both the C++ and scripting SDKs. This snippet shows how to perform this in the Crimson Editor but it will work equally well in any other well supported editor that has this feature.
]]></description>
			<content:encoded><![CDATA[<p>If your editor supports the launching of external programs and allows you to insert text to the command line based on your current selection, then you can get context sensitive help from the XSI SDK help file. This will work for both the C++ and scripting SDKs. This snippet shows how to perform this in the Crimson Editor but it will work equally well in any other well supported editor that has this feature.</p>
<p><span id="more-79"></span>- &#8211; - &#8211; - &#8211; - &#8211; - </p>
<p>If you tend to only use commands in your scripts, then I recommend this method (which only works for commands):</p>
<p>In your editor, find where the settings are for launching external applications via a keyboard shortcut. For Crimson Editor, you can find this in the &#8220;Tools->Conf. User Tools&#8221; menu.</p>
<p>Enter the command as:</p>
<pre>C:\WINDOWS\hh.exe</pre>
<p>And the argument as:</p>
<pre>mk:@MSITStore:C:\Softimage\XSI_5.0\Doc\XSISDK\xsidevref.chm::/$(CurrWord).htm</pre>
<p>Note that you&#8217;ll need to set the path to the help file so that it&#8217;s correct on your system. Also, if you&#8217;re not using Crimson Editor, then you&#8217;ll need to change where it says <code>$(CurrWord)</code> to the correct macro for your editor, so that it adds the currently selected word to your command argument.</p>
<p>Now just associate this tool with a shortcut key, e.g. F1, and you should now be able to launch the  SDK help with a single key press to get instant reference for your command. As I said above, this only works for commands, since it relies on the naming convention of the compiled help.</p>
<p>- &#8211; - &#8211; - &#8211; - &#8211; -</p>
<p>If you want to have general context sensitive help that will work with any method, property, or command in your script, then you need to download KeyHH.exe from <a href="http://www.keyworks.net">www.keyworks.net</a>.</p>
<p>Once you&#8217;ve installed it, just use these settings:</p>
<p>Enter the command as:</p>
<pre>C:\WINDOWS\keyhh.exe</pre>
<p>And the argument as:</p>
<pre>-myhelp -#klink "$(CurrWord)" C:\Softimage\XSI_5.0\Doc\XSISDK\xsidevref.chm</pre>
<p>As mentioned above, you&#8217;ll need to change the path to work for your help file and change the <code>$(CurrWord)</code> macro to suit your editor.</p>
<p>When you launch this command, it will open the help file in Index view using the word selected in the editor. Unfortunately it doesn&#8217;t display the help page automatically, and you still need to double click the entry, but it beats the heck out of having to type it!</p>
<img src="http://www.softimageblog.com/?ak_action=api_record_view&id=79&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.softimageblog.com/archives/79/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Debugging made easier</title>
		<link>http://www.softimageblog.com/archives/78#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=debugging-made-easier</link>
		<comments>http://www.softimageblog.com/archives/78#comments</comments>
		<pubDate>Thu, 22 Dec 2005 10:26:01 +0000</pubDate>
		<dc:creator>Andy Nicholas</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.xsi-blog.com/?p=78</guid>
		<description><![CDATA[The hyperlinks generated in the Script Editor when an script error is thrown can be very helpful in finding exactly where a problem has occurred. The only issue is that if you are using an external editor, the line number is not communicated to the editor to make it automatically scroll to the line of code that produced the error.

Most standalone text editors allow for a command line parameter to indicate which line number to position the cursor when opening a new file. By making a quick change to one of XSI''s scripts, we can communicate this to the external editor. To make this change, follow the steps below. ]]></description>
			<content:encoded><![CDATA[<p>The hyperlinks generated in the Script Editor when an script error is thrown can be very helpful in finding exactly where a problem has occurred. The only issue is that if you are using an external editor, the line number is not communicated to the editor to make it automatically scroll to the line of code that produced the error.<br />
<span id="more-78"></span></p>
<p>Most standalone text editors allow for a command line parameter to indicate which line number to position the cursor when opening a new file. By making a quick change to one of XSI&#8217;&#8217;s scripts, we can communicate this to the external editor. To make this change, follow the steps below. </p>
<p><em>(By the way, I take no responsibility if something goes wrong and you have to reinstall XSI to get everything working again!)</em></p>
<ol>
<li>Navigate to C:\Softimage\&#8230;\Application\Commands</li>
<li>Create a backup copy of &#8220;SDKHelpers.js&#8221; and call it something like &#8220;SDKHelpers.js_backup&#8221;.<br />
<em>Note: it is important to change the file extension to something other than &#8220;js&#8221; as otherwise it will try to install the same commands twice and you&#8221;ll get a conflict.</em></li>
<li>Navigate to line 106. It should be inside the &#8220;ShowFileForEdit_Execute&#8221; function at the line which says :<br />
<code>if ( -1 != strExternalEditor.search( /%s/ ) )</code></li>
<li>Replace everything inside that &#8220;if&#8221; clause, i.e:
<p><code>&nbsp;&nbsp;&nbsp;&nbsp;// (Mis)use the XSIUtils.Translate() API<br />
&nbsp;&nbsp;&nbsp;&nbsp;// to replace a %s token in the string with the file<br />
&nbsp;&nbsp;&nbsp;&nbsp;// name.  This gives us lots of flexibility for supporting<br />
&nbsp;&nbsp;&nbsp;&nbsp;// different command line options for showing an external editor</code></p>
<p><code>&nbsp;&nbsp;&nbsp;&nbsp;strCmd = XSIUtils.Translate( strExternalEditor, "None", in_file ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;logmessage( "Launching " + 	strCmd, siVerbose ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;XSIUtils.LaunchProcess( strCmd, false ) ;<br />
</code></p>
<p>With this:</p>
<p><code>&nbsp;&nbsp;&nbsp;&nbsp;strExternalEditor = strExternalEditor.replace(/%s/,in_file);<br />
&nbsp;&nbsp;&nbsp;&nbsp;if ( strExternalEditor.search( /%l/ ) != -1)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strExternalEditor = strExternalEditor.replace(/%l/,in_linenum);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;XSIUtils.LaunchProcess(strExternalEditor);<br />
</code></p>
</li>
<li>Save the file and restart XSI.</li>
</ol>
<p>You can now use %l (that&#8217;&#8217;s a lowercase L) in the filename for your external editor to pass the line number at the correct position in the command line options. Note that the original script already allowed for a %s parameter to be passed as a location to insert the filename to edit, and we have retained that functionality.</p>
<p>So for example, for JEdit you would use this in the external editor setting in the Script Editor Preferences:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<code>c:\jedit\jedit %s +line:%l</code></p>
<p>Personally, I use Crimson Editor, and my external editor setting is:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<code>C:\Program Files\Crimson Editor\cedt.exe /L:%l %s</code></p>
<p>Now if a script throws an error, you can click on it and your external editor will open the file at the correct line. This should make it a lot easier to use your external editor with XSI.</p>
<p>Have a good Christmas break!</p>
<img src="http://www.softimageblog.com/?ak_action=api_record_view&id=78&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.softimageblog.com/archives/78/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The ScriptedSequencer</title>
		<link>http://www.softimageblog.com/archives/69#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-scriptedsequencer</link>
		<comments>http://www.softimageblog.com/archives/69#comments</comments>
		<pubDate>Sun, 27 Nov 2005 20:10:21 +0000</pubDate>
		<dc:creator>Andrea Interguglielmi</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[VBScript]]></category>

		<guid isPermaLink="false">http://www.xsi-blog.com/?p=69</guid>
		<description><![CDATA[When it comes to math, sometimes is hard to visualize what you are doing, if you are working with vectors and transformations the debugging process can be slow and tedious, you cannot even use primitives to trace positions and rotations if you are writing scripted operators.
My workflow was to write quick run-once scripts in the [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to math, sometimes is hard to visualize what you are doing, if you are working with vectors and transformations the debugging process can be slow and tedious, you cannot even use primitives to trace positions and rotations if you are writing scripted operators.</p>
<p>My workflow was to write quick run-once scripts in the script editor, use curves and nulls to be sure that everything was ok and then write the scripted operator. But, if scripting is meant to make your life easier, this case makes you change your mind a bit. So I decided to take advantage of both c++ and scripting by wrapping some simple OpenGL drawing functions and exposing them to scripting.</p>
<p>Since the result seems to be quite handy, I decided to make this little utility available on XSIBlog. Lionhead, the company I work for, kindly allowed me to publish it.</p>
<p><span id="more-69"></span>So here is the ScriptedSequencer, a small utility to draw vectors and rotation axis on screen.</p>
<p><img style="width: 416px; height: 303px; border-width: 0px" src="/userContent/ainterguglielmi/scriptedSequencer/sequencer.jpg" border="0" /></p>
<p>The tool uses a JScript object to wrap some c++ registered commands, you can use this object from Python and VBScript as well.</p>
<p>First get an instance of the object:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #339933;">=</span> NewSequencer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>then call one of the drawing functions:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> vec <span style="color: #339933;">=</span> XSIMath.<span style="color: #660066;">CreateVector3</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
vec.<span style="color: #660066;">Set</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> s.<span style="color: #660066;">DrawVector</span><span style="color: #009900;">&#40;</span>vec<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>to erase the stack and start again use:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">s.<span style="color: #660066;">Flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>All the drawings are collected by the c++ plug-in and then rendered at the right time using the GraphicSequencer, so you don&#8217;t have to care about synchronizing with the viewport&#8217;s OpenGL rendering, which means in other words that you can draw OpenGL stuff from wherever you are, run once scripts, scripted operators or compiled plug-ins at any moment.</p>
<p>As it is nothing more than a debugging utility it doesn&#8217;t support multiple clients, it means that every time you&#8217;ll flush the stack all the drawings drawn by every script will be flushed at once.</p>
<p>By typing <code>NewSequencer().Help()</code> you&#8217;ll get a quick help about the sequencer object and its methods.</p>
<p>I hope you&#8217;ll find it useful to debug your scripts!</p>
<p>Please note that this utility is not released by Lionhead Ltd., it is not covered by any guarantee and nobody is responsible in any way for any possible troubleshoot.</p>
<p>Download the ScriptedSequencer addon and a sample scene <a href="/userContent/upload/ScriptedSequencer1.zip">here</a> (XSI 5.X required).</p>
<p>You are more than welcome to report possible bugs or give me suggestions, just drop me a line at <a href="mailto:andrea@ray-t.net">andrea@ray-t.net</a>.</p>
<img src="http://www.softimageblog.com/?ak_action=api_record_view&id=69&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.softimageblog.com/archives/69/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Unofficial plugin type: Interactive Manipulators</title>
		<link>http://www.softimageblog.com/archives/55#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=unofficial-plugin-type-interactive-manipulators</link>
		<comments>http://www.softimageblog.com/archives/55#comments</comments>
		<pubDate>Mon, 17 Oct 2005 22:29:17 +0000</pubDate>
		<dc:creator>Andrea Interguglielmi</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Programming / Scripting]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.xsi-blog.com/?p=55</guid>
		<description><![CDATA[This post is about writing interactive manipulators such as the transform tool or the newly introduced tweak tool, something XSI doesn&#8217;t support in its catalog of plugin types by default, but still possible to develop by going through a crazy round trip.

When it comes to real-time plug-ins, XSI allows writing custom operators able to react [...]]]></description>
			<content:encoded><![CDATA[<p>This post is about writing interactive manipulators such as the transform tool or the newly introduced tweak tool, something XSI doesn&#8217;t support in its catalog of plugin types by default, but still possible to develop by going through a crazy round trip.</p>
<p><img src="/userContent/ainterguglielmi/Guy.jpg" alt="Guy" align="left" hspace="10" vspace="5"/></p>
<p>When it comes to real-time plug-ins, XSI allows writing custom operators able to react to inputs and produce outputs, but what if the input we need is the mouse?</p>
<p>We haven&#8217;t got any mouse operator or event in the SDK yet, in fact all this kind of tools in XSI are emended into the core, but fortunately for us, we still have some tricks by our side to fill this gap and write our own interactive tools.</p>
<p>In the example bellow I&#8217;ve done a test, a custom manipulator to &#8220;sketch&#8221; the pose of a character by tracing quick strokes.</p>
<p><a href="/userContent/ainterguglielmi/Sketch.mov">Download the example movie.</a></p>
<p>The tool is in fact a fully functional and integrated manipulator, it is done by using some windows functions to &#8220;steal&#8221; the mouse from XSI. Under XSI&#8217;s SDK workgroup directory there&#8217;s a great example about this topic: UserNormalEditing by Alain Laferriere, thanks for sharing Alain!</p>
<p>Then, to interact with the objects in scene I&#8217;ve used a custom display pass plug-in. For any object of interest there is an OpenGL primitive with a reference to the object in scene, OpenGL picking algorithm does the rest of the job by returning what&#8217;s under the mouse pointer.</p>
<p>Every time an event is fired from the mouse a refresh-viewport command is executed, at this point from the custom display pass a check occurs to get the currently picked object.</p>
<p>I&#8217;m thinking as next step to add the possibility of scripting all this mess ;)</p>
<p>I love this new plugin type!</p>
<p>Andrea</p>
<img src="http://www.softimageblog.com/?ak_action=api_record_view&id=55&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.softimageblog.com/archives/55/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
<enclosure url="http://www.ray-t.net/Downloads/Sketch.mov" length="4326515" type="video/quicktime" />
		</item>
	</channel>
</rss>
