`
web3d
  • 浏览: 83513 次
  • 性别: Icon_minigender_1
  • 来自: 南昌
社区版块
存档分类
最新评论

通过实例学习Virtools脚本语言VSL - 从数组读取字符串

 
阅读更多
<p>该系统演示了怎样用VSL从数组读取字符串,它是习题4的逆过程。</p>
<ol>
<li>开始,创建一个数组,进入"Array Setup"面板对它进行编辑。<br>
根据你的喜欢穿件一些列(Column),并创建几行。<br>
现在再在每个单元格中填充一些文本。
</li>
<li> 你的数组可能会像下面这个样子:<br><br><div>
<div style="display: block; text-align: left;">
<a href="https://sites.google.com/site/x3dofcn/vsl-virtools/Examples/6_stringarray/example6.jpg?attredirects=0"><img src="https://sites.google.com/site/x3dofcn/_/rsrc/1245510842861/vsl-virtools/Examples/6_stringarray/example6.jpg" border="0" alt=""></a>
</div>
</div>
</li>
<li>在层级(Level)下创建一个脚本,并添加一个Run VSL BB。在VSL Script Manager工作区中,为该BB添加一个名为的"myarray"的pIn参数,类型为"Array"。编辑该参数,并将它设置给你的数组。<br><pre>void main()<br>
{<br><span>// Array where we will put the strings that will be read.</span>
<br>
ArrayString arrayString;<br><br><span>// String as temporary buffer.</span>
<br>
String tmp;<br><br><span>// Loop to read each array's cell.</span>
<br>
for (int c = 0; c &lt; myarray.GetColumnCount(); ++c) {<br>
for (int r = 0; r &lt; myarray.GetRowCount(); ++r) { <br><br><span>// First we get the size of the string at pos (r, c)<br>
// (zero included)</span>
<br>
int lengthToRead = myarray.GetElementStringValue(r, c, null);<br><br><span>// Then we resize the string before reading the array.<br></span>
tmp.Resize(lengthToRead-1);<br><br><span>// At last, we can read the string.<br>
// Note that 3rd parameter of GetElementStringValue is a str<br>
// and not an String. </span>
<br>
myarray.GetElementStringValue(r, c, tmp.Str());<br><br><span>// We keep the read string in our array.</span>
<br>
arrayString.PushBack(tmp);<br>
}<br>
}<br><br><span>// We can do what we want with these strings.</span>
<br>
int stringNb = arrayString.Size();<br>
for (int i = 0; i &lt; stringNb; ++i) {<br>
bc.OutputToConsole(arrayString[i].Str());<br>
}<br>
}<br></pre>
</li>
</ol>
<p>
<br>
现在可以去看看<strong>Virtools Minisite</strong>
中提供更多的VSL技术性样例,位置在Dev的文档文件夹下 /CMOS/TechnicalSamples/VSL/Samples/.。</p>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics