<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">

<html>

<!--(==============================================================)-->
<!--(Document created with RoboEditor. )============================-->
<!--(==============================================================)-->

<head>

<title>Introduction to TCL</title>

<!--(Meta)==========================================================-->

<meta name=generator content="RoboHELP by eHelp Corporation - www.ehelp.com">
<meta name=generator-major-version content=0.1>
<meta name=generator-minor-version content=1>
<meta name=filetype content=kadov>
<meta name=filetype-version content=1>
<meta name=page-count content=1>
<meta name=layout-height content=1278>
<meta name=layout-width content=541>
<meta name=date content="07 24, 2002 1:53:27 PM">


<!--(Links)=========================================================-->

<link rel="StyleSheet" href="../../css/main_styles.css">



<!--(Style Sheet)===================================================-->

<style>
<!--
body {background-color: #ffffff;}
-->
</style>


</head>

<!--(Body)==========================================================-->


<body class="bodydocs" onLoad="top.pageLoader()" bgcolor="#FFFFFF">


<h1 CLASS=Section>Introduction to the Tool Command Language (TCL)</h1>

<p CLASS=Paragraph>TCL, pronounced &quot;tickle&quot; or &quot;tee see 
 ell&quot;, is an interpreted language developed by John K. Ousterhout 
 at the University of California - Berkley. TCL is currently supported 
 by Sun Microsystems, Inc. It is public domain software and available on 
 all platforms currently supported by NX.</p>

<p CLASS=Paragraph>TCL is the official NX language for &quot;user-supplied&quot; 
 rules, such as the Event Handler used by Post.</p>

<h5>Basic Syntax</h5>

<p CLASS=Paragraph>TCL code is contained in a TCL script. The script can 
 contain code inside of procs (TCL procedures) and code outside of procs. 
 The code outside of procs, is executed at the time that the interpreter 
 reads the script. The code contained inside the procs is only executed 
 when the proc is called.</p>

<p CLASS=Paragraph>The TCL language allows use of both local and global 
 variables. TCL provides numeric, string, logical, and relational operations. 
 It is very strong at string processing. The TCL language provides control 
 structures such as: if, while, for, foreach, break, continue, switch, 
 eval, expr, and source.</p>

<p CLASS=Paragraph>It provides facilities for error handling, file I/O, 
 process spawning and limited debugging capabilities. TCL allows you to 
 easily build GUI interfaces by using Tk.</p>

<h5>Example TCL Script</h5>

<p style="margin-bottom: 0;">&nbsp;</p>

<p style="margin-bottom: 0;">&nbsp;</p>

<p style="line-height: normal;
			margin-bottom: 14pt;
			margin-top: 14pt;
			x-text-tab-stops: repeat 1in;
			white-space: nowrap;
			font-size: smaller;
			font-family: monospace;">#!/usr/local/bin/tclsh<br>
<br>
proc fact x {</p>

<p style="margin-left: 40px;
			line-height: normal;
			margin-bottom: 14pt;
			margin-top: 14pt;
			x-text-tab-stops: repeat 1in;
			white-space: nowrap;
			font-size: smaller;
			font-family: monospace;">if { $x &lt;= 1 } { return 1 }<br>
expr $x * [fact [expr $x - 1]]<br>
}</p>

<p style="margin-bottom: 0;">&nbsp;</p>

<p style="line-height: normal;
			margin-bottom: 14pt;
			margin-top: 14pt;
			x-text-tab-stops: repeat 1in;
			white-space: nowrap;
			font-size: smaller;
			font-family: monospace;"># Main<br>
<br>
if { $argc != 2 } {</p>

<p style="margin-left: 40px;
			line-height: normal;
			margin-bottom: 14pt;
			margin-top: 14pt;
			x-text-tab-stops: repeat 1in;
			white-space: nowrap;
			font-size: smaller;
			font-family: monospace;">puts &quot;Usage: $argv0 &lt;input file&gt; &lt;output file&gt;&quot;<br>
exit 1</p>

<p style="line-height: normal;
			margin-bottom: 14pt;
			margin-top: 14pt;
			x-text-tab-stops: repeat 1in;
			white-space: nowrap;
			font-size: smaller;
			font-family: monospace;">}<br>
<br>
set infile [open [lindex argv 0] r]<br>
set outfile [open [lindex argv 1] w]<br>
while { [gets $infile number] &gt;= 0 } {</p>

<p style="margin-left: 40px;
			line-height: normal;
			margin-bottom: 14pt;
			margin-top: 14pt;
			x-text-tab-stops: repeat 1in;
			white-space: nowrap;
			font-size: smaller;
			font-family: monospace;">set value [fact $number]<br>
puts $outfile $value</p>

<p style="margin-bottom: 0;">&nbsp;</p>

<p style="line-height: normal;
			margin-bottom: 14pt;
			margin-top: 14pt;
			x-text-tab-stops: repeat 1in;
			white-space: nowrap;
			font-size: smaller;
			font-family: monospace;">}<br>
<br>
close $infile<br>
close $outfile<br>
<br>
#Now remove the input file<br>
exec rm [lindex argv 1]</p>

<h5>Extensions to TCL</h5>

<p CLASS=Paragraph>When creating TCL scripts and procedures you can use 
 any commands and functionality allowed by the &quot;standard&quot; TCL 
 language. In addition, TCL is highly &quot;extensible&quot;, meaning that 
 you can add new commands to the interpreter very easily.</p>

<p CLASS=Paragraph>NX has added special procedures to allow 
 you to further control the Manufacturing Output Managers output and to 
 query the NX system for values for Expression Subsystem Variables.</p>

<p CLASS=Paragraph>These special procedures were developed using the same 
 metalanguage that you will use to develop the Definition File. For more 
 information regarding the metalanguage, please refer to Definition File 
 Metalanguage.</p>

<p CLASS=Paragraph>These special procedures are listed in the Procedures 
 Added To the Translator section.</p>

<p CLASS=Paragraph
	style="margin-left: 40px;">&lt;argument&gt; indicates that the argument 
 is mandatory.</p>

<p CLASS=Paragraph
	style="margin-left: 40px;">&lt;argument&gt;+ indicates 1 or more arguments 
 may be used.</p>

<p CLASS=Paragraph
	style="margin-left: 40px;">{argument} indicates that the argument is 
 optional.</p>

<h1 style="margin-bottom: 0;">&nbsp; </h1>

</body>

</html>
