<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https:///api.php?action=feedcontributions&amp;feedformat=atom&amp;user=WikiSysop</id>
	<title>TexGen - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https:///api.php?action=feedcontributions&amp;feedformat=atom&amp;user=WikiSysop"/>
	<link rel="alternate" type="text/html" href=""/>
	<updated>2026-05-04T20:05:53Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.11</generator>
	<entry>
		<id></id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-12T15:29:47Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* TexGen&lt;br /&gt;
** mainpage|mainpage&lt;br /&gt;
** Download TexGen|Download&lt;br /&gt;
** Windows Installation|Windows Installation&lt;br /&gt;
** Compiling from Source|Source Installation&lt;br /&gt;
** Documentation|Documentation&lt;br /&gt;
** TexGen Applications|Applications&lt;br /&gt;
** Screenshots|Screenshots&lt;br /&gt;
** http://texgen.sourceforge.net/phpBB3/index.php|Forum&lt;br /&gt;
** http://sourceforge.net/projects/texgen/|SourceForge&lt;br /&gt;
* Wiki&lt;br /&gt;
** recentchanges-url|recentchanges&lt;br /&gt;
** randompage-url|randompage&lt;br /&gt;
** http://meta.wikimedia.org/wiki/Help:Editing|Editing help&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-12T15:28:22Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* TexGen&lt;br /&gt;
** mainpage|mainpage&lt;br /&gt;
** Download TexGen|download&lt;br /&gt;
** Download TexGen|Download&lt;br /&gt;
** Windows Installation|Windows Installation&lt;br /&gt;
** Compiling from Source|Source Installation&lt;br /&gt;
** Documentation|Documentation&lt;br /&gt;
** TexGen Applications|Applications&lt;br /&gt;
** Screenshots|Screenshots&lt;br /&gt;
** http://texgen.sourceforge.net/phpBB3/index.php|Forum&lt;br /&gt;
** http://sourceforge.net/projects/texgen/|SourceForge&lt;br /&gt;
* Wiki&lt;br /&gt;
** recentchanges-url|recentchanges&lt;br /&gt;
** randompage-url|randompage&lt;br /&gt;
** http://meta.wikimedia.org/wiki/Help:Editing|Editing help&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-12T15:27:55Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* TexGen&lt;br /&gt;
** mainpage|mainpage&lt;br /&gt;
** Download TexGen|Download&lt;br /&gt;
** Download TexGen|Download&lt;br /&gt;
** Windows Installation|Windows Installation&lt;br /&gt;
** Compiling from Source|Source Installation&lt;br /&gt;
** Documentation|Documentation&lt;br /&gt;
** TexGen Applications|Applications&lt;br /&gt;
** Screenshots|Screenshots&lt;br /&gt;
** http://texgen.sourceforge.net/phpBB3/index.php|Forum&lt;br /&gt;
** http://sourceforge.net/projects/texgen/|SourceForge&lt;br /&gt;
* Wiki&lt;br /&gt;
** recentchanges-url|recentchanges&lt;br /&gt;
** randompage-url|randompage&lt;br /&gt;
** http://meta.wikimedia.org/wiki/Help:Editing|Editing help&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-12T15:24:24Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* TexGen&lt;br /&gt;
** mainpage|mainpage&lt;br /&gt;
** Download TexGen|Download&lt;br /&gt;
** Windows Installation|Windows Installation&lt;br /&gt;
** Compiling from Source|Source Installation&lt;br /&gt;
** Documentation|Documentation&lt;br /&gt;
** TexGen Applications|Applications&lt;br /&gt;
** Screenshots|Screenshots&lt;br /&gt;
** http://texgen.sourceforge.net/phpBB3/index.php|Forum&lt;br /&gt;
** http://sourceforge.net/projects/texgen/|SourceForge&lt;br /&gt;
* Wiki&lt;br /&gt;
** recentchanges-url|recentchanges&lt;br /&gt;
** randompage-url|randompage&lt;br /&gt;
** http://meta.wikimedia.org/wiki/Help:Editing|Editing help&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Download TexGen</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-12T14:16:38Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot; Download Texgen&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Download Texgen&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-12T14:15:05Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* TexGen&lt;br /&gt;
** mainpage|mainpage&lt;br /&gt;
** http://sourceforge.net/project/showfiles.php?group_id=181000| Download&lt;br /&gt;
** Download TexGen|Download&lt;br /&gt;
** Windows Installation|Windows Installation&lt;br /&gt;
** Compiling from Source|Source Installation&lt;br /&gt;
** Documentation|Documentation&lt;br /&gt;
** TexGen Applications|Applications&lt;br /&gt;
** Screenshots|Screenshots&lt;br /&gt;
** http://texgen.sourceforge.net/phpBB3/index.php|Forum&lt;br /&gt;
** http://sourceforge.net/projects/texgen/|SourceForge&lt;br /&gt;
* Wiki&lt;br /&gt;
** recentchanges-url|recentchanges&lt;br /&gt;
** randompage-url|randompage&lt;br /&gt;
** http://meta.wikimedia.org/wiki/Help:Editing|Editing help&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>TexGen Applications</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-03T09:14:36Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Protected &amp;quot;TexGen Applications&amp;quot;: Excessive spamming ([edit=sysop] (indefinite) [move=sysop] (indefinite)) [cascading]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Originally developed at the University of Nottingham to describe textile composite reinforcements, TexGen has various applications in modelling dry fabric mechanics, fluid flow through fabrics and mechanics of textile composites. This page contains information on published and current research activity related to TexGen. Further information is available on the [http://www.textiles.nottingham.ac.uk/ textile composite research pages] at the University of Nottingham.&lt;br /&gt;
&lt;br /&gt;
* [[Textile mechanics]]&lt;br /&gt;
&lt;br /&gt;
* [[Textile permeability]]&lt;br /&gt;
&lt;br /&gt;
* [[Textile composite mechanics]]&lt;br /&gt;
&lt;br /&gt;
* [[Textile composite heat transfer]]&lt;br /&gt;
&lt;br /&gt;
* [[Textile composite viscous forming]]&lt;br /&gt;
&lt;br /&gt;
* [[Other applications]]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Documentation</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-03T09:14:07Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Protected &amp;quot;Documentation&amp;quot; ([edit=sysop] (indefinite) [move=sysop] (indefinite)) [cascading]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following documentation is available:&lt;br /&gt;
&lt;br /&gt;
* [[User Guide]] - Guide to using the TexGen graphical user interface&lt;br /&gt;
* [[Scripting Guide]] - Guide to writing Python scripts for generating TexGen models&lt;br /&gt;
* [http://texgen.sourceforge.net/api/ API Reference Guide] - Reference guide for Python scripting&lt;br /&gt;
* [[TG3 File Format]] - TexGen save file format description&lt;br /&gt;
* [[TexGen Applications]] - Published applications of TexGen&lt;br /&gt;
* [http://etheses.nottingham.ac.uk/archive/00000303/01/thesis-final.pdf Modelling Theory] - Much of the theory behind TexGen can be found in this thesis (Chapters 2 and 3)&lt;br /&gt;
* [http://texgen.sourceforge.net/documents/TexGen_17_10_07.pdf Presentation Slides] - Some slides from a presentation made on TexGen on the 17/10/07&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Windows Installation</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-03T09:13:46Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Protected &amp;quot;Windows Installation&amp;quot;: Excessive spamming ([edit=sysop] (indefinite) [move=sysop] (indefinite)) [cascading]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
==Download==&lt;br /&gt;
TexGen is hosted on sourceforge and the latest version can be [http://sourceforge.net/project/showfiles.php?group_id=181000 downloaded here]. As of version 3.2.0 you have a choice between two version: &amp;#039;&amp;#039;texgen-3.x.x.exe&amp;#039;&amp;#039; and &amp;#039;&amp;#039;texgen-bundle-3.x.x.exe&amp;#039;&amp;#039;. TexGen requires the Python interpreter to be installed in order to run. The standard installation package named &amp;#039;&amp;#039;texgen-3.x.x.exe&amp;#039;&amp;#039; does not include Python and must be installed manually. The bundle installation package comes with the Python interpreter which means that it does not need to be installed manually.&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t know what Python is or you won&amp;#039;t be using it for anything other than TexGen then the bundle package is recommended. For experienced users, the standard installation package is preferable since it will integrate itself with an existing python installation giving existing Python scripts access to TexGen.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
===Prerequisites===&lt;br /&gt;
If you didn&amp;#039;t download the bundle installer than you will need to have Python 2.5 installed, otherwise you can skip this step. &amp;quot;Python 2.5.x Windows installer&amp;quot; can be [http://www.python.org/download/ found here]. Note that even users with a 64 bit system should NOT install the AMD64 or Itanium version of Python (see FAQ for more information).&lt;br /&gt;
&lt;br /&gt;
===Install===&lt;br /&gt;
Run the installer and follow the on screen instructions. Again if you didn&amp;#039;t download the bundle installer there are a few extra steps to complete during the installation. You will be asked to specify where Python has been installed. The installer should detect this automatically if all goes well, if not you must specify the directory manually. This is necessary because TexGen will install an extension module in the Python directory. This is so that Python scripts can be executed from anywhere on the system. Since the TexGen graphical user interface also relies on the Python interface to function, it will not work unless this step is completed correctly.&lt;br /&gt;
&lt;br /&gt;
===Running===&lt;br /&gt;
If TexGen has successfully been installed you should be able to run it from the start menu:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Start &amp;amp;rarr; Programs &amp;amp;rarr; TexGen &amp;amp;rarr; TexGen&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Visit the [[User Guide]] section for information on using TexGen.&lt;br /&gt;
&lt;br /&gt;
==FAQ==&lt;br /&gt;
===python25.dll not found, how do i fix it?===&lt;br /&gt;
&lt;br /&gt;
Normally python25.dll should be placed in windows\system32 directory on installation of Python. In some cases this may not happen, python25.dll may be placed in your Python installation directory instead. If this happens TexGen will not know where to look for it, to solve the issue copy python25.dll from the Python directory to the TexGen directory.&lt;br /&gt;
&lt;br /&gt;
If you have a 64 bit processor (AMD64 or Itanium) and have installed the &amp;quot;Python Windows AMD64 installer&amp;quot; or &amp;quot;Python Windows Itanium installer&amp;quot; TexGen will not function correctly. This is because TexGen is compiled as a 32 bit application and as such cannot link against a 64 bit library&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Windows_XP_Pro_x64#Compatibility_with_32-bit_applications&amp;lt;/ref&amp;gt;. You must un-install Python and install the &amp;quot;Python Windows installer&amp;quot; instead which has been compiled as 32 bit. You may also need locate and copy the python25.dll manually into the TexGen folder, look for it in the windows\SysWoW64 directory. In the future a 64 bit version of TexGen may be provided in binary form but until then you must use the 32 bit version of Python or compile TexGen from source.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-10-03T09:12:33Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Changed protection level for &amp;quot;Main Page&amp;quot;: Excessive spamming ([edit=sysop] (indefinite) [move=sysop] (indefinite)) [cascading]&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
[[Image:3Tex Vf 0.55.png|thumb|3d orthogonal woven fabric]]&lt;br /&gt;
[[Image:2DWeave.png|thumb|2d woven fabric]]&lt;br /&gt;
[[Image:Ncf.png|thumb|Non-crimp fabric]]&lt;br /&gt;
[[Image:Triaxialbraid.png|thumb|Triaxial braid fabric]]&lt;br /&gt;
[[Image:Weftknit.png|thumb|Weft knit fabric]]&lt;br /&gt;
&lt;br /&gt;
TexGen is open source software licensed under the General Public License developed at the University of Nottingham for modelling the geometry of textile structures. TexGen has been used by the Nottingham team as the basis of models for a variety of properties, including textile mechanics, permeability and composite mechanical behaviour.&lt;br /&gt;
&lt;br /&gt;
A summary of our work involving TexGen can be found on the [[TexGen Applications]] page. Please also visit the [http://www.textiles.nottingham.ac.uk/ University of Nottingham Textile Composites Research] website for more details about our research group.&lt;br /&gt;
&lt;br /&gt;
On this website you will find all the information necessary to get started with TexGen by using the sidebar for navigation.&lt;br /&gt;
&lt;br /&gt;
Please leave a message on the [http://texgen.sourceforge.net/phpBB3/index.php TexGen forum] if you find TexGen to be a useful tool. We are very interested to hear about research conducted with TexGen. The [http://texgen.sourceforge.net/phpBB3/index.php forum] is also the place to ask questions, make comments and generally discuss about TexGen with other users.&lt;br /&gt;
&lt;br /&gt;
Specific bug reports, feature requests and patches are always welcome and should be directed to the [http://sourceforge.net/tracker/?group_id=181000 sourceforge trackers].&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
===TexGen 3.4.1 Released! ===&lt;br /&gt;
Version 3.4.1 has been released. This contains minor changes to ABAQUS voxel mesh output and some bug fixes.&lt;br /&gt;
A list of changes can be found [https://sourceforge.net/projects/texgen/files//texgen/3.4.1/README/view here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;15:09, 22 June 2011 (GMT)&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===TexGen 3.4.0 Released! ===&lt;br /&gt;
Version 3.4.0 has been released. It contains the addition of periodic boundary conditions to the Abaqus voxel mesh output.  The dry fibre volume mesh intersection correction has been improved and an additional option added to regenerate the textile model using the adapted mesh following correction.  There are also some bug fixes.&lt;br /&gt;
A list of changes can be found [https://sourceforge.net/projects/texgen/files//texgen/3.4.0/ReleaseNotes3.4.0.txt/view here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;14:49, 16 March 2011 (GMT)&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== TexGen 3.3.3 Released! ===&lt;br /&gt;
Version 3.3.3 has been released.  It contains new features to save fibre and/or matrix as a voxel mesh in Abaqus format, to assign fibre properties to individual yarns and to adjust for small intersections in dry fibre volume mesh when outputting to Abaqus format.  There are also some bug fixes.&lt;br /&gt;
A list of changes can be found [https://sourceforge.net/projects/texgen/files//texgen/3.3.3/ReleaseNotes3.3.3.txt/view here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;4 November 2010&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== TexGen 3.3.2 Released! ===&lt;br /&gt;
Version 3.3.2 has been released.  It contains new features to save fibre models to Abaqus output, render fibre volume mesh and render interference depth.  There are also some bug fixes, in particular a couple to get the GUI working in the Linux version.&lt;br /&gt;
A list of changes can be found [https://sourceforge.net/projects/texgen/files/texgen/3.3.2/Release%20notes3-3-2.txt/view here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;15 June 2010&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===TexGen 3.3.1 Released! ===&lt;br /&gt;
&lt;br /&gt;
Version 3.3.1 has been released (currently only Windows versions). It contains a couple of bug fixes and an option to switch output of messages on and off.  A list of changes can be found [https://sourceforge.net/projects/texgen/files/texgen/3.3.1/Release%20notes3-3-1.txt/view here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;17 March 2010&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== TexGen 3.3.0 Released! ===&lt;br /&gt;
&lt;br /&gt;
Version 3.3.0 has been released, it has various bug fixes most notably to the volume mesher and a few new algorithms dealing with geometry prediction based on mechanical behaviour of yarns. A list of changes can be found [https://sourceforge.net/project/shownotes.php?group_id=181000&amp;amp;release_id=591019 here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;16:52, 9 April 2008 (GMT)&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== TexGen 3.2.1 Released! ===&lt;br /&gt;
&lt;br /&gt;
Version 3.2.1 has been released, this is mainly a bug fix release however there are a few new features. A list of changes can be found [http://sourceforge.net/project/shownotes.php?release_id=553663&amp;amp;group_id=181000 here].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;04:12, 13 November 2007 (PST)&amp;lt;/small&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Documentation</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-09-27T11:48:48Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following documentation is available:&lt;br /&gt;
&lt;br /&gt;
* [[User Guide]] - Guide to using the TexGen graphical user interface&lt;br /&gt;
* [[Scripting Guide]] - Guide to writing Python scripts for generating TexGen models&lt;br /&gt;
* [http://texgen.sourceforge.net/api/ API Reference Guide] - Reference guide for Python scripting&lt;br /&gt;
* [[TG3 File Format]] - TexGen save file format description&lt;br /&gt;
* [[TexGen Applications]] - Published applications of TexGen&lt;br /&gt;
* [http://etheses.nottingham.ac.uk/archive/00000303/01/thesis-final.pdf Modelling Theory] - Much of the theory behind TexGen can be found in this thesis (Chapters 2 and 3)&lt;br /&gt;
* [http://texgen.sourceforge.net/documents/TexGen_17_10_07.pdf Presentation Slides] - Some slides from a presentation made on TexGen on the 17/10/07&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>MediaWiki:Sidebar</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2011-03-18T13:36:16Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* TexGen&lt;br /&gt;
** mainpage|mainpage&lt;br /&gt;
** http://sourceforge.net/project/showfiles.php?group_id=181000| Download&lt;br /&gt;
** Windows Installation|Windows Installation&lt;br /&gt;
** Compiling from Source|Source Installation&lt;br /&gt;
** Documentation|Documentation&lt;br /&gt;
** TexGen Applications|Applications&lt;br /&gt;
** Screenshots|Screenshots&lt;br /&gt;
** http://texgen.sourceforge.net/phpBB3/index.php|Forum&lt;br /&gt;
** http://sourceforge.net/projects/texgen/|SourceForge&lt;br /&gt;
* Wiki&lt;br /&gt;
** recentchanges-url|recentchanges&lt;br /&gt;
** randompage-url|randompage&lt;br /&gt;
** http://meta.wikimedia.org/wiki/Help:Editing|Editing help&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Examples</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-15T09:02:12Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains a number of example scripts which show off some of the more advanced classes used to achieve specific tasks within TexGen. This functionality is not &amp;#039;&amp;#039;yet&amp;#039;&amp;#039; accessible from the graphical user interface.&lt;br /&gt;
&lt;br /&gt;
=== Geometry Solver ===&lt;br /&gt;
&lt;br /&gt;
The theory behind the geometry solver is described in a paper submitted to &amp;quot;The First World Conference on 3D Fabrics and Their Applications&amp;quot; held in Manchester on the 10-11th of April 2008 titled &amp;quot;Prediction of textile geometry using strain energy minimisation&amp;quot;. A longer more detailed version of this will shortly be submitted as a journal paper.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
# Read in a textile&lt;br /&gt;
ReadFromXML(&amp;#039;800s4.tg3&amp;#039;)&lt;br /&gt;
Textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# Create an instance of the geometry solver&lt;br /&gt;
Solver = CGeometrySolver()&lt;br /&gt;
&lt;br /&gt;
# Set some parameters&lt;br /&gt;
Solver.SetContactStiffness(1e6)&lt;br /&gt;
Solver.SetDisabledStiffness(1e-6)&lt;br /&gt;
Solver.SetSeed(1.0)&lt;br /&gt;
# Create the system of equations to be solved&lt;br /&gt;
Solver.CreateSystem(Textile)&lt;br /&gt;
# Solve the system&lt;br /&gt;
Solver.SolveSystem()&lt;br /&gt;
# Save the result to a VTK file for viewing purposes&lt;br /&gt;
Solver.SaveToVTK(&amp;quot;GeomSolve&amp;quot;)&lt;br /&gt;
# Deform the textile&lt;br /&gt;
Solver.DeformTextile()&lt;br /&gt;
# Save the result back to a TG3 file&lt;br /&gt;
SaveToXML(&amp;#039;Def-800s4.tg3&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ABAQUS Dry Fabric Simulation ===&lt;br /&gt;
&lt;br /&gt;
This code consists of running ABAQUS dry fabric simulations from TexGen geometrical models and using the results to modify that model. The basic procedure is outlined below:&lt;br /&gt;
&lt;br /&gt;
* TexGen meshes the yarns using a combination of Hexahedral and Wedge elements.&lt;br /&gt;
* TexGen generates an ABAQUS input file which contains the mesh, element orientations, element volume fractions, material definitions, contact surfaces and definitions, compression plates, periodic boundary conditions and loading steps. Some of this information cannot be determined automatically by TexGen, in these cases they must be specified by the user. These are material definitions, loading steps and initial gap between compression plates if they are to be included.&lt;br /&gt;
* TexGen launches ABAQUS feeding it the input file generated and waits for the process to terminate before continuing. In the case where the simulation failed for an unknown reason an error message is printed and it is up to the user to determine what went wrong.&lt;br /&gt;
* If the simulation succeeded TexGen parses the ABAQUS .dat file to obtain the nodal displacements and .inp file to obtain element connectivity. Using this information, the yarn path and cross-sections of the TexGen model are deformed by the predicted displacement field.&lt;br /&gt;
&lt;br /&gt;
The theory behind this will be described in more depth in a journal paper. Until then the following short example script shows how to use this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Abaqus import *&lt;br /&gt;
&lt;br /&gt;
# Define a linear transformation&lt;br /&gt;
tension = CLinearTransformation()&lt;br /&gt;
# Add a scale in the X direction&lt;br /&gt;
tension.Scale(1.1)&lt;br /&gt;
&lt;br /&gt;
# Create an instance of the TextileDeformerAbaqus class&lt;br /&gt;
deformer = TextileDeformerAbaqus()&lt;br /&gt;
# Add the tensile deformation step&lt;br /&gt;
deformer.AddDeformationStep(tension)&lt;br /&gt;
&lt;br /&gt;
# Read in a TexGen model&lt;br /&gt;
ReadFromXML(&amp;#039;pweave.tg3&amp;#039;)&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# This is where all the work is done, note this may take a long time to run&lt;br /&gt;
deformer.DeformTextile(textile)&lt;br /&gt;
&lt;br /&gt;
# Save the result back to a new TexGen model&lt;br /&gt;
SaveToXML(&amp;#039;pweave-tensioned.tg3&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Guide</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-15T09:00:37Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Python Interface==&lt;br /&gt;
[http://www.python.org/ Python] is a high level interpreted programming language. In this case it is used as a scripting language to allow easy access to TexGen functionality. Python has been embedded in the TexGen GUI which allows the GUI to run python scripts. The goal of this tutorial is not to teach Python programming, there are plenty of resources online for that. A few of them are listed below:&lt;br /&gt;
&lt;br /&gt;
* [http://www.poromenos.org/tutorials/python Learn Python in 10 minutes] - Quick introduction to Python for competent programmers.&lt;br /&gt;
* [http://docs.python.org/tut/tut.html Python Tutorial] - Official Python tutorial (requires some programming knowledge).&lt;br /&gt;
* [http://www.greenteapress.com/thinkpython/ How to Think Like a Computer Scientist: Learning with Python] - Book on Python programming for beginners. [http://www.greenteapress.com/thinkpython/html/ HTML Version]&lt;br /&gt;
* [http://diveintopython.org/ Dive Into Python] - In depth book covering advanced subjects in a comprehensive manner. [http://diveintopython.org/toc/index.html HTML Version]&lt;br /&gt;
&lt;br /&gt;
An advanced knowledge of Python is not needed in order to write simple TexGen scripts. However, bear in mind that Python is a very powerful language with many libraries included for performing common tasks.&lt;br /&gt;
&lt;br /&gt;
A series of tutorials on getting started with using Python in conjunction with TexGen are provided below. They have been written in such a way that they are best read sequentially since each one follows on from the previous:&lt;br /&gt;
&lt;br /&gt;
* [[Scripting Create Models]]&lt;br /&gt;
* [[Scripting Export Mesh]]&lt;br /&gt;
* [[Scripting Examples]]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Examples</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-15T08:59:55Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains a number of example scripts which show off some of the more advanced classes used to achieve specific tasks within TexGen.&lt;br /&gt;
&lt;br /&gt;
=== Geometry Solver ===&lt;br /&gt;
&lt;br /&gt;
The theory behind the geometry solver is described in a paper submitted to &amp;quot;The First World Conference on 3D Fabrics and Their Applications&amp;quot; held in Manchester on the 10-11th of April 2008 titled &amp;quot;Prediction of textile geometry using strain energy minimisation&amp;quot;. A longer more detailed version of this will shortly be submitted as a journal paper.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
# Read in a textile&lt;br /&gt;
ReadFromXML(&amp;#039;800s4.tg3&amp;#039;)&lt;br /&gt;
Textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# Create an instance of the geometry solver&lt;br /&gt;
Solver = CGeometrySolver()&lt;br /&gt;
&lt;br /&gt;
# Set some parameters&lt;br /&gt;
Solver.SetContactStiffness(1e6)&lt;br /&gt;
Solver.SetDisabledStiffness(1e-6)&lt;br /&gt;
Solver.SetSeed(1.0)&lt;br /&gt;
# Create the system of equations to be solved&lt;br /&gt;
Solver.CreateSystem(Textile)&lt;br /&gt;
# Solve the system&lt;br /&gt;
Solver.SolveSystem()&lt;br /&gt;
# Save the result to a VTK file for viewing purposes&lt;br /&gt;
Solver.SaveToVTK(&amp;quot;GeomSolve&amp;quot;)&lt;br /&gt;
# Deform the textile&lt;br /&gt;
Solver.DeformTextile()&lt;br /&gt;
# Save the result back to a TG3 file&lt;br /&gt;
SaveToXML(&amp;#039;Def-800s4.tg3&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ABAQUS Dry Fabric Simulation ===&lt;br /&gt;
&lt;br /&gt;
This code consists of running ABAQUS dry fabric simulations from TexGen geometrical models and using the results to modify that model. The basic procedure is outlined below:&lt;br /&gt;
&lt;br /&gt;
* TexGen meshes the yarns using a combination of Hexahedral and Wedge elements.&lt;br /&gt;
* TexGen generates an ABAQUS input file which contains the mesh, element orientations, element volume fractions, material definitions, contact surfaces and definitions, compression plates, periodic boundary conditions and loading steps. Some of this information cannot be determined automatically by TexGen, in these cases they must be specified by the user. These are material definitions, loading steps and initial gap between compression plates if they are to be included.&lt;br /&gt;
* TexGen launches ABAQUS feeding it the input file generated and waits for the process to terminate before continuing. In the case where the simulation failed for an unknown reason an error message is printed and it is up to the user to determine what went wrong.&lt;br /&gt;
* If the simulation succeeded TexGen parses the ABAQUS .dat file to obtain the nodal displacements and .inp file to obtain element connectivity. Using this information, the yarn path and cross-sections of the TexGen model are deformed by the predicted displacement field.&lt;br /&gt;
&lt;br /&gt;
The theory behind this will be described in more depth in a journal paper. Until then the following short example script shows how to use this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Abaqus import *&lt;br /&gt;
&lt;br /&gt;
# Define a linear transformation&lt;br /&gt;
tension = CLinearTransformation()&lt;br /&gt;
# Add a scale in the X direction&lt;br /&gt;
tension.Scale(1.1)&lt;br /&gt;
&lt;br /&gt;
# Create an instance of the TextileDeformerAbaqus class&lt;br /&gt;
deformer = TextileDeformerAbaqus()&lt;br /&gt;
# Add the tensile deformation step&lt;br /&gt;
deformer.AddDeformationStep(tension)&lt;br /&gt;
&lt;br /&gt;
# Read in a TexGen model&lt;br /&gt;
ReadFromXML(&amp;#039;pweave.tg3&amp;#039;)&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# This is where all the work is done, note this may take a long time to run&lt;br /&gt;
deformer.DeformTextile(textile)&lt;br /&gt;
&lt;br /&gt;
# Save the result back to a new TexGen model&lt;br /&gt;
SaveToXML(&amp;#039;pweave-tensioned.tg3&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Examples</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-15T08:48:36Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Geometry Solver */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains a number of example scripts which show off some of the more advanced classes used to achieve specific tasks within TexGen.&lt;br /&gt;
&lt;br /&gt;
=== Geometry Solver ===&lt;br /&gt;
&lt;br /&gt;
The theory behind the geometry solver is described in a paper submitted to &amp;quot;The First World Conference on 3D Fabrics and Their Applications&amp;quot; held in Manchester on the 10-11th of April 2008 titled &amp;quot;Prediction of textile geometry using strain energy minimisation&amp;quot;. A longer more detailed version of this will shortly be submitted as a journal paper.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Read in a textile&lt;br /&gt;
ReadFromXML(&amp;#039;800s4.tg3&amp;#039;)&lt;br /&gt;
Textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# Create an instance of the geometry solver&lt;br /&gt;
Solver = CGeometrySolver()&lt;br /&gt;
&lt;br /&gt;
# Set some parameters&lt;br /&gt;
Solver.SetContactStiffness(1e6)&lt;br /&gt;
Solver.SetDisabledStiffness(1e-6)&lt;br /&gt;
Solver.SetSeed(1.0)&lt;br /&gt;
# Create the system of equations to be solved&lt;br /&gt;
Solver.CreateSystem(Textile)&lt;br /&gt;
# Solve the system&lt;br /&gt;
Solver.SolveSystem()&lt;br /&gt;
# Save the result to a VTK file for viewing purposes&lt;br /&gt;
Solver.SaveToVTK(&amp;quot;GeomSolve&amp;quot;)&lt;br /&gt;
# Deform the textile&lt;br /&gt;
Solver.DeformTextile()&lt;br /&gt;
# Save the result back to a TG3 file&lt;br /&gt;
SaveToXML(&amp;#039;Def-800s4.tg3&amp;#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Examples</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-14T15:53:03Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains a number of example scripts which show off some of the more advanced classes used to achieve specific tasks within TexGen.&lt;br /&gt;
&lt;br /&gt;
=== Geometry Solver ===&lt;br /&gt;
&lt;br /&gt;
The theory behind the geometry solver is described in a paper submitted to &amp;quot;The First World Conference on 3D Fabrics and Their Applications&amp;quot; held in Manchester on the 10-11th of April 2008 titled &amp;quot;...&amp;quot;. A longer version of this will shortly be submitted as a journal paper.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-14T11:36:23Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Getting started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Create Models]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
Note that by adding this line does not prevent you from running your scripts through the GUI as well.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. Note that this is just a mesh of the yarns, the volume between the yarns (i.e. the matrix volume) is not meshed. If you wanted to get a mesh of the yarns and matrix together you need to use the &amp;lt;code&amp;gt;CMesher&amp;lt;/code&amp;gt; class instead, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create an instance of the mesher class&lt;br /&gt;
mesher = CMesher()&lt;br /&gt;
# Create the mesh&lt;br /&gt;
mesher.CreateMesh(textile)&lt;br /&gt;
# Get the mesh&lt;br /&gt;
mesh = mesher.GetMesh()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This was a bit of a divergence from the tutorial, don&amp;#039;t put this in your script unless you specifically wanted a mesh of the matrix as well. If you do use this, please be aware that it will generate a tetrahedral mesh and the code below will need to be extended to accommodate these elements.&lt;br /&gt;
&lt;br /&gt;
The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decided what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial section 7.2] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial section 7.1] and [http://docs.python.org/lib/typesseq-strings.html Python library reference 3.6.2] for more information on this.&lt;br /&gt;
&lt;br /&gt;
At this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points were written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it, you should now have a script which reads a TexGen tg3 file, extracts a mesh from it and writes the contents to a file in the VTK legacy file format. Your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&lt;br /&gt;
file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&lt;br /&gt;
# Get element information from the mesh&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&lt;br /&gt;
# Write the element information&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Verification==&lt;br /&gt;
&lt;br /&gt;
The first thing to do now is to run the script from the command line like so:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
replacing &amp;lt;code&amp;gt;myscript.py&amp;lt;/code&amp;gt; with the name of the script your created and ensuring you have a textile model named &amp;lt;code&amp;gt;textile.tg3&amp;lt;/code&amp;gt; in the some folder as the script. If it ran successfully you should see a file named &amp;lt;code&amp;gt;mesh.vtk&amp;lt;/code&amp;gt; being created. Load this up into [http://www.paraview.org/ ParaView] and you should see a mesh of your textile.&lt;br /&gt;
&lt;br /&gt;
When writing your own scripts it is unlikely that they will work straight away (even for professional programmers), so it is a good idea to check the output of your script at each step with a text editor to ensure that it is writing exactly what you want. This will enable you to isolate bugs early on and one at a time rather than having to fix a long script containing numerous bugs. The [http://docs.python.org/tut/node5.html#SECTION005200000000000000000 print statement] is your friend when it comes to debugging, it can be used to print out values and verify that they are what you expect.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-14T11:26:14Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Getting started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Create Models]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
Note that by adding this line does not prevent you from running your scripts through the GUI as well.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. Note that this is just a mesh of the yarns, the volume between the yarns (i.e. the matrix volume) is not meshed. If you wanted to get a mesh of the yarns and matrix together you need to use the &amp;lt;code&amp;gt;CMesher&amp;lt;/code&amp;gt; class instead, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create an instance of the mesher class&lt;br /&gt;
mesher = CMesher()&lt;br /&gt;
# Create the mesh&lt;br /&gt;
mesher.CreateMesh(textile)&lt;br /&gt;
# Get the mesh&lt;br /&gt;
mesh = mesher.GetMesh()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This was a bit of a divergence from the tutorial, don&amp;#039;t put this in your script unless you specifically wanted a mesh of the matrix as well. Please be aware that if you use this code, it will generate a tetrahedral mesh and so the code below will need to be extended to accommodate that.&lt;br /&gt;
&lt;br /&gt;
The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decided what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial section 7.2] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial section 7.1] and [http://docs.python.org/lib/typesseq-strings.html Python library reference 3.6.2] for more information on this.&lt;br /&gt;
&lt;br /&gt;
At this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points were written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it, you should now have a script which reads a TexGen tg3 file, extracts a mesh from it and writes the contents to a file in the VTK legacy file format. Your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&lt;br /&gt;
file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&lt;br /&gt;
# Get element information from the mesh&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&lt;br /&gt;
# Write the element information&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Verification==&lt;br /&gt;
&lt;br /&gt;
The first thing to do now is to run the script from the command line like so:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
replacing &amp;lt;code&amp;gt;myscript.py&amp;lt;/code&amp;gt; with the name of the script your created and ensuring you have a textile model named &amp;lt;code&amp;gt;textile.tg3&amp;lt;/code&amp;gt; in the some folder as the script. If it ran successfully you should see a file named &amp;lt;code&amp;gt;mesh.vtk&amp;lt;/code&amp;gt; being created. Load this up into [http://www.paraview.org/ ParaView] and you should see a mesh of your textile.&lt;br /&gt;
&lt;br /&gt;
When writing your own scripts it is unlikely that they will work straight away (even for professional programmers), so it is a good idea to check the output of your script at each step with a text editor to ensure that it is writing exactly what you want. This will enable you to isolate bugs early on and one at a time rather than having to fix a long script containing numerous bugs. The [http://docs.python.org/tut/node5.html#SECTION005200000000000000000 print statement] is your friend when it comes to debugging, it can be used to print out values and verify that they are what you expect.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Compiling from Source</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-14T10:46:25Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Checkout TexGen source code from subversion server */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In order to compile TexGen and &amp;#039;&amp;#039;&amp;#039;all&amp;#039;&amp;#039;&amp;#039; of its modules, the following software is required:&lt;br /&gt;
&lt;br /&gt;
The following programs are needed to build TexGen:&lt;br /&gt;
* [http://www.cmake.org/ CMake]&lt;br /&gt;
* [http://www.swig.org/ SWIG]&lt;br /&gt;
&lt;br /&gt;
The following libraries are needed to link to TexGen:&lt;br /&gt;
* [http://www.vtk.org/ VTK]&lt;br /&gt;
* [http://www.wxwidgets.org/ wxWidgets]&lt;br /&gt;
* [http://www.opencascade.org/ OpenCascade]&lt;br /&gt;
* [http://www.python.org/ Python]&lt;br /&gt;
&lt;br /&gt;
However to perform a minimum build of TexGen with none of the additional modules you only require CMake and a C++ compiler. It is recommended to begin with a minimum build, once that is working try adding modules one at a time. A list of modules along with dependencies is shown below:&lt;br /&gt;
&lt;br /&gt;
* Python interface: Python, SWIG&lt;br /&gt;
* Renderer: VTK&lt;br /&gt;
* Export: OpenCascade&lt;br /&gt;
* GUI: wxWidgets, Renderer, Python interface&lt;br /&gt;
* Unit tests: CPPUnit&lt;br /&gt;
&lt;br /&gt;
A graphical representation of the modules and their dependencies can also be found in the [http://texgen.sourceforge.net/api/ TexGen API].&lt;br /&gt;
&lt;br /&gt;
If you want to get the source code from the Subversion repository you will need to install [http://subversion.tigris.org/ Subversion] by following the instructions below. Note that this is the very latest development source and so may it contain some bugs and unfinished features. However it is very easy to keep up to date with the latest version of TexGen using this method and will allow you to keep any modifications you have made to the source when updating. If you find a bug or implement new features that may be usefull to the rest of the community they can also be submited as patch and incorporated into TexGen following review.&lt;br /&gt;
&lt;br /&gt;
Alternatively the stable source code can be downloaded as a [http://sourceforge.net/project/showfiles.php?group_id=181000 tarball]. Download the latest file release named &amp;#039;&amp;#039;texgen-3.x.x.tar.gz&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Windows (Microsoft Visual Studio C++, recommended method) ==&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
It is assumed that Microsoft Visual Studio is already installed.  If it isn&amp;#039;t and you plan to use it, then install it.  It may be possible to use the free [http://www.microsoft.com/express/ Visual Studio Express]; if anyone tries this and finds out one way or the other, please post the information either here or in the [http://texgen.sourceforge.net/phpBB2/index.php forum]. Brief instructions on how to install the various 3rd party libraries under windows are given below. Note that you do not need to install all of these in order to perform the minimal build. Only CMake is absolutely required.&lt;br /&gt;
&lt;br /&gt;
==== CMake ====&lt;br /&gt;
&lt;br /&gt;
[http://www.cmake.org/HTML/Download.html Download CMake] and install, selecting &amp;#039;Add CMake to the system PATH for all users&amp;#039; (select current user if this is not permissible on your system).&lt;br /&gt;
&lt;br /&gt;
==== TortoiseSVN ====&lt;br /&gt;
&lt;br /&gt;
[http://tortoisesvn.net/downloads Download TortoiseSVN] and install it.&lt;br /&gt;
&lt;br /&gt;
==== SWIG ====&lt;br /&gt;
&lt;br /&gt;
[http://www.swig.org/ Download] the latest release of the windows .zip files and extract to a suitable location (e.g. c:\Program Files\swigwin-1.3.31).&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
[http://www.python.org/ Download Python] and install.&lt;br /&gt;
&lt;br /&gt;
==== OpenCascade ====&lt;br /&gt;
&lt;br /&gt;
[http://www.opencascade.org/getocc/download/ Download OpenCascade] and install; this extracts the files to a directory. If the installation doesn&amp;#039;t start automatically, run the &amp;#039;install.bat&amp;#039; file located the directory where the files where extracted (read &amp;#039;readme.htm&amp;#039; file in the same directory for more information).  Choose &amp;#039;complete installation&amp;#039; and tick the box to set the environment variables.&lt;br /&gt;
&lt;br /&gt;
==== VTK ====&lt;br /&gt;
&lt;br /&gt;
[http://www.vtk.org/get-software.php Download] the latest source files and extract them. Follow the instructions in &amp;#039;README.html&amp;#039; found in the extracted directory to compile VTK using CMake. The following CMake settings should be set:&lt;br /&gt;
&lt;br /&gt;
 BUILD_EXAMPLES           OFF&lt;br /&gt;
 BUILD_SHARED_LIBS        OFF&lt;br /&gt;
 VTK_USE_MPEG2_ENCODER    OFF&lt;br /&gt;
 VTK_USE_PARALLEL         OFF&lt;br /&gt;
 VTK_USE_RENDERING        ON&lt;br /&gt;
 VTK_WRAP_JAVA            OFF&lt;br /&gt;
 VTK_WRAP_PYTHON          OFF&lt;br /&gt;
 VTK_WRAP_TCL             OFF&lt;br /&gt;
&lt;br /&gt;
You may be able to get things working with different settings, however these are the settings I use and are known to work.&lt;br /&gt;
&lt;br /&gt;
==== wxWidgets ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wxwidgets.org/downloads/ Download] and install the windows version of wxWidgets (wxMSW). It is then necessary to compile wxWidgets from source, detailed instructions on how to do this can be found in &amp;#039;install.txt&amp;#039; located in the &amp;#039;docs\msw&amp;#039; subfolder. The main steps are to open &amp;#039;wx.dsw&amp;#039; with MSVC located in the &amp;#039;build\msw&amp;#039; subfolder and compile both Release and Debug configurations (The configuration can be selected from the drop down box on the main toolbar in Visual Studio. Universal, Unicode and DLL versions need not be compiled).&lt;br /&gt;
&lt;br /&gt;
=== Checkout TexGen source code from subversion server ===&lt;br /&gt;
Create a directory where you would like to store the TexGen source code in Windows Explorer. Right click on this folder and select &amp;quot;SVN Checkout...&amp;quot; from the context menu that appears. In the dialog box which follows, enter &amp;quot;https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/&amp;quot; in the URL field. The Checkout directory field should have been filled in automatically. Click on OK to start downloading the TexGen source code. In future the latest version of the source code can be obtained simply by right clicking on the folder and selecting &amp;quot;SVN Update&amp;quot; from the context menu.&lt;br /&gt;
&lt;br /&gt;
=== Configuring the build system with CMake ===&lt;br /&gt;
Run CMake from its shortcut on the Start menu. There are some general instructions on using CMake on the [http://www.cmake.org/HTML/RunningCMake.html CMake website] which are worth reading. You will need to fill in the source code location, this should point to where you checkout out the latest TexGen SVN code or where you extracted the source code from the zip file. Also set where to place the binary files once they are compiled, this can be the same as the source directory, a subdirectory within the source directory or any other location.&lt;br /&gt;
&lt;br /&gt;
Once that is entered click &amp;#039;Configure&amp;#039; and choose the Visual Studio version which you have installed and click ok. You will initially get a number of error messages such as:&lt;br /&gt;
&lt;br /&gt;
 CMake Error: Swig was not found on the system. Please specify the location of Swig. (click OK)&lt;br /&gt;
 CMake Error: Error in configuration process, project files may be invalid. (click OK)&lt;br /&gt;
&lt;br /&gt;
This is normal, in order to get rid of the errors you will need to tell CMake where the various libraries you have installed can be found. This is done in the Cache Values sections.&lt;br /&gt;
&lt;br /&gt;
It is recommended to begin with a minimal build, this is achieved by setting the cache values as follows:&lt;br /&gt;
&lt;br /&gt;
 BUILD_CASCADE_EXPORT           OFF&lt;br /&gt;
 BUILD_DOCUMENTATION            OFF&lt;br /&gt;
 BUILD_EXAMPLES                 OFF&lt;br /&gt;
 BUILD_GUI                      OFF&lt;br /&gt;
 BUILD_PYTHON_INTERFACE         OFF&lt;br /&gt;
 BUILD_RENDERER                 OFF&lt;br /&gt;
 BUILD_SHARED                   ON&lt;br /&gt;
 BUILD_UNIT_TESTS               OFF&lt;br /&gt;
&lt;br /&gt;
Once these are set press configure again and you shouldn&amp;#039;t have any more errors/warnings. Press &amp;#039;OK&amp;#039; to generate the MSVC solution and project files. Configuring the various optional modules is explained in [[#Configuring optional modules]].&lt;br /&gt;
&lt;br /&gt;
=== Configuring optional modules ===&lt;br /&gt;
&lt;br /&gt;
Once the minimal build is working you may want to switch on the optional modules. To do this open up CMake again and switch the modules you want to ON in the Cache Values then click Configure. You will most likely see some errors telling you it is unable to automatically find certain directories. You will need to specify these manually. An explanation of the different locations is listed below:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PYTHON_SITEPACKAGES_DIR&amp;#039;&amp;#039;&amp;#039; - This should be the folder where the TexGen python modules will be placed. Usually located in &amp;#039;C:\Python25\Lib\site-packages&amp;#039;, but this will depend on the version of Python installed and where you decided to install it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SWIG_DIR&amp;#039;&amp;#039;&amp;#039; -  This is the location where you extracted the SWIG executable. e.g. &amp;#039;C:\Program Files\swigwin-1.3.35&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SWIG_EXECUTABLE&amp;#039;&amp;#039;&amp;#039; - Same as root directory followed by &amp;#039;swig.exe&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wxWidgets_ROOT_DIR&amp;#039;&amp;#039;&amp;#039; - Location where you install wxWidgets. e.g. &amp;#039;C:/wxWidgets-2.8.7&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wxWidgets_LIB_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the wxWidgets libraries were compiled to, should be the same as the root directory followed by &amp;#039;lib\vc_lib&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_INCLUDE_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade header files are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/inc&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_LIBRARY_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade libraries are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/win32/lib&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_DEBUG_LIBRARY_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade debug libraries are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/win32/libd&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;VTK_DIR&amp;#039;&amp;#039;&amp;#039; - Location of the VTK binary directory (note: not the source directory).&lt;br /&gt;
&lt;br /&gt;
After setting the directories manually, click on configure again. You may need to go through several iterations of changing parameters then pressing configure. Once you have finished changing parameters and have successfully pressed configure without error messages you can press the OK button to generate the build. Note: you can always come back to this at a later time to make changes.&lt;br /&gt;
&lt;br /&gt;
=== Compiling ===&lt;br /&gt;
&lt;br /&gt;
Find &amp;#039;TexGen.sln&amp;#039; which should be located in the directory where you told CMake to output the binary files to and open it with Microsoft Visual Studio.&lt;br /&gt;
&lt;br /&gt;
Set the configuration to &amp;#039;Release&amp;#039; and build the solution. Hopefully the project will have been compiled without errors.&lt;br /&gt;
&lt;br /&gt;
If you want to compile and execute the Graphical User Interface you will need to install it, you will not be able to execute it directly from the build directory. This is done by right click on the &amp;#039;INSTALL&amp;#039; project in the Solution Explorer and selecting Build. This will copy the Python modules into the Python site-packages directory so that they can be imported into scripts, and it will copy the executable along with other necessary files into &amp;#039;C:\Program Files\TexGen\&amp;#039; by default (this can be changed with the CMAKE_INSTALL_PREFIX cache value in CMake). TexGenGUI.exe should then be run from the installed location, if you attempt to run it directly from where it was compiled you will get some errors on launch.&lt;br /&gt;
&lt;br /&gt;
=== Building the documentation ===&lt;br /&gt;
&lt;br /&gt;
To build the documentation, [http://www.stack.nl/~dimitri/doxygen/download.html Doxygen] is required.  Open a command prompt in the &amp;#039;Docs&amp;#039; subdirectory of the source code and run &amp;#039;doxygen&amp;#039;. If the doxygen directory is not in your path, you must add it, or give the full path on the command line.&lt;br /&gt;
&lt;br /&gt;
=== Integrating TexGen with ABAQUS ===&lt;br /&gt;
&lt;br /&gt;
If you are using ABAQUS and wish to use TexGen Python scripting from within the ABAQUS/CAE environment, there are a few extra steps to perform. This is because ABAQUS comes packaged with its own version of Python, so any modules added to your standalone python installation will not be accessible by ABAQUS. You must compile the TexGen Python modules with the same version of Python as ABAQUS uses. The following table shows which version of Python is used in specific ABAQUS versions:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! ABAQUS Version !! Python Version&lt;br /&gt;
|-&lt;br /&gt;
| 6.6-1 || 2.3.3&lt;br /&gt;
|- &lt;br /&gt;
| 6.7-1 || 2.4.3 &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If your version of ABAQUS is not listed in the table above you can type &amp;#039;abaqus python -V&amp;#039; to check what version of Python is used (then please edit this page to update the table). You can obtain specific versions of Python from http://www.python.org/download/releases/x.y.z/ where x.y.z represents the version number.&lt;br /&gt;
&lt;br /&gt;
Additionally you will need to place the TexGen python modules inside ABAQUS&amp;#039; version of python. There are a few ways to accomplish this, the easiest is perhaps to set the CMake cache variable &amp;#039;PYTHON_SITEPACKAGES_DIR&amp;#039; point to the ABAQUS&amp;#039; python directory, e.g.:&lt;br /&gt;
&lt;br /&gt;
 PYTHON_SITEPACKAGES_DIR     C:\Abaqus\6.7-1\Python\Lib\&lt;br /&gt;
&lt;br /&gt;
Then when you build the INSTALL project in MSVC++ it will automatically copy the TexGen python modules to the ABAQUS&amp;#039; Python. Alternatively you can simply copy the files manually or modify Python&amp;#039;s search path to include the TexGen python modules, e.g. In python:&lt;br /&gt;
&lt;br /&gt;
 import sys&lt;br /&gt;
 sys.path.append(&amp;#039;C:/Python24/Lib/site-packages/&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when compiling:&lt;br /&gt;
 fatal error LNK1104: cannot open file &amp;#039;python25_d.lib&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; The windows installation of Python doesn&amp;#039;t come with the debug library (&amp;#039;python25_d.lib&amp;#039;, the _d part means debug). You should be able to compile in release mode however. If you really want to compile in debug mode you will need to compile Python from source and link to that. Or you can try to link to the release library &amp;#039;python25.lib&amp;#039; instead, easiest way to do that is to copy &amp;#039;python25.lib&amp;#039; to &amp;#039;python25_d.lib&amp;#039; but this may cause problems during linking or execution.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when compiling:&lt;br /&gt;
 fatal error C1083: Cannot open include file: &amp;#039;wx/wxprec.h&amp;#039;: No such file or directory&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; Make sure that you have compiled wxWidgets and that the wxWidgets_XXX cache variables are set correctly in CMake.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I do not have a &amp;#039;libd&amp;#039; folder in &amp;#039;ros/win32&amp;#039; for OpenCASCADE.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; If you do not compile OpenCASCADE yourself then this folder does not exist. However it can be ignored if you are only interested in building the release version of TexGen. If you really want to compile the debug version please refer to the OpenCASCADE documentation.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; Why do I get the error message: &amp;quot;The parameter is incorrect.&amp;quot; when launching TexGenGUI.exe?&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; This appears to only happen when compiling TexGen with MSVC 2005 or later. I have still not been able to track down the cause of the error as it is particularly cryptic and it will not even allow me to debug the program. For now you must compile with MSVC 2003 or avoid using the GUI until this issue can be resolved.&lt;br /&gt;
&lt;br /&gt;
== Windows (Cygwin and gcc, alternate method) ==&lt;br /&gt;
A limited build (without graphics) can be made under cygwin, this is a UNIX emulation environment available at [http://www.cygwin.com www.cygwin.com]. &lt;br /&gt;
This can exist peacefully next to the native windows version. &lt;br /&gt;
Cygwin creates a unix-style file system within your windows installation. If you choose c:/cygwin as your install directory, your HOME will be at c:/cygwin/home/&amp;lt;username&amp;gt;/. &lt;br /&gt;
&lt;br /&gt;
=== Download cygwin and install packages ===&lt;br /&gt;
Install gcc, g++, wget, make and cmake using the setup.exe program from the cygwin website. &lt;br /&gt;
For the mesh generator and python interface to work we currently need VTK and swig. &lt;br /&gt;
&lt;br /&gt;
This downloads and installs swig from source (when starting the cygwin shell you can paste this into the command line, otherwise write it to a file and run it with sh). &lt;br /&gt;
 mkdir progs&lt;br /&gt;
 cd progs &lt;br /&gt;
 SWIG=swig-1.3.31&lt;br /&gt;
 wget -nc http://kent.dl.sourceforge.net/sourceforge/swig/$SWIG.tar.gz&lt;br /&gt;
 tar xzvf $SWIG.tar.gz &lt;br /&gt;
 cd $SWIG&lt;br /&gt;
 ./configure &lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
This downloads and installs VTK from source, in the ccmake stage, use the cmake graphical commands to get a working install. &lt;br /&gt;
 VTK=vtk-5.0.3&lt;br /&gt;
 wget -nc http://www.vtk.org/files/release/5.0/$VTK.tar.gz&lt;br /&gt;
 tar xzvf $VTK.tar.gz&lt;br /&gt;
 mkdir vtkbin&lt;br /&gt;
 cd vtkbin&lt;br /&gt;
 ccmake ../VTK&lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== Install TexGen from source ===&lt;br /&gt;
Now we can proceed to install texgen, as an example we&amp;#039;ll work in ~/temp/texgen&lt;br /&gt;
 cd ~; mkdir temp; cd temp; mkdir texgen; cd texgen&lt;br /&gt;
 svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen&lt;br /&gt;
 cd .. ; mkdir tbin; cd tbin&lt;br /&gt;
 ccmake ../texgen&lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
This should result in a working texgen install in ~/temp/texgen/tbin.&lt;br /&gt;
&lt;br /&gt;
== Unix ==&lt;br /&gt;
=== Notes ===&lt;br /&gt;
If you are installing to a system where you don&amp;#039;t have root access (i.e. this computer does not belong to you) you won&amp;#039;t be able to install the software using the default configure script. This is because by default software is installed to the /usr/local directory. If you are not a systems administrator then you will quite rightly not have write access to this folder. All is not lost! You can still install software into your home directory. In order to do this you should always call the configure script with the following parameter: --prefix=$HOME. This goes for all the software to be installed below. All executables will then be placed in ~/bin, libraries in ~/lib, includes in ~/include, etc...&lt;br /&gt;
&lt;br /&gt;
In the guide below the parameter is included in italic. If you do in fact have root access then it is recommended to omit this parameter and install to the default directory so that other users will also have access to the software.&lt;br /&gt;
&lt;br /&gt;
=== Get TexGen from Subversion repository ===&lt;br /&gt;
&lt;br /&gt;
==== Install Subversion ====&lt;br /&gt;
[http://subversion.tigris.org/servlets/ProjectDocumentList?collapseFolder=260&amp;amp;folderID=260 Download Subversion] and unpack.&lt;br /&gt;
Open a shell in extracted folder and type:&lt;br /&gt;
 ./configure --with-ssl &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* You will need to install Subversion with SSL support since TexGen is hosted on sourceforge which uses SSL. If you don&amp;#039;t configure with the --with-ssl flag you will get an error when trying to checkout TexGen in the next step.&lt;br /&gt;
* If you have trouble installing the latest version of Subversion, try installing version 1.3 as it does not require a seperate dependencies package.&lt;br /&gt;
&lt;br /&gt;
==== Checkout ====&lt;br /&gt;
Open a shell in folder you wish to place TexGen (e.g. ~/):&lt;br /&gt;
 svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The first parameter tells SVN to get the files for the first time&lt;br /&gt;
* The second parameter is the location of the TexGen svn repository&lt;br /&gt;
* The final parameter is the subfolder to put the files in&lt;br /&gt;
&lt;br /&gt;
==== Update ====&lt;br /&gt;
The checkout command only needs to performed once. SVN keeps track of where the code was originally obtained and can update to the latest version without having to re-specify the location. In order to do that open a shell in the folder where TexGen was originally checkout (e.g. ~/TexGen) and type:&lt;br /&gt;
 svn update&lt;br /&gt;
or if you are in a hurry you can type the shorter version:&lt;br /&gt;
 svn up&lt;br /&gt;
&lt;br /&gt;
=== Compile source ===&lt;br /&gt;
&lt;br /&gt;
==== Install CMake ====&lt;br /&gt;
&lt;br /&gt;
[http://www.cmake.org/HTML/Download.html Download CMake] and unpack.&lt;br /&gt;
Open a shell in extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
==== Compile TexGen core ====&lt;br /&gt;
Open a shell in the folder with the TexGen source code (e.g. ~/TexGen):&lt;br /&gt;
 mkdir bin&lt;br /&gt;
 cd bin&lt;br /&gt;
 ccmake ../&lt;br /&gt;
Press &amp;#039;c&amp;#039; to configure. When a warning pops up telling you it can&amp;#039;t find such and such a file press &amp;#039;e&amp;#039; to close it. You will now need to specify which components of TexGen to build and where their dependencies can be found. Use the up and down arrows to move the caret and press enter to modify options. Do this to set BUILD_GUI, BUILD_PYTHON_INTERFACE and BUILD_RENDERER to OFF. You are basically telling CMake not to attempt to build these components, which means that you won&amp;#039;t need to have installed their dependencies.&lt;br /&gt;
&lt;br /&gt;
Similarly to the --prefix=$HOME parameter to the configure script, you can tell CMake to install TexGen to your home directory by changing CMAKE_INSTALL_PREFIX to ~/. Note that it won&amp;#039;t actually install anything until you get type make install.&lt;br /&gt;
&lt;br /&gt;
Now press &amp;#039;c&amp;#039; again to update the changes.&lt;br /&gt;
&lt;br /&gt;
Hopefully now that all the additional modules have been switched off no errors will be shown. Press &amp;#039;g&amp;#039; to generate the makefiles and exit. At the shell type:&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Note that at this point you have only built and installed the TexGen Core library which doesn&amp;#039;t actually do anything on its own. If you plan to incorporate TexGen into your own C++ program then this is enough, however if you would like to interface with TexGen from a Python script or Graphical User Interface then follow the steps below.&lt;br /&gt;
&lt;br /&gt;
=== Compiling optional modules ===&lt;br /&gt;
==== Python interface ====&lt;br /&gt;
[http://www.python.org/download/ Download Python] and unpack.&lt;br /&gt;
Open a shell in the extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
[http://www.swig.org/download.html Download SWIG] and unpack.&lt;br /&gt;
Open a shell in the extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Open a shell in the folder where you called ccmake from for the first time (e.g. ~/TexGen/bin):&lt;br /&gt;
 ccmake ../&lt;br /&gt;
&lt;br /&gt;
Use the up and down arrows to reach BUILD_PYTHON_INTERFACE and press Enter to set it to ON. Then press &amp;#039;c&amp;#039; to configure. You will probably get a warning saying you need to specify the location of SWIG and/or Python, press &amp;#039;e&amp;#039; to close it.&lt;br /&gt;
&lt;br /&gt;
Set the PYTHON_INCLUDE_PATH, PYTHON_LIBRARY, PYTHON_SITEPACKAGES_DIR, SWIG_DIR and SWIG_EXECUTABLE parameters correctly where necessary. If you have installed packages to your home directory then they should look something like this:&lt;br /&gt;
&lt;br /&gt;
 PYTHON_INCLUDE_PATH: ~/include/python2.5&lt;br /&gt;
 PYTHON_LIBRARY: ~/lib/python2.5/config/libpython2.5.a&lt;br /&gt;
 PYTHON_SITEPACKAGES_DIR: ~/lib/python2.5/site-packages&lt;br /&gt;
 SWIG_DIR: ~/bin&lt;br /&gt;
 SWIG_EXECUTABLE: ~/bin/swig&lt;br /&gt;
&lt;br /&gt;
Once that is done press &amp;#039;c&amp;#039; again. You may need perform this process over several iterations. When everything is set correctly press &amp;#039;g&amp;#039; to generate the makefiles.&lt;br /&gt;
&lt;br /&gt;
At the shell type:&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Assuming the build completed without errors you should now be able to access TexGen functions from within Python. In order to check everything worked as planned open Python in interactive mode by typing:&lt;br /&gt;
 python&lt;br /&gt;
&lt;br /&gt;
Then from within Python type:&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
 CTexGen.GetInstance().GetVersion()&lt;br /&gt;
&lt;br /&gt;
This should display the version of TexGen installed.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when linking _Core.so:&lt;br /&gt;
 libpython2.5.a(abstract.o): relocation R_X86_64_32 against `a local symbol&amp;#039;&lt;br /&gt;
 can not be used when making a shared object; recompile with -fPIC&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; Try removing libpython2.5.a from the libraries to link to by setting PYTHON_LIBRARY to a bogus path, e.g.:&lt;br /&gt;
&lt;br /&gt;
PYTHON_LIBRARY: ~/&lt;br /&gt;
&lt;br /&gt;
By doing so you may receive a warning similar to this:&lt;br /&gt;
 Warning: Ignoring path found in link libraries for target: _Core, path is:&lt;br /&gt;
 /home/username. Expected a library name or a full path to a library name.&lt;br /&gt;
This warning may be ignored.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Compiling from Source</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-13T16:30:29Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Troubleshooting */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In order to compile TexGen and &amp;#039;&amp;#039;&amp;#039;all&amp;#039;&amp;#039;&amp;#039; of its modules, the following software is required:&lt;br /&gt;
&lt;br /&gt;
The following programs are needed to build TexGen:&lt;br /&gt;
* [http://www.cmake.org/ CMake]&lt;br /&gt;
* [http://www.swig.org/ SWIG]&lt;br /&gt;
&lt;br /&gt;
The following libraries are needed to link to TexGen:&lt;br /&gt;
* [http://www.vtk.org/ VTK]&lt;br /&gt;
* [http://www.wxwidgets.org/ wxWidgets]&lt;br /&gt;
* [http://www.opencascade.org/ OpenCascade]&lt;br /&gt;
* [http://www.python.org/ Python]&lt;br /&gt;
&lt;br /&gt;
However to perform a minimum build of TexGen with none of the additional modules you only require CMake and a C++ compiler. It is recommended to begin with a minimum build, once that is working try adding modules one at a time. A list of modules along with dependencies is shown below:&lt;br /&gt;
&lt;br /&gt;
* Python interface: Python, SWIG&lt;br /&gt;
* Renderer: VTK&lt;br /&gt;
* Export: OpenCascade&lt;br /&gt;
* GUI: wxWidgets, Renderer, Python interface&lt;br /&gt;
* Unit tests: CPPUnit&lt;br /&gt;
&lt;br /&gt;
A graphical representation of the modules and their dependencies can also be found in the [http://texgen.sourceforge.net/api/ TexGen API].&lt;br /&gt;
&lt;br /&gt;
If you want to get the source code from the Subversion repository you will need to install [http://subversion.tigris.org/ Subversion] by following the instructions below. Note that this is the very latest development source and so may it contain some bugs and unfinished features. However it is very easy to keep up to date with the latest version of TexGen using this method and will allow you to keep any modifications you have made to the source when updating. If you find a bug or implement new features that may be usefull to the rest of the community they can also be submited as patch and incorporated into TexGen following review.&lt;br /&gt;
&lt;br /&gt;
Alternatively the stable source code can be downloaded as a [http://sourceforge.net/project/showfiles.php?group_id=181000 tarball]. Download the latest file release named &amp;#039;&amp;#039;texgen-3.x.x.tar.gz&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Windows (Microsoft Visual Studio C++, recommended method) ==&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
It is assumed that Microsoft Visual Studio is already installed.  If it isn&amp;#039;t and you plan to use it, then install it.  It may be possible to use the free [http://www.microsoft.com/express/ Visual Studio Express]; if anyone tries this and finds out one way or the other, please post the information either here or in the [http://texgen.sourceforge.net/phpBB2/index.php forum]. Brief instructions on how to install the various 3rd party libraries under windows are given below. Note that you do not need to install all of these in order to perform the minimal build. Only CMake is absolutely required.&lt;br /&gt;
&lt;br /&gt;
==== CMake ====&lt;br /&gt;
&lt;br /&gt;
[http://www.cmake.org/HTML/Download.html Download CMake] and install, selecting &amp;#039;Add CMake to the system PATH for all users&amp;#039; (select current user if this is not permissible on your system).&lt;br /&gt;
&lt;br /&gt;
==== TortoiseSVN ====&lt;br /&gt;
&lt;br /&gt;
[http://tortoisesvn.net/downloads Download TortoiseSVN] and install it.&lt;br /&gt;
&lt;br /&gt;
==== SWIG ====&lt;br /&gt;
&lt;br /&gt;
[http://www.swig.org/ Download] the latest release of the windows .zip files and extract to a suitable location (e.g. c:\Program Files\swigwin-1.3.31).&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
[http://www.python.org/ Download Python] and install.&lt;br /&gt;
&lt;br /&gt;
==== OpenCascade ====&lt;br /&gt;
&lt;br /&gt;
[http://www.opencascade.org/getocc/download/ Download OpenCascade] and install; this extracts the files to a directory. If the installation doesn&amp;#039;t start automatically, run the &amp;#039;install.bat&amp;#039; file located the directory where the files where extracted (read &amp;#039;readme.htm&amp;#039; file in the same directory for more information).  Choose &amp;#039;complete installation&amp;#039; and tick the box to set the environment variables.&lt;br /&gt;
&lt;br /&gt;
==== VTK ====&lt;br /&gt;
&lt;br /&gt;
[http://www.vtk.org/get-software.php Download] the latest source files and extract them. Follow the instructions in &amp;#039;README.html&amp;#039; found in the extracted directory to compile VTK using CMake. The following CMake settings should be set:&lt;br /&gt;
&lt;br /&gt;
 BUILD_EXAMPLES           OFF&lt;br /&gt;
 BUILD_SHARED_LIBS        OFF&lt;br /&gt;
 VTK_USE_MPEG2_ENCODER    OFF&lt;br /&gt;
 VTK_USE_PARALLEL         OFF&lt;br /&gt;
 VTK_USE_RENDERING        ON&lt;br /&gt;
 VTK_WRAP_JAVA            OFF&lt;br /&gt;
 VTK_WRAP_PYTHON          OFF&lt;br /&gt;
 VTK_WRAP_TCL             OFF&lt;br /&gt;
&lt;br /&gt;
You may be able to get things working with different settings, however these are the settings I use and are known to work.&lt;br /&gt;
&lt;br /&gt;
==== wxWidgets ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wxwidgets.org/downloads/ Download] and install the windows version of wxWidgets (wxMSW). It is then necessary to compile wxWidgets from source, detailed instructions on how to do this can be found in &amp;#039;install.txt&amp;#039; located in the &amp;#039;docs\msw&amp;#039; subfolder. The main steps are to open &amp;#039;wx.dsw&amp;#039; with MSVC located in the &amp;#039;build\msw&amp;#039; subfolder and compile both Release and Debug configurations (The configuration can be selected from the drop down box on the main toolbar in Visual Studio. Universal, Unicode and DLL versions need not be compiled).&lt;br /&gt;
&lt;br /&gt;
=== Checkout TexGen source code from subversion server ===&lt;br /&gt;
Create a directory where you would like to store the TexGen source code in Windows Explorer. Right click on this folder and select &amp;#039;SVN Checkout...&amp;#039; from the context menu that appears. In the dialog box which follows, enter &amp;#039;https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/&amp;#039; in the URL field. The Checkout directory field should have been filled in automatically. Click on OK to start downloading the TexGen source code. In future the latest version of the source code can be obtained simply by right clicking on the folder and selecting &amp;#039;SVN Update&amp;#039; from the context menu.&lt;br /&gt;
&lt;br /&gt;
=== Configuring the build system with CMake ===&lt;br /&gt;
Run CMake from its shortcut on the Start menu. There are some general instructions on using CMake on the [http://www.cmake.org/HTML/RunningCMake.html CMake website] which are worth reading. You will need to fill in the source code location, this should point to where you checkout out the latest TexGen SVN code or where you extracted the source code from the zip file. Also set where to place the binary files once they are compiled, this can be the same as the source directory, a subdirectory within the source directory or any other location.&lt;br /&gt;
&lt;br /&gt;
Once that is entered click &amp;#039;Configure&amp;#039; and choose the Visual Studio version which you have installed and click ok. You will initially get a number of error messages such as:&lt;br /&gt;
&lt;br /&gt;
 CMake Error: Swig was not found on the system. Please specify the location of Swig. (click OK)&lt;br /&gt;
 CMake Error: Error in configuration process, project files may be invalid. (click OK)&lt;br /&gt;
&lt;br /&gt;
This is normal, in order to get rid of the errors you will need to tell CMake where the various libraries you have installed can be found. This is done in the Cache Values sections.&lt;br /&gt;
&lt;br /&gt;
It is recommended to begin with a minimal build, this is achieved by setting the cache values as follows:&lt;br /&gt;
&lt;br /&gt;
 BUILD_CASCADE_EXPORT           OFF&lt;br /&gt;
 BUILD_DOCUMENTATION            OFF&lt;br /&gt;
 BUILD_EXAMPLES                 OFF&lt;br /&gt;
 BUILD_GUI                      OFF&lt;br /&gt;
 BUILD_PYTHON_INTERFACE         OFF&lt;br /&gt;
 BUILD_RENDERER                 OFF&lt;br /&gt;
 BUILD_SHARED                   ON&lt;br /&gt;
 BUILD_UNIT_TESTS               OFF&lt;br /&gt;
&lt;br /&gt;
Once these are set press configure again and you shouldn&amp;#039;t have any more errors/warnings. Press &amp;#039;OK&amp;#039; to generate the MSVC solution and project files. Configuring the various optional modules is explained in [[#Configuring optional modules]].&lt;br /&gt;
&lt;br /&gt;
=== Configuring optional modules ===&lt;br /&gt;
&lt;br /&gt;
Once the minimal build is working you may want to switch on the optional modules. To do this open up CMake again and switch the modules you want to ON in the Cache Values then click Configure. You will most likely see some errors telling you it is unable to automatically find certain directories. You will need to specify these manually. An explanation of the different locations is listed below:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PYTHON_SITEPACKAGES_DIR&amp;#039;&amp;#039;&amp;#039; - This should be the folder where the TexGen python modules will be placed. Usually located in &amp;#039;C:\Python25\Lib\site-packages&amp;#039;, but this will depend on the version of Python installed and where you decided to install it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SWIG_DIR&amp;#039;&amp;#039;&amp;#039; -  This is the location where you extracted the SWIG executable. e.g. &amp;#039;C:\Program Files\swigwin-1.3.35&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SWIG_EXECUTABLE&amp;#039;&amp;#039;&amp;#039; - Same as root directory followed by &amp;#039;swig.exe&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wxWidgets_ROOT_DIR&amp;#039;&amp;#039;&amp;#039; - Location where you install wxWidgets. e.g. &amp;#039;C:/wxWidgets-2.8.7&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wxWidgets_LIB_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the wxWidgets libraries were compiled to, should be the same as the root directory followed by &amp;#039;lib\vc_lib&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_INCLUDE_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade header files are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/inc&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_LIBRARY_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade libraries are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/win32/lib&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_DEBUG_LIBRARY_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade debug libraries are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/win32/libd&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;VTK_DIR&amp;#039;&amp;#039;&amp;#039; - Location of the VTK binary directory (note: not the source directory).&lt;br /&gt;
&lt;br /&gt;
After setting the directories manually, click on configure again. You may need to go through several iterations of changing parameters then pressing configure. Once you have finished changing parameters and have successfully pressed configure without error messages you can press the OK button to generate the build. Note: you can always come back to this at a later time to make changes.&lt;br /&gt;
&lt;br /&gt;
=== Compiling ===&lt;br /&gt;
&lt;br /&gt;
Find &amp;#039;TexGen.sln&amp;#039; which should be located in the directory where you told CMake to output the binary files to and open it with Microsoft Visual Studio.&lt;br /&gt;
&lt;br /&gt;
Set the configuration to &amp;#039;Release&amp;#039; and build the solution. Hopefully the project will have been compiled without errors.&lt;br /&gt;
&lt;br /&gt;
If you want to compile and execute the Graphical User Interface you will need to install it, you will not be able to execute it directly from the build directory. This is done by right click on the &amp;#039;INSTALL&amp;#039; project in the Solution Explorer and selecting Build. This will copy the Python modules into the Python site-packages directory so that they can be imported into scripts, and it will copy the executable along with other necessary files into &amp;#039;C:\Program Files\TexGen\&amp;#039; by default (this can be changed with the CMAKE_INSTALL_PREFIX cache value in CMake). TexGenGUI.exe should then be run from the installed location, if you attempt to run it directly from where it was compiled you will get some errors on launch.&lt;br /&gt;
&lt;br /&gt;
=== Building the documentation ===&lt;br /&gt;
&lt;br /&gt;
To build the documentation, [http://www.stack.nl/~dimitri/doxygen/download.html Doxygen] is required.  Open a command prompt in the &amp;#039;Docs&amp;#039; subdirectory of the source code and run &amp;#039;doxygen&amp;#039;. If the doxygen directory is not in your path, you must add it, or give the full path on the command line.&lt;br /&gt;
&lt;br /&gt;
=== Integrating TexGen with ABAQUS ===&lt;br /&gt;
&lt;br /&gt;
If you are using ABAQUS and wish to use TexGen Python scripting from within the ABAQUS/CAE environment, there are a few extra steps to perform. This is because ABAQUS comes packaged with its own version of Python, so any modules added to your standalone python installation will not be accessible by ABAQUS. You must compile the TexGen Python modules with the same version of Python as ABAQUS uses. The following table shows which version of Python is used in specific ABAQUS versions:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! ABAQUS Version !! Python Version&lt;br /&gt;
|-&lt;br /&gt;
| 6.6-1 || 2.3.3&lt;br /&gt;
|- &lt;br /&gt;
| 6.7-1 || 2.4.3 &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If your version of ABAQUS is not listed in the table above you can type &amp;#039;abaqus python -V&amp;#039; to check what version of Python is used (then please edit this page to update the table). You can obtain specific versions of Python from http://www.python.org/download/releases/x.y.z/ where x.y.z represents the version number.&lt;br /&gt;
&lt;br /&gt;
Additionally you will need to place the TexGen python modules inside ABAQUS&amp;#039; version of python. There are a few ways to accomplish this, the easiest is perhaps to set the CMake cache variable &amp;#039;PYTHON_SITEPACKAGES_DIR&amp;#039; point to the ABAQUS&amp;#039; python directory, e.g.:&lt;br /&gt;
&lt;br /&gt;
 PYTHON_SITEPACKAGES_DIR     C:\Abaqus\6.7-1\Python\Lib\&lt;br /&gt;
&lt;br /&gt;
Then when you build the INSTALL project in MSVC++ it will automatically copy the TexGen python modules to the ABAQUS&amp;#039; Python. Alternatively you can simply copy the files manually or modify Python&amp;#039;s search path to include the TexGen python modules, e.g. In python:&lt;br /&gt;
&lt;br /&gt;
 import sys&lt;br /&gt;
 sys.path.append(&amp;#039;C:/Python24/Lib/site-packages/&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when compiling:&lt;br /&gt;
 fatal error LNK1104: cannot open file &amp;#039;python25_d.lib&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; The windows installation of Python doesn&amp;#039;t come with the debug library (&amp;#039;python25_d.lib&amp;#039;, the _d part means debug). You should be able to compile in release mode however. If you really want to compile in debug mode you will need to compile Python from source and link to that. Or you can try to link to the release library &amp;#039;python25.lib&amp;#039; instead, easiest way to do that is to copy &amp;#039;python25.lib&amp;#039; to &amp;#039;python25_d.lib&amp;#039; but this may cause problems during linking or execution.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when compiling:&lt;br /&gt;
 fatal error C1083: Cannot open include file: &amp;#039;wx/wxprec.h&amp;#039;: No such file or directory&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; Make sure that you have compiled wxWidgets and that the wxWidgets_XXX cache variables are set correctly in CMake.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I do not have a &amp;#039;libd&amp;#039; folder in &amp;#039;ros/win32&amp;#039; for OpenCASCADE.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; If you do not compile OpenCASCADE yourself then this folder does not exist. However it can be ignored if you are only interested in building the release version of TexGen. If you really want to compile the debug version please refer to the OpenCASCADE documentation.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; Why do I get the error message: &amp;quot;The parameter is incorrect.&amp;quot; when launching TexGenGUI.exe?&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; This appears to only happen when compiling TexGen with MSVC 2005 or later. I have still not been able to track down the cause of the error as it is particularly cryptic and it will not even allow me to debug the program. For now you must compile with MSVC 2003 or avoid using the GUI until this issue can be resolved.&lt;br /&gt;
&lt;br /&gt;
== Windows (Cygwin and gcc, alternate method) ==&lt;br /&gt;
A limited build (without graphics) can be made under cygwin, this is a UNIX emulation environment available at [http://www.cygwin.com www.cygwin.com]. &lt;br /&gt;
This can exist peacefully next to the native windows version. &lt;br /&gt;
Cygwin creates a unix-style file system within your windows installation. If you choose c:/cygwin as your install directory, your HOME will be at c:/cygwin/home/&amp;lt;username&amp;gt;/. &lt;br /&gt;
&lt;br /&gt;
=== Download cygwin and install packages ===&lt;br /&gt;
Install gcc, g++, wget, make and cmake using the setup.exe program from the cygwin website. &lt;br /&gt;
For the mesh generator and python interface to work we currently need VTK and swig. &lt;br /&gt;
&lt;br /&gt;
This downloads and installs swig from source (when starting the cygwin shell you can paste this into the command line, otherwise write it to a file and run it with sh). &lt;br /&gt;
 mkdir progs&lt;br /&gt;
 cd progs &lt;br /&gt;
 SWIG=swig-1.3.31&lt;br /&gt;
 wget -nc http://kent.dl.sourceforge.net/sourceforge/swig/$SWIG.tar.gz&lt;br /&gt;
 tar xzvf $SWIG.tar.gz &lt;br /&gt;
 cd $SWIG&lt;br /&gt;
 ./configure &lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
This downloads and installs VTK from source, in the ccmake stage, use the cmake graphical commands to get a working install. &lt;br /&gt;
 VTK=vtk-5.0.3&lt;br /&gt;
 wget -nc http://www.vtk.org/files/release/5.0/$VTK.tar.gz&lt;br /&gt;
 tar xzvf $VTK.tar.gz&lt;br /&gt;
 mkdir vtkbin&lt;br /&gt;
 cd vtkbin&lt;br /&gt;
 ccmake ../VTK&lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== Install TexGen from source ===&lt;br /&gt;
Now we can proceed to install texgen, as an example we&amp;#039;ll work in ~/temp/texgen&lt;br /&gt;
 cd ~; mkdir temp; cd temp; mkdir texgen; cd texgen&lt;br /&gt;
 svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen&lt;br /&gt;
 cd .. ; mkdir tbin; cd tbin&lt;br /&gt;
 ccmake ../texgen&lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
This should result in a working texgen install in ~/temp/texgen/tbin.&lt;br /&gt;
&lt;br /&gt;
== Unix ==&lt;br /&gt;
=== Notes ===&lt;br /&gt;
If you are installing to a system where you don&amp;#039;t have root access (i.e. this computer does not belong to you) you won&amp;#039;t be able to install the software using the default configure script. This is because by default software is installed to the /usr/local directory. If you are not a systems administrator then you will quite rightly not have write access to this folder. All is not lost! You can still install software into your home directory. In order to do this you should always call the configure script with the following parameter: --prefix=$HOME. This goes for all the software to be installed below. All executables will then be placed in ~/bin, libraries in ~/lib, includes in ~/include, etc...&lt;br /&gt;
&lt;br /&gt;
In the guide below the parameter is included in italic. If you do in fact have root access then it is recommended to omit this parameter and install to the default directory so that other users will also have access to the software.&lt;br /&gt;
&lt;br /&gt;
=== Get TexGen from Subversion repository ===&lt;br /&gt;
&lt;br /&gt;
==== Install Subversion ====&lt;br /&gt;
[http://subversion.tigris.org/servlets/ProjectDocumentList?collapseFolder=260&amp;amp;folderID=260 Download Subversion] and unpack.&lt;br /&gt;
Open a shell in extracted folder and type:&lt;br /&gt;
 ./configure --with-ssl &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* You will need to install Subversion with SSL support since TexGen is hosted on sourceforge which uses SSL. If you don&amp;#039;t configure with the --with-ssl flag you will get an error when trying to checkout TexGen in the next step.&lt;br /&gt;
* If you have trouble installing the latest version of Subversion, try installing version 1.3 as it does not require a seperate dependencies package.&lt;br /&gt;
&lt;br /&gt;
==== Checkout ====&lt;br /&gt;
Open a shell in folder you wish to place TexGen (e.g. ~/):&lt;br /&gt;
 svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The first parameter tells SVN to get the files for the first time&lt;br /&gt;
* The second parameter is the location of the TexGen svn repository&lt;br /&gt;
* The final parameter is the subfolder to put the files in&lt;br /&gt;
&lt;br /&gt;
==== Update ====&lt;br /&gt;
The checkout command only needs to performed once. SVN keeps track of where the code was originally obtained and can update to the latest version without having to re-specify the location. In order to do that open a shell in the folder where TexGen was originally checkout (e.g. ~/TexGen) and type:&lt;br /&gt;
 svn update&lt;br /&gt;
or if you are in a hurry you can type the shorter version:&lt;br /&gt;
 svn up&lt;br /&gt;
&lt;br /&gt;
=== Compile source ===&lt;br /&gt;
&lt;br /&gt;
==== Install CMake ====&lt;br /&gt;
&lt;br /&gt;
[http://www.cmake.org/HTML/Download.html Download CMake] and unpack.&lt;br /&gt;
Open a shell in extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
==== Compile TexGen core ====&lt;br /&gt;
Open a shell in the folder with the TexGen source code (e.g. ~/TexGen):&lt;br /&gt;
 mkdir bin&lt;br /&gt;
 cd bin&lt;br /&gt;
 ccmake ../&lt;br /&gt;
Press &amp;#039;c&amp;#039; to configure. When a warning pops up telling you it can&amp;#039;t find such and such a file press &amp;#039;e&amp;#039; to close it. You will now need to specify which components of TexGen to build and where their dependencies can be found. Use the up and down arrows to move the caret and press enter to modify options. Do this to set BUILD_GUI, BUILD_PYTHON_INTERFACE and BUILD_RENDERER to OFF. You are basically telling CMake not to attempt to build these components, which means that you won&amp;#039;t need to have installed their dependencies.&lt;br /&gt;
&lt;br /&gt;
Similarly to the --prefix=$HOME parameter to the configure script, you can tell CMake to install TexGen to your home directory by changing CMAKE_INSTALL_PREFIX to ~/. Note that it won&amp;#039;t actually install anything until you get type make install.&lt;br /&gt;
&lt;br /&gt;
Now press &amp;#039;c&amp;#039; again to update the changes.&lt;br /&gt;
&lt;br /&gt;
Hopefully now that all the additional modules have been switched off no errors will be shown. Press &amp;#039;g&amp;#039; to generate the makefiles and exit. At the shell type:&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Note that at this point you have only built and installed the TexGen Core library which doesn&amp;#039;t actually do anything on its own. If you plan to incorporate TexGen into your own C++ program then this is enough, however if you would like to interface with TexGen from a Python script or Graphical User Interface then follow the steps below.&lt;br /&gt;
&lt;br /&gt;
=== Compiling optional modules ===&lt;br /&gt;
==== Python interface ====&lt;br /&gt;
[http://www.python.org/download/ Download Python] and unpack.&lt;br /&gt;
Open a shell in the extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
[http://www.swig.org/download.html Download SWIG] and unpack.&lt;br /&gt;
Open a shell in the extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Open a shell in the folder where you called ccmake from for the first time (e.g. ~/TexGen/bin):&lt;br /&gt;
 ccmake ../&lt;br /&gt;
&lt;br /&gt;
Use the up and down arrows to reach BUILD_PYTHON_INTERFACE and press Enter to set it to ON. Then press &amp;#039;c&amp;#039; to configure. You will probably get a warning saying you need to specify the location of SWIG and/or Python, press &amp;#039;e&amp;#039; to close it.&lt;br /&gt;
&lt;br /&gt;
Set the PYTHON_INCLUDE_PATH, PYTHON_LIBRARY, PYTHON_SITEPACKAGES_DIR, SWIG_DIR and SWIG_EXECUTABLE parameters correctly where necessary. If you have installed packages to your home directory then they should look something like this:&lt;br /&gt;
&lt;br /&gt;
 PYTHON_INCLUDE_PATH: ~/include/python2.5&lt;br /&gt;
 PYTHON_LIBRARY: ~/lib/python2.5/config/libpython2.5.a&lt;br /&gt;
 PYTHON_SITEPACKAGES_DIR: ~/lib/python2.5/site-packages&lt;br /&gt;
 SWIG_DIR: ~/bin&lt;br /&gt;
 SWIG_EXECUTABLE: ~/bin/swig&lt;br /&gt;
&lt;br /&gt;
Once that is done press &amp;#039;c&amp;#039; again. You may need perform this process over several iterations. When everything is set correctly press &amp;#039;g&amp;#039; to generate the makefiles.&lt;br /&gt;
&lt;br /&gt;
At the shell type:&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Assuming the build completed without errors you should now be able to access TexGen functions from within Python. In order to check everything worked as planned open Python in interactive mode by typing:&lt;br /&gt;
 python&lt;br /&gt;
&lt;br /&gt;
Then from within Python type:&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
 CTexGen.GetInstance().GetVersion()&lt;br /&gt;
&lt;br /&gt;
This should display the version of TexGen installed.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when linking _Core.so:&lt;br /&gt;
 libpython2.5.a(abstract.o): relocation R_X86_64_32 against `a local symbol&amp;#039;&lt;br /&gt;
 can not be used when making a shared object; recompile with -fPIC&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; Try removing libpython2.5.a from the libraries to link to by setting PYTHON_LIBRARY to a bogus path, e.g.:&lt;br /&gt;
&lt;br /&gt;
PYTHON_LIBRARY: ~/&lt;br /&gt;
&lt;br /&gt;
By doing so you may receive a warning similar to this:&lt;br /&gt;
 Warning: Ignoring path found in link libraries for target: _Core, path is:&lt;br /&gt;
 /home/username. Expected a library name or a full path to a library name.&lt;br /&gt;
This warning may be ignored.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Create Models</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-09T11:55:31Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Example 4: A sheared plain weave */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Example 1: A plain weave===&lt;br /&gt;
First of all, a Python script is just a plain ASCII text file with a .py extension. To create one simply open up your favorite text editor. Notepad will do if you have nothing else but I suggest a more powerful freeware text editor like [http://www.pspad.com/ PSPad] or [http://notepad-plus.sourceforge.net/ Notepad++]. Code that goes into the python script will be displayed like so:&lt;br /&gt;
&lt;br /&gt;
 # All Python code will be shown in a box like this one.&lt;br /&gt;
 # Lines begining with a &amp;#039;#&amp;#039; character are comments&lt;br /&gt;
&lt;br /&gt;
In this example, we will create a simple 2x2 plain weave model with a Python script. Its time to dive in and see some actual Python code. At this point if you are completely lost please refer back to the resources on Python programming. The first step is to create an instance of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class and give it a name, &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class takes 5 parameters in the order shown below:&lt;br /&gt;
* Number of weft yarns in the unit cell&lt;br /&gt;
* Number of warp yarns in the unit cell&lt;br /&gt;
* Spacing between the yarns&lt;br /&gt;
* Thickness of the fabrics&lt;br /&gt;
* Refine model (True/False)&lt;br /&gt;
&lt;br /&gt;
The only parameter that really needs an explanation here is the Refine model option, this controls whether or not the interference correction algorithm will be applied to keep the yarn volumes from intersecting which is a common problem. The interference correction algorithm generally does a good job but is not instantaneous so sometimes it can be beneficial to switch it off.&lt;br /&gt;
&lt;br /&gt;
This is the bare minimum information necessary to create a 2D woven fabric. In the following steps we will add more information to create the model the way we want it.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s set the weave pattern, this determines whether a warp or weft yarn will appear on top at a particular cross over. Cross overs are arranged in 2d grid where the size of the grid depends on the number of warp and weft yarns created. To swap the positions of the weft and warp yarns, we call the function &amp;lt;code&amp;gt;SwapPosition&amp;lt;/code&amp;gt; with the grid coordinates of the cross over. In order to create a plain weave we need to do this on two diagonally opposite cross overs like so:&lt;br /&gt;
&lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
&lt;br /&gt;
Now let&amp;#039;s add our &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt; model to the database of models so that TexGen can render it:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Thats it! This is a very simple script but it will generate a plain weave model. To recap your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
 &lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Save it to disk as &amp;#039;&amp;#039;PlainWeave.py&amp;#039;&amp;#039; or give it whatever name you want as long as it has a &amp;#039;&amp;#039;.py&amp;#039;&amp;#039; extension.&lt;br /&gt;
&lt;br /&gt;
In order to test the Script we need to load it into TexGen. So start up the TexGen GUI and from the &amp;#039;&amp;#039;Python menu&amp;#039;&amp;#039; select &amp;#039;&amp;#039;Run Script&amp;#039;&amp;#039;. Select the file you have just saved and click ok. With a bit of luck you should see a 2d plain weave on screen:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Congratulations you have created your first TexGen Python script!&lt;br /&gt;
&lt;br /&gt;
===Example 2: Another plain weave (the hard way)===&lt;br /&gt;
In the first example we made use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; which is the reason the script is so compact. This was great for creating a 2D Weave, but what if we want to create something other than a 2D Weave? Well, let&amp;#039;s stick to the 2D weave for now but in this example we will create geometric model in a generic way without the use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class. This takes a little bit longer to do, but gives more control over the final geometry.&lt;br /&gt;
&lt;br /&gt;
First we will define a general textile and call it &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextile&amp;lt;/code&amp;gt; class doesn&amp;#039;t take any parameters, instead yarns will be created and added to it. Next we will create 4 yarns to go inside our textile, it is convenient to make use of the Python lists to do this. Create a list called &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; with 4 elements, each one an instance of the class &amp;lt;code&amp;gt;CYarn&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; now contains 4 empty yarns. Note that the yarns are not currently associated with the Textile, first we must fill in the details then make them a part of the textile. The first thing to do is define their paths with nodes. This is done like so:&lt;br /&gt;
&lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
&lt;br /&gt;
We have added 3 nodes to each yarn creating a woven pattern. The number in the square brackets after &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; refers to a particular yarn in the list. The function &amp;lt;code&amp;gt;AddNode&amp;lt;/code&amp;gt; is then called for the yarn. The function takes an instance of the class &amp;lt;code&amp;gt;CNode&amp;lt;/code&amp;gt; which in turn is constructed with an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; representing the position of the node. The class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers representing the X, Y and Z coordinates of the point.&lt;br /&gt;
&lt;br /&gt;
We still need to define a few more things to obtain a model. For the sake of simplicity, we will give all the yarns the same cross sectional shape, width, height, etc... The easiest way to do this is to loop over the yarns and assign the same properties to each yarn one by one. The syntax for looping over &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
&lt;br /&gt;
Inside the loop, the variable &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; refers to the current yarn in the list. So within the loop we just assign properties to &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; and they will be applied to all the yarns in the list. In python the begining and end of a loop are defined by indentation, hence the following lines are indented to represent the contents of the loop.&lt;br /&gt;
&lt;br /&gt;
Let us define periodic cubic spline interpolation between the nodes:&lt;br /&gt;
&lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
&lt;br /&gt;
This is done with the function &amp;lt;code&amp;gt;AssignInterpolation&amp;lt;/code&amp;gt; which takes an instance of a class derived from &amp;lt;code&amp;gt;CInterpolation&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CInterpolationCubic&amp;lt;/code&amp;gt; to specify periodic cubic spline interpolation.&lt;br /&gt;
&lt;br /&gt;
Next we need to define a cross section for the yarn, to keep things simple a constant cross section all along the length of the yarn will be defined:&lt;br /&gt;
&lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignSection&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CYarnSection&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CYarnSectionConstant&amp;lt;/code&amp;gt; which in turns take an instance of a class derived from &amp;lt;code&amp;gt;CSection&amp;lt;/code&amp;gt; as a constructor. &amp;lt;code&amp;gt;CSectionEllipse&amp;lt;/code&amp;gt; defines an elliptical cross section with given width and height defined by the first and second parameters respectively.&lt;br /&gt;
&lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
This line sets the resolution of the surface mesh created. The first parameter to the function &amp;lt;code&amp;gt;SetResolution&amp;lt;/code&amp;gt; represents the number of points around a cross section. The number of points along the length of the yarns is automatically calculated such that the distance between points is similar to around the cross section.&lt;br /&gt;
&lt;br /&gt;
Next we must add repeat vectors to define how the yarns are repeated.&lt;br /&gt;
&lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AddRepeat&amp;lt;/code&amp;gt; takes an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;. As we saw earlier the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers defining the X, Y and Z components.&lt;br /&gt;
&lt;br /&gt;
Finally the yarn is fully defined, it can now be added to &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
This is the end of the loop, hence the following lines return to the original indentation. Now let&amp;#039;s define a Domain within which the textile will be placed:&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignDomain&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CDomain&amp;lt;/code&amp;gt;. In this case we will create a box shaped domain, this can be accomplished by using the class &amp;lt;code&amp;gt;CDomainPlanes&amp;lt;/code&amp;gt;. A box can be created by passing in opposite corners of the box (the minimum and maximum coordinates). This is done again with the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And finally &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt; must be added to so that it can be rendered. Each Textile added must be assigned a name to identify it, this is the name that will appear at the top in the TexGen GUI. This name can either be generated automatically or we can specify it explicitly like so:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! You now have the knowledge to create any type of fabric imaginable. Well, almost. The model created here is pretty simple, there is plenty of oppertunity to create more complex shapes. For example non-constant cross sections can be defined, complex domain shapes defined by arbritrary planes, different interpolation functions.&lt;br /&gt;
&lt;br /&gt;
Here is the completed script:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
 &lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
 &lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
 &lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
 &lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
 &lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
 &lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
 &lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create a domain and assign it to the textile&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example2.png]]&lt;br /&gt;
&lt;br /&gt;
===Example 3: A 3d weave===&lt;br /&gt;
This example is similar to the [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]] in that the yarns will be defined by nodes. This time we will create a 3d woven fabric that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example3.png]]&lt;br /&gt;
&lt;br /&gt;
We start by defining a new CTextile instance:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
Before starting to define the geometry using TexGen it is helpful to define a list of parameters which may need to be changed later. These typically include spacing between yarns and yarn dimensions:&lt;br /&gt;
&lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
&lt;br /&gt;
It is a good idea to define these up front rather than hard coding them in the rest of the script because if you want to tweak any parameters they can easily be located and will only need to be changed once. Lets start by defining the warp stuffer yarns, these are fairly easy to define since they all straight and parallel to each other:&lt;br /&gt;
&lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Next we define the weft stuffer yarns, again these are easy to define:&lt;br /&gt;
&lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
And finally we need to insert the binder yarns. Making clever use of the repeat vectors it is only necessary to define a single instance of the binder yarn.&lt;br /&gt;
&lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Now that the geometry is defined we shall define a domain and add the textile so that TexGen knows about it.&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
The completed scripts is shown below:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
 &lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
===Example 4: A sheared plain weave===&lt;br /&gt;
This example builds on [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]], except this time we will be modeling a sheared unit cell. The final script can be found at the bottom, I will not step through each section of case as I have done for the previous cases since you should now be familiar with the basic procedure.&lt;br /&gt;
&lt;br /&gt;
You will notice at the top of the script the line &amp;lt;code&amp;gt;from math import *&amp;lt;/code&amp;gt;, this is a Python command to import the contents of the math module. We need this here because we will be making use of the value &amp;lt;code&amp;gt;pi&amp;lt;/code&amp;gt; and functions &amp;lt;code&amp;gt;cos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sin&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this script I have also defined some constants up front (spacing, height, shear angle, twist angle and shear offset) as they will get used frequently within the script. It is best to define them as variables so that they can easily be modified later.&lt;br /&gt;
&lt;br /&gt;
The position of the nodes are arranged as plain weave but displaced slightly by the shear offset. Note that if the shear angle is 0, the shear offset is also 0 and the position of the nodes is equivalent to [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]].&lt;br /&gt;
&lt;br /&gt;
The next difference is how the cross-section is defined. When a plain woven fabric is sheared the yarn is likely to twist, so we can no longer use a constant cross-section all along the length of the yarn. Instead here I have defined a yarn which twists in one direction at 1/4 of its way along the length of the yarn and twists in the other direction at 3/4 of the way along the length of the yarn. This is to avoid intersections between the yarns. The cross-section is interpolated at other positions along the yarn.&lt;br /&gt;
&lt;br /&gt;
The repeat vectors are defined to take into account the shear and is fairly straight forwards.&lt;br /&gt;
&lt;br /&gt;
The next complication is defining a domain which is sheared. This is done by specifying 6 planes which define the bounds of the domain. The normals of the planes must point inwards, in the case of an unsheared fabric the normals are all in line with the global axes. But in order to create a lozenge shaped unit cell these normals must be rotated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from math import *&lt;br /&gt;
&lt;br /&gt;
# Create a textile&lt;br /&gt;
Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a python list containing 4 yarns&lt;br /&gt;
Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
# Define some constants that will be used in further calculations&lt;br /&gt;
spacing = 0.22&lt;br /&gt;
height = 0.05&lt;br /&gt;
&lt;br /&gt;
shearAngle = pi/16&lt;br /&gt;
twistAngle = shearAngle&lt;br /&gt;
&lt;br /&gt;
shearOffset = spacing*sin(shearAngle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Add nodes to the yarns to describe their paths, these are the sheared node positions&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(spacing, shearOffset, height)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(2*spacing, 2*shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(0+shearOffset, spacing, height)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, 0)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(2*spacing+shearOffset, spacing+2*shearOffset, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(0, 0, height)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(shearOffset, spacing, 0)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(2*shearOffset, 2*spacing, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing, 0+shearOffset, 0)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, height)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+2*shearOffset, 2*spacing+shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
# Create a cross-section which twists along the length of the yarn to accommodate the sheared fabric architecture&lt;br /&gt;
ellipse = CSectionEllipse(0.18, 0.04)&lt;br /&gt;
sectionTwist1 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist1.AddSection(0.25, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
sectionTwist1.AddSection(0.75, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist2.AddSection(0.25, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2.AddSection(0.75, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
&lt;br /&gt;
for Yarn in (Yarns[1], Yarns[3]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist1)&lt;br /&gt;
for Yarn in (Yarns[0], Yarns[2]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist2)&lt;br /&gt;
&lt;br /&gt;
# Loop over all the yarns in the list&lt;br /&gt;
for Yarn in Yarns:&lt;br /&gt;
    # Set the resolution of the surface mesh created&lt;br /&gt;
    Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
    # Add repeat vectors to the yarn&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*spacing, 2*shearOffset, 0))&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*shearOffset, 2*spacing, 0))&lt;br /&gt;
&lt;br /&gt;
    # Add the yarn to our textile&lt;br /&gt;
    Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
# Create a sheared domain with 6 planes&lt;br /&gt;
domain = CDomainPlanes()&lt;br /&gt;
d = (2*spacing-2*shearOffset*sin(shearAngle))/sqrt(1+sin(shearAngle)**2)&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(1, -sin(shearAngle), 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-1, sin(shearAngle), 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-sin(shearAngle), 1, 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(sin(shearAngle), -1, 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, 1), -height))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, -1), -2*height))&lt;br /&gt;
Textile.AssignDomain(domain)&lt;br /&gt;
&lt;br /&gt;
# Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you run the script your model should look like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example4.png]]&lt;br /&gt;
&lt;br /&gt;
===Saving to TG3 file format===&lt;br /&gt;
TexGen has it&amp;#039;s own file format for storing textile geometry with the extension .tg3. For more details on this file format please read the [[TG3 File Format]] page. Any textile models saved to this file format can be reloaded at a later time however it is also a good idea to keep the python script used to generate the geometry in case modifications need to be made. To save such a file it is simply a matter of adding an additional like at the end of your script like so:&lt;br /&gt;
&lt;br /&gt;
 SaveToXML(&amp;quot;MyTextile.tg3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The first parameter is the name of the file to save, note that if the .tg3 extension is omitted then it will automatically be appended for you. The second parameter is optional and if used should be the name of the textile to save, this is useful if you have several textiles loaded at once (i.e. you called AddTextile more than once) and you only want to save one of them. Note that if you don&amp;#039;t specify the second parameter and you do have several textiles loaded then it will save all of them to a single .tg3 file. The third parameter determines how much information is saved in the .tg3 file, see the [[TG3 File Format]] for more details.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Create Models</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-09T11:53:35Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Example 1: A plain weave===&lt;br /&gt;
First of all, a Python script is just a plain ASCII text file with a .py extension. To create one simply open up your favorite text editor. Notepad will do if you have nothing else but I suggest a more powerful freeware text editor like [http://www.pspad.com/ PSPad] or [http://notepad-plus.sourceforge.net/ Notepad++]. Code that goes into the python script will be displayed like so:&lt;br /&gt;
&lt;br /&gt;
 # All Python code will be shown in a box like this one.&lt;br /&gt;
 # Lines begining with a &amp;#039;#&amp;#039; character are comments&lt;br /&gt;
&lt;br /&gt;
In this example, we will create a simple 2x2 plain weave model with a Python script. Its time to dive in and see some actual Python code. At this point if you are completely lost please refer back to the resources on Python programming. The first step is to create an instance of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class and give it a name, &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class takes 5 parameters in the order shown below:&lt;br /&gt;
* Number of weft yarns in the unit cell&lt;br /&gt;
* Number of warp yarns in the unit cell&lt;br /&gt;
* Spacing between the yarns&lt;br /&gt;
* Thickness of the fabrics&lt;br /&gt;
* Refine model (True/False)&lt;br /&gt;
&lt;br /&gt;
The only parameter that really needs an explanation here is the Refine model option, this controls whether or not the interference correction algorithm will be applied to keep the yarn volumes from intersecting which is a common problem. The interference correction algorithm generally does a good job but is not instantaneous so sometimes it can be beneficial to switch it off.&lt;br /&gt;
&lt;br /&gt;
This is the bare minimum information necessary to create a 2D woven fabric. In the following steps we will add more information to create the model the way we want it.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s set the weave pattern, this determines whether a warp or weft yarn will appear on top at a particular cross over. Cross overs are arranged in 2d grid where the size of the grid depends on the number of warp and weft yarns created. To swap the positions of the weft and warp yarns, we call the function &amp;lt;code&amp;gt;SwapPosition&amp;lt;/code&amp;gt; with the grid coordinates of the cross over. In order to create a plain weave we need to do this on two diagonally opposite cross overs like so:&lt;br /&gt;
&lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
&lt;br /&gt;
Now let&amp;#039;s add our &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt; model to the database of models so that TexGen can render it:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Thats it! This is a very simple script but it will generate a plain weave model. To recap your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
 &lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Save it to disk as &amp;#039;&amp;#039;PlainWeave.py&amp;#039;&amp;#039; or give it whatever name you want as long as it has a &amp;#039;&amp;#039;.py&amp;#039;&amp;#039; extension.&lt;br /&gt;
&lt;br /&gt;
In order to test the Script we need to load it into TexGen. So start up the TexGen GUI and from the &amp;#039;&amp;#039;Python menu&amp;#039;&amp;#039; select &amp;#039;&amp;#039;Run Script&amp;#039;&amp;#039;. Select the file you have just saved and click ok. With a bit of luck you should see a 2d plain weave on screen:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Congratulations you have created your first TexGen Python script!&lt;br /&gt;
&lt;br /&gt;
===Example 2: Another plain weave (the hard way)===&lt;br /&gt;
In the first example we made use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; which is the reason the script is so compact. This was great for creating a 2D Weave, but what if we want to create something other than a 2D Weave? Well, let&amp;#039;s stick to the 2D weave for now but in this example we will create geometric model in a generic way without the use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class. This takes a little bit longer to do, but gives more control over the final geometry.&lt;br /&gt;
&lt;br /&gt;
First we will define a general textile and call it &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextile&amp;lt;/code&amp;gt; class doesn&amp;#039;t take any parameters, instead yarns will be created and added to it. Next we will create 4 yarns to go inside our textile, it is convenient to make use of the Python lists to do this. Create a list called &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; with 4 elements, each one an instance of the class &amp;lt;code&amp;gt;CYarn&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; now contains 4 empty yarns. Note that the yarns are not currently associated with the Textile, first we must fill in the details then make them a part of the textile. The first thing to do is define their paths with nodes. This is done like so:&lt;br /&gt;
&lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
&lt;br /&gt;
We have added 3 nodes to each yarn creating a woven pattern. The number in the square brackets after &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; refers to a particular yarn in the list. The function &amp;lt;code&amp;gt;AddNode&amp;lt;/code&amp;gt; is then called for the yarn. The function takes an instance of the class &amp;lt;code&amp;gt;CNode&amp;lt;/code&amp;gt; which in turn is constructed with an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; representing the position of the node. The class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers representing the X, Y and Z coordinates of the point.&lt;br /&gt;
&lt;br /&gt;
We still need to define a few more things to obtain a model. For the sake of simplicity, we will give all the yarns the same cross sectional shape, width, height, etc... The easiest way to do this is to loop over the yarns and assign the same properties to each yarn one by one. The syntax for looping over &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
&lt;br /&gt;
Inside the loop, the variable &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; refers to the current yarn in the list. So within the loop we just assign properties to &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; and they will be applied to all the yarns in the list. In python the begining and end of a loop are defined by indentation, hence the following lines are indented to represent the contents of the loop.&lt;br /&gt;
&lt;br /&gt;
Let us define periodic cubic spline interpolation between the nodes:&lt;br /&gt;
&lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
&lt;br /&gt;
This is done with the function &amp;lt;code&amp;gt;AssignInterpolation&amp;lt;/code&amp;gt; which takes an instance of a class derived from &amp;lt;code&amp;gt;CInterpolation&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CInterpolationCubic&amp;lt;/code&amp;gt; to specify periodic cubic spline interpolation.&lt;br /&gt;
&lt;br /&gt;
Next we need to define a cross section for the yarn, to keep things simple a constant cross section all along the length of the yarn will be defined:&lt;br /&gt;
&lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignSection&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CYarnSection&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CYarnSectionConstant&amp;lt;/code&amp;gt; which in turns take an instance of a class derived from &amp;lt;code&amp;gt;CSection&amp;lt;/code&amp;gt; as a constructor. &amp;lt;code&amp;gt;CSectionEllipse&amp;lt;/code&amp;gt; defines an elliptical cross section with given width and height defined by the first and second parameters respectively.&lt;br /&gt;
&lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
This line sets the resolution of the surface mesh created. The first parameter to the function &amp;lt;code&amp;gt;SetResolution&amp;lt;/code&amp;gt; represents the number of points around a cross section. The number of points along the length of the yarns is automatically calculated such that the distance between points is similar to around the cross section.&lt;br /&gt;
&lt;br /&gt;
Next we must add repeat vectors to define how the yarns are repeated.&lt;br /&gt;
&lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AddRepeat&amp;lt;/code&amp;gt; takes an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;. As we saw earlier the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers defining the X, Y and Z components.&lt;br /&gt;
&lt;br /&gt;
Finally the yarn is fully defined, it can now be added to &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
This is the end of the loop, hence the following lines return to the original indentation. Now let&amp;#039;s define a Domain within which the textile will be placed:&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignDomain&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CDomain&amp;lt;/code&amp;gt;. In this case we will create a box shaped domain, this can be accomplished by using the class &amp;lt;code&amp;gt;CDomainPlanes&amp;lt;/code&amp;gt;. A box can be created by passing in opposite corners of the box (the minimum and maximum coordinates). This is done again with the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And finally &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt; must be added to so that it can be rendered. Each Textile added must be assigned a name to identify it, this is the name that will appear at the top in the TexGen GUI. This name can either be generated automatically or we can specify it explicitly like so:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! You now have the knowledge to create any type of fabric imaginable. Well, almost. The model created here is pretty simple, there is plenty of oppertunity to create more complex shapes. For example non-constant cross sections can be defined, complex domain shapes defined by arbritrary planes, different interpolation functions.&lt;br /&gt;
&lt;br /&gt;
Here is the completed script:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
 &lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
 &lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
 &lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
 &lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
 &lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
 &lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
 &lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create a domain and assign it to the textile&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example2.png]]&lt;br /&gt;
&lt;br /&gt;
===Example 3: A 3d weave===&lt;br /&gt;
This example is similar to the [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]] in that the yarns will be defined by nodes. This time we will create a 3d woven fabric that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example3.png]]&lt;br /&gt;
&lt;br /&gt;
We start by defining a new CTextile instance:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
Before starting to define the geometry using TexGen it is helpful to define a list of parameters which may need to be changed later. These typically include spacing between yarns and yarn dimensions:&lt;br /&gt;
&lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
&lt;br /&gt;
It is a good idea to define these up front rather than hard coding them in the rest of the script because if you want to tweak any parameters they can easily be located and will only need to be changed once. Lets start by defining the warp stuffer yarns, these are fairly easy to define since they all straight and parallel to each other:&lt;br /&gt;
&lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Next we define the weft stuffer yarns, again these are easy to define:&lt;br /&gt;
&lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
And finally we need to insert the binder yarns. Making clever use of the repeat vectors it is only necessary to define a single instance of the binder yarn.&lt;br /&gt;
&lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Now that the geometry is defined we shall define a domain and add the textile so that TexGen knows about it.&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
The completed scripts is shown below:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
 &lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
===Example 4: A sheared plain weave===&lt;br /&gt;
This example builds on [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]], except this time we will be modeling a sheared unit cell. The final script can be found at the bottom, I will not step through each section of case as I have done for the previous cases since you should now be familiar with the basic procedure.&lt;br /&gt;
&lt;br /&gt;
You will notice at the top of the script the line &amp;lt;code&amp;gt;from math import *&amp;lt;/code&amp;gt;, this is a Python command to import the contents of the math module. We need this here because we will be making use of the value &amp;lt;code&amp;gt;pi&amp;lt;/code&amp;gt; and functions &amp;lt;code&amp;gt;cos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sin&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this script I have also defined some constants up front (spacing, height, shear angle, twist angle and shear offset) as they will get used frequently within the script. It is best to define them as variables so that they can easily be modified later.&lt;br /&gt;
&lt;br /&gt;
The position of the nodes are arranged as plain weave but displaced slightly by the shear offset. Note that if the shear angle is 0, the shear offset is also 0 and the position of the nodes is equivalent to [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]].&lt;br /&gt;
&lt;br /&gt;
The next difference is how the cross-section is defined. When a plain woven fabric is sheared the yarn is likely to twist, so we can no longer use a constant cross-section all along the length of the yarn. Instead here I have defined a yarn which twists in one direction at 1/4 of its way along the length of the yarn and twists in the other direction at 3/4 of the way along the length of the yarn. This is to avoid intersections between the yarns. The cross-section is interpolated at other positions along the yarn.&lt;br /&gt;
&lt;br /&gt;
The repeat vectors are defined to take into account the shear and is fairly straight forwards.&lt;br /&gt;
&lt;br /&gt;
The next complication is defining a domain which is shared. This is done by specifying 6 planes which define the bounds of the domain. The normals of the planes must point inwards, in the case of an unsheared fabric the normals are all in line with the global axes. But in order to create a lozenge shaped unit cell these normals must be rotated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from math import *&lt;br /&gt;
&lt;br /&gt;
# Create a textile&lt;br /&gt;
Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a python list containing 4 yarns&lt;br /&gt;
Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
# Define some constants that will be used in further calculations&lt;br /&gt;
spacing = 0.22&lt;br /&gt;
height = 0.05&lt;br /&gt;
&lt;br /&gt;
shearAngle = pi/16&lt;br /&gt;
twistAngle = shearAngle&lt;br /&gt;
&lt;br /&gt;
shearOffset = spacing*sin(shearAngle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Add nodes to the yarns to describe their paths, these are the sheared node positions&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(spacing, shearOffset, height)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(2*spacing, 2*shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(0+shearOffset, spacing, height)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, 0)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(2*spacing+shearOffset, spacing+2*shearOffset, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(0, 0, height)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(shearOffset, spacing, 0)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(2*shearOffset, 2*spacing, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing, 0+shearOffset, 0)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, height)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+2*shearOffset, 2*spacing+shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
# Create a cross-section which twists along the length of the yarn to accommodate the sheared fabric architecture&lt;br /&gt;
ellipse = CSectionEllipse(0.18, 0.04)&lt;br /&gt;
sectionTwist1 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist1.AddSection(0.25, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
sectionTwist1.AddSection(0.75, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist2.AddSection(0.25, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2.AddSection(0.75, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
&lt;br /&gt;
for Yarn in (Yarns[1], Yarns[3]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist1)&lt;br /&gt;
for Yarn in (Yarns[0], Yarns[2]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist2)&lt;br /&gt;
&lt;br /&gt;
# Loop over all the yarns in the list&lt;br /&gt;
for Yarn in Yarns:&lt;br /&gt;
    # Set the resolution of the surface mesh created&lt;br /&gt;
    Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
    # Add repeat vectors to the yarn&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*spacing, 2*shearOffset, 0))&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*shearOffset, 2*spacing, 0))&lt;br /&gt;
&lt;br /&gt;
    # Add the yarn to our textile&lt;br /&gt;
    Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
# Create a sheared domain with 6 planes&lt;br /&gt;
domain = CDomainPlanes()&lt;br /&gt;
d = (2*spacing-2*shearOffset*sin(shearAngle))/sqrt(1+sin(shearAngle)**2)&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(1, -sin(shearAngle), 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-1, sin(shearAngle), 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-sin(shearAngle), 1, 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(sin(shearAngle), -1, 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, 1), -height))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, -1), -2*height))&lt;br /&gt;
Textile.AssignDomain(domain)&lt;br /&gt;
&lt;br /&gt;
# Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you run the script your model should look like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example4.png]]&lt;br /&gt;
&lt;br /&gt;
===Saving to TG3 file format===&lt;br /&gt;
TexGen has it&amp;#039;s own file format for storing textile geometry with the extension .tg3. For more details on this file format please read the [[TG3 File Format]] page. Any textile models saved to this file format can be reloaded at a later time however it is also a good idea to keep the python script used to generate the geometry in case modifications need to be made. To save such a file it is simply a matter of adding an additional like at the end of your script like so:&lt;br /&gt;
&lt;br /&gt;
 SaveToXML(&amp;quot;MyTextile.tg3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The first parameter is the name of the file to save, note that if the .tg3 extension is omitted then it will automatically be appended for you. The second parameter is optional and if used should be the name of the textile to save, this is useful if you have several textiles loaded at once (i.e. you called AddTextile more than once) and you only want to save one of them. Note that if you don&amp;#039;t specify the second parameter and you do have several textiles loaded then it will save all of them to a single .tg3 file. The third parameter determines how much information is saved in the .tg3 file, see the [[TG3 File Format]] for more details.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>File:Example4.png</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-09T11:52:50Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Create Models</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-09T11:49:14Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Example 4: A sheared plain weave */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Example 1: A plain weave===&lt;br /&gt;
First of all, a Python script is just a plain ASCII text file with a .py extension. To create one simply open up your favorite text editor. Notepad will do if you have nothing else but I suggest a more powerful freeware text editor like [http://www.pspad.com/ PSPad] or [http://notepad-plus.sourceforge.net/ Notepad++]. Code that goes into the python script will be displayed like so:&lt;br /&gt;
&lt;br /&gt;
 # All Python code will be shown in a box like this one.&lt;br /&gt;
 # Lines begining with a &amp;#039;#&amp;#039; character are comments&lt;br /&gt;
&lt;br /&gt;
In this example, we will create a simple 2x2 plain weave model with a Python script. Its time to dive in and see some actual Python code. At this point if you are completely lost please refer back to the resources on Python programming. The first step is to create an instance of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class and give it a name, &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class takes 5 parameters in the order shown below:&lt;br /&gt;
* Number of weft yarns in the unit cell&lt;br /&gt;
* Number of warp yarns in the unit cell&lt;br /&gt;
* Spacing between the yarns&lt;br /&gt;
* Thickness of the fabrics&lt;br /&gt;
* Refine model (True/False)&lt;br /&gt;
&lt;br /&gt;
The only parameter that really needs an explanation here is the Refine model option, this controls whether or not the interference correction algorithm will be applied to keep the yarn volumes from intersecting which is a common problem. The interference correction algorithm generally does a good job but is not instantaneous so sometimes it can be beneficial to switch it off.&lt;br /&gt;
&lt;br /&gt;
This is the bare minimum information necessary to create a 2D woven fabric. In the following steps we will add more information to create the model the way we want it.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s set the weave pattern, this determines whether a warp or weft yarn will appear on top at a particular cross over. Cross overs are arranged in 2d grid where the size of the grid depends on the number of warp and weft yarns created. To swap the positions of the weft and warp yarns, we call the function &amp;lt;code&amp;gt;SwapPosition&amp;lt;/code&amp;gt; with the grid coordinates of the cross over. In order to create a plain weave we need to do this on two diagonally opposite cross overs like so:&lt;br /&gt;
&lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
&lt;br /&gt;
Now let&amp;#039;s add our &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt; model to the database of models so that TexGen can render it:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Thats it! This is a very simple script but it will generate a plain weave model. To recap your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
 &lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Save it to disk as &amp;#039;&amp;#039;PlainWeave.py&amp;#039;&amp;#039; or give it whatever name you want as long as it has a &amp;#039;&amp;#039;.py&amp;#039;&amp;#039; extension.&lt;br /&gt;
&lt;br /&gt;
In order to test the Script we need to load it into TexGen. So start up the TexGen GUI and from the &amp;#039;&amp;#039;Python menu&amp;#039;&amp;#039; select &amp;#039;&amp;#039;Run Script&amp;#039;&amp;#039;. Select the file you have just saved and click ok. With a bit of luck you should see a 2d plain weave on screen:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Congratulations you have created your first TexGen Python script!&lt;br /&gt;
&lt;br /&gt;
===Example 2: Another plain weave (the hard way)===&lt;br /&gt;
In the first example we made use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; which is the reason the script is so compact. This was great for creating a 2D Weave, but what if we want to create something other than a 2D Weave? Well, let&amp;#039;s stick to the 2D weave for now but in this example we will create geometric model in a generic way without the use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class. This takes a little bit longer to do, but gives more control over the final geometry.&lt;br /&gt;
&lt;br /&gt;
First we will define a general textile and call it &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextile&amp;lt;/code&amp;gt; class doesn&amp;#039;t take any parameters, instead yarns will be created and added to it. Next we will create 4 yarns to go inside our textile, it is convenient to make use of the Python lists to do this. Create a list called &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; with 4 elements, each one an instance of the class &amp;lt;code&amp;gt;CYarn&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; now contains 4 empty yarns. Note that the yarns are not currently associated with the Textile, first we must fill in the details then make them a part of the textile. The first thing to do is define their paths with nodes. This is done like so:&lt;br /&gt;
&lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
&lt;br /&gt;
We have added 3 nodes to each yarn creating a woven pattern. The number in the square brackets after &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; refers to a particular yarn in the list. The function &amp;lt;code&amp;gt;AddNode&amp;lt;/code&amp;gt; is then called for the yarn. The function takes an instance of the class &amp;lt;code&amp;gt;CNode&amp;lt;/code&amp;gt; which in turn is constructed with an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; representing the position of the node. The class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers representing the X, Y and Z coordinates of the point.&lt;br /&gt;
&lt;br /&gt;
We still need to define a few more things to obtain a model. For the sake of simplicity, we will give all the yarns the same cross sectional shape, width, height, etc... The easiest way to do this is to loop over the yarns and assign the same properties to each yarn one by one. The syntax for looping over &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
&lt;br /&gt;
Inside the loop, the variable &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; refers to the current yarn in the list. So within the loop we just assign properties to &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; and they will be applied to all the yarns in the list. In python the begining and end of a loop are defined by indentation, hence the following lines are indented to represent the contents of the loop.&lt;br /&gt;
&lt;br /&gt;
Let us define periodic cubic spline interpolation between the nodes:&lt;br /&gt;
&lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
&lt;br /&gt;
This is done with the function &amp;lt;code&amp;gt;AssignInterpolation&amp;lt;/code&amp;gt; which takes an instance of a class derived from &amp;lt;code&amp;gt;CInterpolation&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CInterpolationCubic&amp;lt;/code&amp;gt; to specify periodic cubic spline interpolation.&lt;br /&gt;
&lt;br /&gt;
Next we need to define a cross section for the yarn, to keep things simple a constant cross section all along the length of the yarn will be defined:&lt;br /&gt;
&lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignSection&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CYarnSection&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CYarnSectionConstant&amp;lt;/code&amp;gt; which in turns take an instance of a class derived from &amp;lt;code&amp;gt;CSection&amp;lt;/code&amp;gt; as a constructor. &amp;lt;code&amp;gt;CSectionEllipse&amp;lt;/code&amp;gt; defines an elliptical cross section with given width and height defined by the first and second parameters respectively.&lt;br /&gt;
&lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
This line sets the resolution of the surface mesh created. The first parameter to the function &amp;lt;code&amp;gt;SetResolution&amp;lt;/code&amp;gt; represents the number of points around a cross section. The number of points along the length of the yarns is automatically calculated such that the distance between points is similar to around the cross section.&lt;br /&gt;
&lt;br /&gt;
Next we must add repeat vectors to define how the yarns are repeated.&lt;br /&gt;
&lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AddRepeat&amp;lt;/code&amp;gt; takes an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;. As we saw earlier the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers defining the X, Y and Z components.&lt;br /&gt;
&lt;br /&gt;
Finally the yarn is fully defined, it can now be added to &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
This is the end of the loop, hence the following lines return to the original indentation. Now let&amp;#039;s define a Domain within which the textile will be placed:&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignDomain&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CDomain&amp;lt;/code&amp;gt;. In this case we will create a box shaped domain, this can be accomplished by using the class &amp;lt;code&amp;gt;CDomainPlanes&amp;lt;/code&amp;gt;. A box can be created by passing in opposite corners of the box (the minimum and maximum coordinates). This is done again with the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And finally &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt; must be added to so that it can be rendered. Each Textile added must be assigned a name to identify it, this is the name that will appear at the top in the TexGen GUI. This name can either be generated automatically or we can specify it explicitly like so:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! You now have the knowledge to create any type of fabric imaginable. Well, almost. The model created here is pretty simple, there is plenty of oppertunity to create more complex shapes. For example non-constant cross sections can be defined, complex domain shapes defined by arbritrary planes, different interpolation functions.&lt;br /&gt;
&lt;br /&gt;
Here is the completed script:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
 &lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
 &lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
 &lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
 &lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
 &lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
 &lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
 &lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create a domain and assign it to the textile&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example2.png]]&lt;br /&gt;
&lt;br /&gt;
===Example 3: A 3d weave===&lt;br /&gt;
This example is similar to the [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]] in that the yarns will be defined by nodes. This time we will create a 3d woven fabric that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example3.png]]&lt;br /&gt;
&lt;br /&gt;
We start by defining a new CTextile instance:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
Before starting to define the geometry using TexGen it is helpful to define a list of parameters which may need to be changed later. These typically include spacing between yarns and yarn dimensions:&lt;br /&gt;
&lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
&lt;br /&gt;
It is a good idea to define these up front rather than hard coding them in the rest of the script because if you want to tweak any parameters they can easily be located and will only need to be changed once. Lets start by defining the warp stuffer yarns, these are fairly easy to define since they all straight and parallel to each other:&lt;br /&gt;
&lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Next we define the weft stuffer yarns, again these are easy to define:&lt;br /&gt;
&lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
And finally we need to insert the binder yarns. Making clever use of the repeat vectors it is only necessary to define a single instance of the binder yarn.&lt;br /&gt;
&lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Now that the geometry is defined we shall define a domain and add the textile so that TexGen knows about it.&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
The completed scripts is shown below:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
 &lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
===Example 4: A sheared plain weave===&lt;br /&gt;
This example builds on [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]], except this time we will be modeling a sheared unit cell. The final script can be found at the bottom, I will not step through each section of case as I have done for the previous cases since you should now be familiar with the basic procedure.&lt;br /&gt;
&lt;br /&gt;
You will notice at the top of the script the line &amp;lt;code&amp;gt;from math import *&amp;lt;/code&amp;gt;, this is a Python command to import the contents of the math module. We need this here because we will be making use of the value &amp;lt;code&amp;gt;pi&amp;lt;/code&amp;gt; and functions &amp;lt;code&amp;gt;cos&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;sin&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In this script I have also defined some constants up front (spacing, height, shear angle, twist angle and shear offset) as they will get used frequently within the script. It is best to define them as variables so that they can easily be modified later.&lt;br /&gt;
&lt;br /&gt;
The position of the nodes are arranged as plain weave but displaced slightly by the shear offset. Note that if the shear angle is 0, the shear offset is also 0 and the position of the nodes is equivalent to [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]].&lt;br /&gt;
&lt;br /&gt;
The next difference is how the cross-section is defined. When a plain woven fabric is sheared the yarn is likely to twist, so we can no longer use a constant cross-section all along the length of the yarn. Instead here I have defined a yarn which twists in one direction at 1/4 of its way along the length of the yarn and twists in the other direction at 3/4 of the way along the length of the yarn. This is to avoid intersections between the yarns. The cross-section is interpolated at other positions along the yarn.&lt;br /&gt;
&lt;br /&gt;
The repeat vectors are defined to take into account the shear and is fairly straight forwards.&lt;br /&gt;
&lt;br /&gt;
The next complication is defining a domain which is shared. This is done by specifying 6 planes which define the bounds of the domain. The normals of the planes must point inwards, in the case of an unsheared fabric the normals are all in line with the global axes. But in order to create a lozenge shaped unit cell these normals must be rotated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from math import *&lt;br /&gt;
&lt;br /&gt;
# Create a textile&lt;br /&gt;
Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a python list containing 4 yarns&lt;br /&gt;
Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
# Define some constants that will be used in further calculations&lt;br /&gt;
spacing = 0.22&lt;br /&gt;
height = 0.05&lt;br /&gt;
&lt;br /&gt;
shearAngle = pi/16&lt;br /&gt;
twistAngle = shearAngle&lt;br /&gt;
&lt;br /&gt;
shearOffset = spacing*sin(shearAngle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Add nodes to the yarns to describe their paths, these are the sheared node positions&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(spacing, shearOffset, height)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(2*spacing, 2*shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(0+shearOffset, spacing, height)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, 0)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(2*spacing+shearOffset, spacing+2*shearOffset, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(0, 0, height)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(shearOffset, spacing, 0)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(2*shearOffset, 2*spacing, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing, 0+shearOffset, 0)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, height)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+2*shearOffset, 2*spacing+shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
# Create a cross-section which twists along the length of the yarn to accommodate the sheared fabric architecture&lt;br /&gt;
ellipse = CSectionEllipse(0.18, 0.04)&lt;br /&gt;
sectionTwist1 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist1.AddSection(0.25, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
sectionTwist1.AddSection(0.75, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist2.AddSection(0.25, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2.AddSection(0.75, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
&lt;br /&gt;
for Yarn in (Yarns[1], Yarns[3]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist1)&lt;br /&gt;
for Yarn in (Yarns[0], Yarns[2]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist2)&lt;br /&gt;
&lt;br /&gt;
# Loop over all the yarns in the list&lt;br /&gt;
for Yarn in Yarns:&lt;br /&gt;
    # Set the resolution of the surface mesh created&lt;br /&gt;
    Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
    # Add repeat vectors to the yarn&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*spacing, 2*shearOffset, 0))&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*shearOffset, 2*spacing, 0))&lt;br /&gt;
&lt;br /&gt;
    # Add the yarn to our textile&lt;br /&gt;
    Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
# Create a sheared domain with 6 planes&lt;br /&gt;
domain = CDomainPlanes()&lt;br /&gt;
d = (2*spacing-2*shearOffset*sin(shearAngle))/sqrt(1+sin(shearAngle)**2)&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(1, -sin(shearAngle), 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-1, sin(shearAngle), 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-sin(shearAngle), 1, 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(sin(shearAngle), -1, 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, 1), -height))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, -1), -2*height))&lt;br /&gt;
Textile.AssignDomain(domain)&lt;br /&gt;
&lt;br /&gt;
# Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Saving to TG3 file format===&lt;br /&gt;
TexGen has it&amp;#039;s own file format for storing textile geometry with the extension .tg3. For more details on this file format please read the [[TG3 File Format]] page. Any textile models saved to this file format can be reloaded at a later time however it is also a good idea to keep the python script used to generate the geometry in case modifications need to be made. To save such a file it is simply a matter of adding an additional like at the end of your script like so:&lt;br /&gt;
&lt;br /&gt;
 SaveToXML(&amp;quot;MyTextile.tg3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The first parameter is the name of the file to save, note that if the .tg3 extension is omitted then it will automatically be appended for you. The second parameter is optional and if used should be the name of the textile to save, this is useful if you have several textiles loaded at once (i.e. you called AddTextile more than once) and you only want to save one of them. Note that if you don&amp;#039;t specify the second parameter and you do have several textiles loaded then it will save all of them to a single .tg3 file. The third parameter determines how much information is saved in the .tg3 file, see the [[TG3 File Format]] for more details.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Create Models</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-09T11:27:41Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Example 3: A 3d weave */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Example 1: A plain weave===&lt;br /&gt;
First of all, a Python script is just a plain ASCII text file with a .py extension. To create one simply open up your favorite text editor. Notepad will do if you have nothing else but I suggest a more powerful freeware text editor like [http://www.pspad.com/ PSPad] or [http://notepad-plus.sourceforge.net/ Notepad++]. Code that goes into the python script will be displayed like so:&lt;br /&gt;
&lt;br /&gt;
 # All Python code will be shown in a box like this one.&lt;br /&gt;
 # Lines begining with a &amp;#039;#&amp;#039; character are comments&lt;br /&gt;
&lt;br /&gt;
In this example, we will create a simple 2x2 plain weave model with a Python script. Its time to dive in and see some actual Python code. At this point if you are completely lost please refer back to the resources on Python programming. The first step is to create an instance of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class and give it a name, &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class takes 5 parameters in the order shown below:&lt;br /&gt;
* Number of weft yarns in the unit cell&lt;br /&gt;
* Number of warp yarns in the unit cell&lt;br /&gt;
* Spacing between the yarns&lt;br /&gt;
* Thickness of the fabrics&lt;br /&gt;
* Refine model (True/False)&lt;br /&gt;
&lt;br /&gt;
The only parameter that really needs an explanation here is the Refine model option, this controls whether or not the interference correction algorithm will be applied to keep the yarn volumes from intersecting which is a common problem. The interference correction algorithm generally does a good job but is not instantaneous so sometimes it can be beneficial to switch it off.&lt;br /&gt;
&lt;br /&gt;
This is the bare minimum information necessary to create a 2D woven fabric. In the following steps we will add more information to create the model the way we want it.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s set the weave pattern, this determines whether a warp or weft yarn will appear on top at a particular cross over. Cross overs are arranged in 2d grid where the size of the grid depends on the number of warp and weft yarns created. To swap the positions of the weft and warp yarns, we call the function &amp;lt;code&amp;gt;SwapPosition&amp;lt;/code&amp;gt; with the grid coordinates of the cross over. In order to create a plain weave we need to do this on two diagonally opposite cross overs like so:&lt;br /&gt;
&lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
&lt;br /&gt;
Now let&amp;#039;s add our &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt; model to the database of models so that TexGen can render it:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Thats it! This is a very simple script but it will generate a plain weave model. To recap your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
 &lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Save it to disk as &amp;#039;&amp;#039;PlainWeave.py&amp;#039;&amp;#039; or give it whatever name you want as long as it has a &amp;#039;&amp;#039;.py&amp;#039;&amp;#039; extension.&lt;br /&gt;
&lt;br /&gt;
In order to test the Script we need to load it into TexGen. So start up the TexGen GUI and from the &amp;#039;&amp;#039;Python menu&amp;#039;&amp;#039; select &amp;#039;&amp;#039;Run Script&amp;#039;&amp;#039;. Select the file you have just saved and click ok. With a bit of luck you should see a 2d plain weave on screen:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Congratulations you have created your first TexGen Python script!&lt;br /&gt;
&lt;br /&gt;
===Example 2: Another plain weave (the hard way)===&lt;br /&gt;
In the first example we made use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; which is the reason the script is so compact. This was great for creating a 2D Weave, but what if we want to create something other than a 2D Weave? Well, let&amp;#039;s stick to the 2D weave for now but in this example we will create geometric model in a generic way without the use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class. This takes a little bit longer to do, but gives more control over the final geometry.&lt;br /&gt;
&lt;br /&gt;
First we will define a general textile and call it &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextile&amp;lt;/code&amp;gt; class doesn&amp;#039;t take any parameters, instead yarns will be created and added to it. Next we will create 4 yarns to go inside our textile, it is convenient to make use of the Python lists to do this. Create a list called &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; with 4 elements, each one an instance of the class &amp;lt;code&amp;gt;CYarn&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; now contains 4 empty yarns. Note that the yarns are not currently associated with the Textile, first we must fill in the details then make them a part of the textile. The first thing to do is define their paths with nodes. This is done like so:&lt;br /&gt;
&lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
&lt;br /&gt;
We have added 3 nodes to each yarn creating a woven pattern. The number in the square brackets after &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; refers to a particular yarn in the list. The function &amp;lt;code&amp;gt;AddNode&amp;lt;/code&amp;gt; is then called for the yarn. The function takes an instance of the class &amp;lt;code&amp;gt;CNode&amp;lt;/code&amp;gt; which in turn is constructed with an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; representing the position of the node. The class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers representing the X, Y and Z coordinates of the point.&lt;br /&gt;
&lt;br /&gt;
We still need to define a few more things to obtain a model. For the sake of simplicity, we will give all the yarns the same cross sectional shape, width, height, etc... The easiest way to do this is to loop over the yarns and assign the same properties to each yarn one by one. The syntax for looping over &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
&lt;br /&gt;
Inside the loop, the variable &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; refers to the current yarn in the list. So within the loop we just assign properties to &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; and they will be applied to all the yarns in the list. In python the begining and end of a loop are defined by indentation, hence the following lines are indented to represent the contents of the loop.&lt;br /&gt;
&lt;br /&gt;
Let us define periodic cubic spline interpolation between the nodes:&lt;br /&gt;
&lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
&lt;br /&gt;
This is done with the function &amp;lt;code&amp;gt;AssignInterpolation&amp;lt;/code&amp;gt; which takes an instance of a class derived from &amp;lt;code&amp;gt;CInterpolation&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CInterpolationCubic&amp;lt;/code&amp;gt; to specify periodic cubic spline interpolation.&lt;br /&gt;
&lt;br /&gt;
Next we need to define a cross section for the yarn, to keep things simple a constant cross section all along the length of the yarn will be defined:&lt;br /&gt;
&lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignSection&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CYarnSection&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CYarnSectionConstant&amp;lt;/code&amp;gt; which in turns take an instance of a class derived from &amp;lt;code&amp;gt;CSection&amp;lt;/code&amp;gt; as a constructor. &amp;lt;code&amp;gt;CSectionEllipse&amp;lt;/code&amp;gt; defines an elliptical cross section with given width and height defined by the first and second parameters respectively.&lt;br /&gt;
&lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
This line sets the resolution of the surface mesh created. The first parameter to the function &amp;lt;code&amp;gt;SetResolution&amp;lt;/code&amp;gt; represents the number of points around a cross section. The number of points along the length of the yarns is automatically calculated such that the distance between points is similar to around the cross section.&lt;br /&gt;
&lt;br /&gt;
Next we must add repeat vectors to define how the yarns are repeated.&lt;br /&gt;
&lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AddRepeat&amp;lt;/code&amp;gt; takes an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;. As we saw earlier the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers defining the X, Y and Z components.&lt;br /&gt;
&lt;br /&gt;
Finally the yarn is fully defined, it can now be added to &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
This is the end of the loop, hence the following lines return to the original indentation. Now let&amp;#039;s define a Domain within which the textile will be placed:&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignDomain&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CDomain&amp;lt;/code&amp;gt;. In this case we will create a box shaped domain, this can be accomplished by using the class &amp;lt;code&amp;gt;CDomainPlanes&amp;lt;/code&amp;gt;. A box can be created by passing in opposite corners of the box (the minimum and maximum coordinates). This is done again with the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And finally &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt; must be added to so that it can be rendered. Each Textile added must be assigned a name to identify it, this is the name that will appear at the top in the TexGen GUI. This name can either be generated automatically or we can specify it explicitly like so:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! You now have the knowledge to create any type of fabric imaginable. Well, almost. The model created here is pretty simple, there is plenty of oppertunity to create more complex shapes. For example non-constant cross sections can be defined, complex domain shapes defined by arbritrary planes, different interpolation functions.&lt;br /&gt;
&lt;br /&gt;
Here is the completed script:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
 &lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
 &lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
 &lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
 &lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
 &lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
 &lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
 &lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create a domain and assign it to the textile&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example2.png]]&lt;br /&gt;
&lt;br /&gt;
===Example 3: A 3d weave===&lt;br /&gt;
This example is similar to the [[Scripting Create Models#Example 2: Another plain weave (the hard way)|Example 2]] in that the yarns will be defined by nodes. This time we will create a 3d woven fabric that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example3.png]]&lt;br /&gt;
&lt;br /&gt;
We start by defining a new CTextile instance:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
Before starting to define the geometry using TexGen it is helpful to define a list of parameters which may need to be changed later. These typically include spacing between yarns and yarn dimensions:&lt;br /&gt;
&lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
&lt;br /&gt;
It is a good idea to define these up front rather than hard coding them in the rest of the script because if you want to tweak any parameters they can easily be located and will only need to be changed once. Lets start by defining the warp stuffer yarns, these are fairly easy to define since they all straight and parallel to each other:&lt;br /&gt;
&lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Next we define the weft stuffer yarns, again these are easy to define:&lt;br /&gt;
&lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
And finally we need to insert the binder yarns. Making clever use of the repeat vectors it is only necessary to define a single instance of the binder yarn.&lt;br /&gt;
&lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Now that the geometry is defined we shall define a domain and add the textile so that TexGen knows about it.&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
The completed scripts is shown below:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
 &lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
===Example 4: A sheared plain weave===&lt;br /&gt;
This example builds on [[Scripting Guide#Example 2: Another plain weave (the hard way)|Example 2]], except this time we will be modelling a sheared unit cell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
from math import *&lt;br /&gt;
&lt;br /&gt;
# Create a textile&lt;br /&gt;
Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a python list containing 4 yarns&lt;br /&gt;
Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
# Define some constants that will be used in further calculations&lt;br /&gt;
spacing = 0.22&lt;br /&gt;
height = 0.05&lt;br /&gt;
&lt;br /&gt;
shearAngle = pi/32&lt;br /&gt;
twistAngle = shearAngle&lt;br /&gt;
&lt;br /&gt;
shearOffset = spacing*sin(shearAngle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Add nodes to the yarns to describe their paths, these are the sheared node positions&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(spacing, shearOffset, height)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(2*spacing, 2*shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(0+shearOffset, spacing, height)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, 0)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(2*spacing+shearOffset, spacing+2*shearOffset, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(0, 0, height)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(shearOffset, spacing, 0)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(2*shearOffset, 2*spacing, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing, 0+shearOffset, 0)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, height)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+2*shearOffset, 2*spacing+shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
# Create a cross-section which twists along the length of the yarn to accommodate the sheared fabric architecture&lt;br /&gt;
ellipse = CSectionEllipse(0.18, 0.04)&lt;br /&gt;
sectionTwist1 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist1.AddSection(0.25, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
sectionTwist1.AddSection(0.75, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist2.AddSection(0.25, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2.AddSection(0.75, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
&lt;br /&gt;
for Yarn in (Yarns[1], Yarns[3]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist1)&lt;br /&gt;
for Yarn in (Yarns[0], Yarns[2]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist2)&lt;br /&gt;
&lt;br /&gt;
# Loop over all the yarns in the list&lt;br /&gt;
for Yarn in Yarns:&lt;br /&gt;
    # Set the resolution of the surface mesh created&lt;br /&gt;
    Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
    # Add repeat vectors to the yarn&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*spacing, 2*shearOffset, 0))&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*shearOffset, 2*spacing, 0))&lt;br /&gt;
&lt;br /&gt;
    # Add the yarn to our textile&lt;br /&gt;
    Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
# Create a sheared domain with 6 planes&lt;br /&gt;
domain = CDomainPlanes()&lt;br /&gt;
d = (2*spacing-2*shearOffset*sin(shearAngle))/sqrt(1+sin(shearAngle)**2)&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(1, -sin(shearAngle), 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-1, sin(shearAngle), 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-sin(shearAngle), 1, 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(sin(shearAngle), -1, 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, 1), -height))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, -1), -2*height))&lt;br /&gt;
Textile.AssignDomain(domain)&lt;br /&gt;
&lt;br /&gt;
# Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Saving to TG3 file format===&lt;br /&gt;
TexGen has it&amp;#039;s own file format for storing textile geometry with the extension .tg3. For more details on this file format please read the [[TG3 File Format]] page. Any textile models saved to this file format can be reloaded at a later time however it is also a good idea to keep the python script used to generate the geometry in case modifications need to be made. To save such a file it is simply a matter of adding an additional like at the end of your script like so:&lt;br /&gt;
&lt;br /&gt;
 SaveToXML(&amp;quot;MyTextile.tg3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The first parameter is the name of the file to save, note that if the .tg3 extension is omitted then it will automatically be appended for you. The second parameter is optional and if used should be the name of the textile to save, this is useful if you have several textiles loaded at once (i.e. you called AddTextile more than once) and you only want to save one of them. Note that if you don&amp;#039;t specify the second parameter and you do have several textiles loaded then it will save all of them to a single .tg3 file. The third parameter determines how much information is saved in the .tg3 file, see the [[TG3 File Format]] for more details.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Create Models</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-09T11:26:45Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Example 1: A plain weave===&lt;br /&gt;
First of all, a Python script is just a plain ASCII text file with a .py extension. To create one simply open up your favorite text editor. Notepad will do if you have nothing else but I suggest a more powerful freeware text editor like [http://www.pspad.com/ PSPad] or [http://notepad-plus.sourceforge.net/ Notepad++]. Code that goes into the python script will be displayed like so:&lt;br /&gt;
&lt;br /&gt;
 # All Python code will be shown in a box like this one.&lt;br /&gt;
 # Lines begining with a &amp;#039;#&amp;#039; character are comments&lt;br /&gt;
&lt;br /&gt;
In this example, we will create a simple 2x2 plain weave model with a Python script. Its time to dive in and see some actual Python code. At this point if you are completely lost please refer back to the resources on Python programming. The first step is to create an instance of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class and give it a name, &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class takes 5 parameters in the order shown below:&lt;br /&gt;
* Number of weft yarns in the unit cell&lt;br /&gt;
* Number of warp yarns in the unit cell&lt;br /&gt;
* Spacing between the yarns&lt;br /&gt;
* Thickness of the fabrics&lt;br /&gt;
* Refine model (True/False)&lt;br /&gt;
&lt;br /&gt;
The only parameter that really needs an explanation here is the Refine model option, this controls whether or not the interference correction algorithm will be applied to keep the yarn volumes from intersecting which is a common problem. The interference correction algorithm generally does a good job but is not instantaneous so sometimes it can be beneficial to switch it off.&lt;br /&gt;
&lt;br /&gt;
This is the bare minimum information necessary to create a 2D woven fabric. In the following steps we will add more information to create the model the way we want it.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s set the weave pattern, this determines whether a warp or weft yarn will appear on top at a particular cross over. Cross overs are arranged in 2d grid where the size of the grid depends on the number of warp and weft yarns created. To swap the positions of the weft and warp yarns, we call the function &amp;lt;code&amp;gt;SwapPosition&amp;lt;/code&amp;gt; with the grid coordinates of the cross over. In order to create a plain weave we need to do this on two diagonally opposite cross overs like so:&lt;br /&gt;
&lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
&lt;br /&gt;
Now let&amp;#039;s add our &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt; model to the database of models so that TexGen can render it:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Thats it! This is a very simple script but it will generate a plain weave model. To recap your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
 &lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Save it to disk as &amp;#039;&amp;#039;PlainWeave.py&amp;#039;&amp;#039; or give it whatever name you want as long as it has a &amp;#039;&amp;#039;.py&amp;#039;&amp;#039; extension.&lt;br /&gt;
&lt;br /&gt;
In order to test the Script we need to load it into TexGen. So start up the TexGen GUI and from the &amp;#039;&amp;#039;Python menu&amp;#039;&amp;#039; select &amp;#039;&amp;#039;Run Script&amp;#039;&amp;#039;. Select the file you have just saved and click ok. With a bit of luck you should see a 2d plain weave on screen:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Congratulations you have created your first TexGen Python script!&lt;br /&gt;
&lt;br /&gt;
===Example 2: Another plain weave (the hard way)===&lt;br /&gt;
In the first example we made use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; which is the reason the script is so compact. This was great for creating a 2D Weave, but what if we want to create something other than a 2D Weave? Well, let&amp;#039;s stick to the 2D weave for now but in this example we will create geometric model in a generic way without the use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class. This takes a little bit longer to do, but gives more control over the final geometry.&lt;br /&gt;
&lt;br /&gt;
First we will define a general textile and call it &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextile&amp;lt;/code&amp;gt; class doesn&amp;#039;t take any parameters, instead yarns will be created and added to it. Next we will create 4 yarns to go inside our textile, it is convenient to make use of the Python lists to do this. Create a list called &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; with 4 elements, each one an instance of the class &amp;lt;code&amp;gt;CYarn&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; now contains 4 empty yarns. Note that the yarns are not currently associated with the Textile, first we must fill in the details then make them a part of the textile. The first thing to do is define their paths with nodes. This is done like so:&lt;br /&gt;
&lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
&lt;br /&gt;
We have added 3 nodes to each yarn creating a woven pattern. The number in the square brackets after &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; refers to a particular yarn in the list. The function &amp;lt;code&amp;gt;AddNode&amp;lt;/code&amp;gt; is then called for the yarn. The function takes an instance of the class &amp;lt;code&amp;gt;CNode&amp;lt;/code&amp;gt; which in turn is constructed with an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; representing the position of the node. The class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers representing the X, Y and Z coordinates of the point.&lt;br /&gt;
&lt;br /&gt;
We still need to define a few more things to obtain a model. For the sake of simplicity, we will give all the yarns the same cross sectional shape, width, height, etc... The easiest way to do this is to loop over the yarns and assign the same properties to each yarn one by one. The syntax for looping over &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
&lt;br /&gt;
Inside the loop, the variable &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; refers to the current yarn in the list. So within the loop we just assign properties to &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; and they will be applied to all the yarns in the list. In python the begining and end of a loop are defined by indentation, hence the following lines are indented to represent the contents of the loop.&lt;br /&gt;
&lt;br /&gt;
Let us define periodic cubic spline interpolation between the nodes:&lt;br /&gt;
&lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
&lt;br /&gt;
This is done with the function &amp;lt;code&amp;gt;AssignInterpolation&amp;lt;/code&amp;gt; which takes an instance of a class derived from &amp;lt;code&amp;gt;CInterpolation&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CInterpolationCubic&amp;lt;/code&amp;gt; to specify periodic cubic spline interpolation.&lt;br /&gt;
&lt;br /&gt;
Next we need to define a cross section for the yarn, to keep things simple a constant cross section all along the length of the yarn will be defined:&lt;br /&gt;
&lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignSection&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CYarnSection&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CYarnSectionConstant&amp;lt;/code&amp;gt; which in turns take an instance of a class derived from &amp;lt;code&amp;gt;CSection&amp;lt;/code&amp;gt; as a constructor. &amp;lt;code&amp;gt;CSectionEllipse&amp;lt;/code&amp;gt; defines an elliptical cross section with given width and height defined by the first and second parameters respectively.&lt;br /&gt;
&lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
This line sets the resolution of the surface mesh created. The first parameter to the function &amp;lt;code&amp;gt;SetResolution&amp;lt;/code&amp;gt; represents the number of points around a cross section. The number of points along the length of the yarns is automatically calculated such that the distance between points is similar to around the cross section.&lt;br /&gt;
&lt;br /&gt;
Next we must add repeat vectors to define how the yarns are repeated.&lt;br /&gt;
&lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AddRepeat&amp;lt;/code&amp;gt; takes an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;. As we saw earlier the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers defining the X, Y and Z components.&lt;br /&gt;
&lt;br /&gt;
Finally the yarn is fully defined, it can now be added to &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
This is the end of the loop, hence the following lines return to the original indentation. Now let&amp;#039;s define a Domain within which the textile will be placed:&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignDomain&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CDomain&amp;lt;/code&amp;gt;. In this case we will create a box shaped domain, this can be accomplished by using the class &amp;lt;code&amp;gt;CDomainPlanes&amp;lt;/code&amp;gt;. A box can be created by passing in opposite corners of the box (the minimum and maximum coordinates). This is done again with the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And finally &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt; must be added to so that it can be rendered. Each Textile added must be assigned a name to identify it, this is the name that will appear at the top in the TexGen GUI. This name can either be generated automatically or we can specify it explicitly like so:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! You now have the knowledge to create any type of fabric imaginable. Well, almost. The model created here is pretty simple, there is plenty of oppertunity to create more complex shapes. For example non-constant cross sections can be defined, complex domain shapes defined by arbritrary planes, different interpolation functions.&lt;br /&gt;
&lt;br /&gt;
Here is the completed script:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
 &lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
 &lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
 &lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
 &lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
 &lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
 &lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
 &lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create a domain and assign it to the textile&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example2.png]]&lt;br /&gt;
&lt;br /&gt;
===Example 3: A 3d weave===&lt;br /&gt;
This example is similar to the [[Scripting Guide#Example 2: Another plain weave (the hard way)|Example 2]] in that the yarns will be defined by nodes. This time we will create a 3d woven fabric that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example3.png]]&lt;br /&gt;
&lt;br /&gt;
We start by defining a new CTextile instance:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
Before starting to define the geometry using TexGen it is helpful to define a list of parameters which may need to be changed later. These typically include spacing between yarns and yarn dimensions:&lt;br /&gt;
&lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
&lt;br /&gt;
It is a good idea to define these up front rather than hard coding them in the rest of the script because if you want to tweak any parameters they can easily be located and will only need to be changed once. Lets start by defining the warp stuffer yarns, these are fairly easy to define since they all straight and parallel to each other:&lt;br /&gt;
&lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Next we define the weft stuffer yarns, again these are easy to define:&lt;br /&gt;
&lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
And finally we need to insert the binder yarns. Making clever use of the repeat vectors it is only necessary to define a single instance of the binder yarn.&lt;br /&gt;
&lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Now that the geometry is defined we shall define a domain and add the textile so that TexGen knows about it.&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
The completed scripts is shown below:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
 &lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
===Example 4: A sheared plain weave===&lt;br /&gt;
This example builds on [[Scripting Guide#Example 2: Another plain weave (the hard way)|Example 2]], except this time we will be modelling a sheared unit cell.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
from math import *&lt;br /&gt;
&lt;br /&gt;
# Create a textile&lt;br /&gt;
Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a python list containing 4 yarns&lt;br /&gt;
Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
# Define some constants that will be used in further calculations&lt;br /&gt;
spacing = 0.22&lt;br /&gt;
height = 0.05&lt;br /&gt;
&lt;br /&gt;
shearAngle = pi/32&lt;br /&gt;
twistAngle = shearAngle&lt;br /&gt;
&lt;br /&gt;
shearOffset = spacing*sin(shearAngle)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Add nodes to the yarns to describe their paths, these are the sheared node positions&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(spacing, shearOffset, height)))&lt;br /&gt;
Yarns[0].AddNode(CNode(XYZ(2*spacing, 2*shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(0+shearOffset, spacing, height)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, 0)))&lt;br /&gt;
Yarns[1].AddNode(CNode(XYZ(2*spacing+shearOffset, spacing+2*shearOffset, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(0, 0, height)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(shearOffset, spacing, 0)))&lt;br /&gt;
Yarns[2].AddNode(CNode(XYZ(2*shearOffset, 2*spacing, height)))&lt;br /&gt;
&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing, 0+shearOffset, 0)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+shearOffset, spacing+shearOffset, height)))&lt;br /&gt;
Yarns[3].AddNode(CNode(XYZ(spacing+2*shearOffset, 2*spacing+shearOffset, 0)))&lt;br /&gt;
&lt;br /&gt;
# Create a cross-section which twists along the length of the yarn to accommodate the sheared fabric architecture&lt;br /&gt;
ellipse = CSectionEllipse(0.18, 0.04)&lt;br /&gt;
sectionTwist1 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist1.AddSection(0.25, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
sectionTwist1.AddSection(0.75, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2 = CYarnSectionInterpPosition()&lt;br /&gt;
sectionTwist2.AddSection(0.25, CSectionRotated(ellipse, twistAngle))&lt;br /&gt;
sectionTwist2.AddSection(0.75, CSectionRotated(ellipse, -twistAngle))&lt;br /&gt;
&lt;br /&gt;
for Yarn in (Yarns[1], Yarns[3]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist1)&lt;br /&gt;
for Yarn in (Yarns[0], Yarns[2]):&lt;br /&gt;
    Yarn.AssignSection(sectionTwist2)&lt;br /&gt;
&lt;br /&gt;
# Loop over all the yarns in the list&lt;br /&gt;
for Yarn in Yarns:&lt;br /&gt;
    # Set the resolution of the surface mesh created&lt;br /&gt;
    Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
    # Add repeat vectors to the yarn&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*spacing, 2*shearOffset, 0))&lt;br /&gt;
    Yarn.AddRepeat(XYZ(2*shearOffset, 2*spacing, 0))&lt;br /&gt;
&lt;br /&gt;
    # Add the yarn to our textile&lt;br /&gt;
    Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
# Create a sheared domain with 6 planes&lt;br /&gt;
domain = CDomainPlanes()&lt;br /&gt;
d = (2*spacing-2*shearOffset*sin(shearAngle))/sqrt(1+sin(shearAngle)**2)&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(1, -sin(shearAngle), 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-1, sin(shearAngle), 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(-sin(shearAngle), 1, 0), 0))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(sin(shearAngle), -1, 0), -d))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, 1), -height))&lt;br /&gt;
domain.AddPlane(PLANE(XYZ(0, 0, -1), -2*height))&lt;br /&gt;
Textile.AssignDomain(domain)&lt;br /&gt;
&lt;br /&gt;
# Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Saving to TG3 file format===&lt;br /&gt;
TexGen has it&amp;#039;s own file format for storing textile geometry with the extension .tg3. For more details on this file format please read the [[TG3 File Format]] page. Any textile models saved to this file format can be reloaded at a later time however it is also a good idea to keep the python script used to generate the geometry in case modifications need to be made. To save such a file it is simply a matter of adding an additional like at the end of your script like so:&lt;br /&gt;
&lt;br /&gt;
 SaveToXML(&amp;quot;MyTextile.tg3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The first parameter is the name of the file to save, note that if the .tg3 extension is omitted then it will automatically be appended for you. The second parameter is optional and if used should be the name of the textile to save, this is useful if you have several textiles loaded at once (i.e. you called AddTextile more than once) and you only want to save one of them. Note that if you don&amp;#039;t specify the second parameter and you do have several textiles loaded then it will save all of them to a single .tg3 file. The third parameter determines how much information is saved in the .tg3 file, see the [[TG3 File Format]] for more details.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Compiling from Source</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-02T15:07:10Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Configuring optional modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In order to compile TexGen and &amp;#039;&amp;#039;&amp;#039;all&amp;#039;&amp;#039;&amp;#039; of its modules, the following software is required:&lt;br /&gt;
&lt;br /&gt;
The following programs are needed to build TexGen:&lt;br /&gt;
* [http://www.cmake.org/ CMake]&lt;br /&gt;
* [http://www.swig.org/ SWIG]&lt;br /&gt;
&lt;br /&gt;
The following libraries are needed to link to TexGen:&lt;br /&gt;
* [http://www.vtk.org/ VTK]&lt;br /&gt;
* [http://www.wxwidgets.org/ wxWidgets]&lt;br /&gt;
* [http://www.opencascade.org/ OpenCascade]&lt;br /&gt;
* [http://www.python.org/ Python]&lt;br /&gt;
&lt;br /&gt;
However to perform a minimum build of TexGen with none of the additional modules you only require CMake and a C++ compiler. It is recommended to begin with a minimum build, once that is working try adding modules one at a time. A list of modules along with dependencies is shown below:&lt;br /&gt;
&lt;br /&gt;
* Python interface: Python, SWIG&lt;br /&gt;
* Renderer: VTK&lt;br /&gt;
* Export: OpenCascade&lt;br /&gt;
* GUI: wxWidgets, Renderer, Python interface&lt;br /&gt;
* Unit tests: CPPUnit&lt;br /&gt;
&lt;br /&gt;
A graphical representation of the modules and their dependencies can also be found in the [http://texgen.sourceforge.net/api/ TexGen API].&lt;br /&gt;
&lt;br /&gt;
If you want to get the source code from the Subversion repository you will need to install [http://subversion.tigris.org/ Subversion] by following the instructions below. Note that this is the very latest development source and so may it contain some bugs and unfinished features. However it is very easy to keep up to date with the latest version of TexGen using this method and will allow you to keep any modifications you have made to the source when updating. If you find a bug or implement new features that may be usefull to the rest of the community they can also be submited as patch and incorporated into TexGen following review.&lt;br /&gt;
&lt;br /&gt;
Alternatively the stable source code can be downloaded as a [http://sourceforge.net/project/showfiles.php?group_id=181000 tarball]. Download the latest file release named &amp;#039;&amp;#039;texgen-3.x.x.tar.gz&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Windows (Microsoft Visual Studio C++, recommended method) ==&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
It is assumed that Microsoft Visual Studio is already installed.  If it isn&amp;#039;t and you plan to use it, then install it.  It may be possible to use the free [http://www.microsoft.com/express/ Visual Studio Express]; if anyone tries this and finds out one way or the other, please post the information either here or in the [http://texgen.sourceforge.net/phpBB2/index.php forum]. Brief instructions on how to install the various 3rd party libraries under windows are given below. Note that you do not need to install all of these in order to perform the minimal build. Only CMake is absolutely required.&lt;br /&gt;
&lt;br /&gt;
==== CMake ====&lt;br /&gt;
&lt;br /&gt;
[http://www.cmake.org/HTML/Download.html Download CMake] and install, selecting &amp;#039;Add CMake to the system PATH for all users&amp;#039; (select current user if this is not permissible on your system).&lt;br /&gt;
&lt;br /&gt;
==== TortoiseSVN ====&lt;br /&gt;
&lt;br /&gt;
[http://tortoisesvn.net/downloads Download TortoiseSVN] and install it.&lt;br /&gt;
&lt;br /&gt;
==== SWIG ====&lt;br /&gt;
&lt;br /&gt;
[http://www.swig.org/ Download] the latest release of the windows .zip files and extract to a suitable location (e.g. c:\Program Files\swigwin-1.3.31).&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
[http://www.python.org/ Download Python] and install.&lt;br /&gt;
&lt;br /&gt;
==== OpenCascade ====&lt;br /&gt;
&lt;br /&gt;
[http://www.opencascade.org/getocc/download/ Download OpenCascade] and install; this extracts the files to a directory. If the installation doesn&amp;#039;t start automatically, run the &amp;#039;install.bat&amp;#039; file located the directory where the files where extracted (read &amp;#039;readme.htm&amp;#039; file in the same directory for more information).  Choose &amp;#039;complete installation&amp;#039; and tick the box to set the environment variables.&lt;br /&gt;
&lt;br /&gt;
==== VTK ====&lt;br /&gt;
&lt;br /&gt;
[http://www.vtk.org/get-software.php Download] the latest source files and extract them. Follow the instructions in &amp;#039;README.html&amp;#039; found in the extracted directory to compile VTK using CMake. The following CMake settings should be set:&lt;br /&gt;
&lt;br /&gt;
 BUILD_EXAMPLES           OFF&lt;br /&gt;
 BUILD_SHARED_LIBS        OFF&lt;br /&gt;
 VTK_USE_MPEG2_ENCODER    OFF&lt;br /&gt;
 VTK_USE_PARALLEL         OFF&lt;br /&gt;
 VTK_USE_RENDERING        ON&lt;br /&gt;
 VTK_WRAP_JAVA            OFF&lt;br /&gt;
 VTK_WRAP_PYTHON          OFF&lt;br /&gt;
 VTK_WRAP_TCL             OFF&lt;br /&gt;
&lt;br /&gt;
You may be able to get things working with different settings, however these are the settings I use and are known to work.&lt;br /&gt;
&lt;br /&gt;
==== wxWidgets ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wxwidgets.org/downloads/ Download] and install the windows version of wxWidgets (wxMSW). It is then necessary to compile wxWidgets from source, detailed instructions on how to do this can be found in &amp;#039;install.txt&amp;#039; located in the &amp;#039;docs\msw&amp;#039; subfolder. The main steps are to open &amp;#039;wx.dsw&amp;#039; with MSVC located in the &amp;#039;build\msw&amp;#039; subfolder and compile both Release and Debug configurations (The configuration can be selected from the drop down box on the main toolbar in Visual Studio. Universal, Unicode and DLL versions need not be compiled).&lt;br /&gt;
&lt;br /&gt;
=== Checkout TexGen source code from subversion server ===&lt;br /&gt;
Create a directory where you would like to store the TexGen source code in Windows Explorer. Right click on this folder and select &amp;#039;SVN Checkout...&amp;#039; from the context menu that appears. In the dialog box which follows, enter &amp;#039;https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/&amp;#039; in the URL field. The Checkout directory field should have been filled in automatically. Click on OK to start downloading the TexGen source code. In future the latest version of the source code can be obtained simply by right clicking on the folder and selecting &amp;#039;SVN Update&amp;#039; from the context menu.&lt;br /&gt;
&lt;br /&gt;
=== Configuring the build system with CMake ===&lt;br /&gt;
Run CMake from its shortcut on the Start menu. There are some general instructions on using CMake on the [http://www.cmake.org/HTML/RunningCMake.html CMake website] which are worth reading. You will need to fill in the source code location, this should point to where you checkout out the latest TexGen SVN code or where you extracted the source code from the zip file. Also set where to place the binary files once they are compiled, this can be the same as the source directory, a subdirectory within the source directory or any other location.&lt;br /&gt;
&lt;br /&gt;
Once that is entered click &amp;#039;Configure&amp;#039; and choose the Visual Studio version which you have installed and click ok. You will initially get a number of error messages such as:&lt;br /&gt;
&lt;br /&gt;
 CMake Error: Swig was not found on the system. Please specify the location of Swig. (click OK)&lt;br /&gt;
 CMake Error: Error in configuration process, project files may be invalid. (click OK)&lt;br /&gt;
&lt;br /&gt;
This is normal, in order to get rid of the errors you will need to tell CMake where the various libraries you have installed can be found. This is done in the Cache Values sections.&lt;br /&gt;
&lt;br /&gt;
It is recommended to begin with a minimal build, this is achieved by setting the cache values as follows:&lt;br /&gt;
&lt;br /&gt;
 BUILD_CASCADE_EXPORT           OFF&lt;br /&gt;
 BUILD_DOCUMENTATION            OFF&lt;br /&gt;
 BUILD_EXAMPLES                 OFF&lt;br /&gt;
 BUILD_GUI                      OFF&lt;br /&gt;
 BUILD_PYTHON_INTERFACE         OFF&lt;br /&gt;
 BUILD_RENDERER                 OFF&lt;br /&gt;
 BUILD_SHARED                   ON&lt;br /&gt;
 BUILD_UNIT_TESTS               OFF&lt;br /&gt;
&lt;br /&gt;
Once these are set press configure again and you shouldn&amp;#039;t have any more errors/warnings. Press &amp;#039;OK&amp;#039; to generate the MSVC solution and project files. Configuring the various optional modules is explained in [[#Configuring optional modules]].&lt;br /&gt;
&lt;br /&gt;
=== Configuring optional modules ===&lt;br /&gt;
&lt;br /&gt;
Once the minimal build is working you may want to switch on the optional modules. To do this open up CMake again and switch the modules you want to ON in the Cache Values then click Configure. You will most likely see some errors telling you it is unable to automatically find certain directories. You will need to specify these manually. An explanation of the different locations is listed below:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PYTHON_SITEPACKAGES_DIR&amp;#039;&amp;#039;&amp;#039; - This should be the folder where the TexGen python modules will be placed. Usually located in &amp;#039;C:\Python25\Lib\site-packages&amp;#039;, but this will depend on the version of Python installed and where you decided to install it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SWIG_DIR&amp;#039;&amp;#039;&amp;#039; -  This is the location where you extracted the SWIG executable. e.g. &amp;#039;C:\Program Files\swigwin-1.3.35&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SWIG_EXECUTABLE&amp;#039;&amp;#039;&amp;#039; - Same as root directory followed by &amp;#039;swig.exe&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wxWidgets_ROOT_DIR&amp;#039;&amp;#039;&amp;#039; - Location where you install wxWidgets. e.g. &amp;#039;C:/wxWidgets-2.8.7&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wxWidgets_LIB_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the wxWidgets libraries were compiled to, should be the same as the root directory followed by &amp;#039;lib\vc_lib&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_INCLUDE_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade header files are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/inc&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_LIBRARY_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade libraries are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/win32/lib&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_DEBUG_LIBRARY_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade debug libraries are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/win32/libd&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;VTK_DIR&amp;#039;&amp;#039;&amp;#039; - Location of the VTK binary directory (note: not the source directory).&lt;br /&gt;
&lt;br /&gt;
After setting the directories manually, click on configure again. You may need to go through several iterations of changing parameters then pressing configure. Once you have finished changing parameters and have successfully pressed configure without error messages you can press the OK button to generate the build. Note: you can always come back to this at a later time to make changes.&lt;br /&gt;
&lt;br /&gt;
=== Compiling ===&lt;br /&gt;
&lt;br /&gt;
Find &amp;#039;TexGen.sln&amp;#039; which should be located in the directory where you told CMake to output the binary files to and open it with Microsoft Visual Studio.&lt;br /&gt;
&lt;br /&gt;
Set the configuration to &amp;#039;Release&amp;#039; and build the solution. Hopefully the project will have been compiled without errors.&lt;br /&gt;
&lt;br /&gt;
If you want to compile and execute the Graphical User Interface you will need to install it, you will not be able to execute it directly from the build directory. This is done by right click on the &amp;#039;INSTALL&amp;#039; project in the Solution Explorer and selecting Build. This will copy the Python modules into the Python site-packages directory so that they can be imported into scripts, and it will copy the executable along with other necessary files into &amp;#039;C:\Program Files\TexGen\&amp;#039; by default (this can be changed with the CMAKE_INSTALL_PREFIX cache value in CMake). TexGenGUI.exe should then be run from the installed location, if you attempt to run it directly from where it was compiled you will get some errors on launch.&lt;br /&gt;
&lt;br /&gt;
=== Building the documentation ===&lt;br /&gt;
&lt;br /&gt;
To build the documentation, [http://www.stack.nl/~dimitri/doxygen/download.html Doxygen] is required.  Open a command prompt in the &amp;#039;Docs&amp;#039; subdirectory of the source code and run &amp;#039;doxygen&amp;#039;. If the doxygen directory is not in your path, you must add it, or give the full path on the command line.&lt;br /&gt;
&lt;br /&gt;
=== Integrating TexGen with ABAQUS ===&lt;br /&gt;
&lt;br /&gt;
If you are using ABAQUS and wish to use TexGen Python scripting from within the ABAQUS/CAE environment, there are a few extra steps to perform. This is because ABAQUS comes packaged with its own version of Python, so any modules added to your standalone python installation will not be accessible by ABAQUS. You must compile the TexGen Python modules with the same version of Python as ABAQUS uses. The following table shows which version of Python is used in specific ABAQUS versions:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! ABAQUS Version !! Python Version&lt;br /&gt;
|-&lt;br /&gt;
| 6.6-1 || 2.3.3&lt;br /&gt;
|- &lt;br /&gt;
| 6.7-1 || 2.4.3 &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If your version of ABAQUS is not listed in the table above you can type &amp;#039;abaqus python -V&amp;#039; to check what version of Python is used (then please edit this page to update the table). You can obtain specific versions of Python from http://www.python.org/download/releases/x.y.z/ where x.y.z represents the version number.&lt;br /&gt;
&lt;br /&gt;
Additionally you will need to place the TexGen python modules inside ABAQUS&amp;#039; version of python. There are a few ways to accomplish this, the easiest is perhaps to set the CMake cache variable &amp;#039;PYTHON_SITEPACKAGES_DIR&amp;#039; point to the ABAQUS&amp;#039; python directory, e.g.:&lt;br /&gt;
&lt;br /&gt;
 PYTHON_SITEPACKAGES_DIR     C:\Abaqus\6.7-1\Python\Lib\&lt;br /&gt;
&lt;br /&gt;
Then when you build the INSTALL project in MSVC++ it will automatically copy the TexGen python modules to the ABAQUS&amp;#039; Python. Alternatively you can simply copy the files manually or modify Python&amp;#039;s search path to include the TexGen python modules, e.g. In python:&lt;br /&gt;
&lt;br /&gt;
 import sys&lt;br /&gt;
 sys.path.append(&amp;#039;C:/Python24/Lib/site-packages/&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when compiling:&lt;br /&gt;
 fatal error LNK1104: cannot open file &amp;#039;python25_d.lib&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; The windows installation of Python doesn&amp;#039;t come with the debug library (&amp;#039;python25_d.lib&amp;#039;, the _d part means debug). You should be able to compile in release mode however. If you really want to compile in debug mode you will need to compile Python from source and link to that. Or you can try to link to the release library &amp;#039;python25.lib&amp;#039; instead, easiest way to do that is to copy &amp;#039;python25.lib&amp;#039; to &amp;#039;python25_d.lib&amp;#039; but this may cause problems during linking or execution.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when compiling:&lt;br /&gt;
 fatal error C1083: Cannot open include file: &amp;#039;wx/wxprec.h&amp;#039;: No such file or directory&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; Make sure that you have compiled wxWidgets and that the wxWidgets_XXX cache variables are set correctly in CMake.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I do not have a &amp;#039;libd&amp;#039; folder in &amp;#039;ros/win32&amp;#039; for OpenCASCADE.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; If you do not compile OpenCASCADE yourself then this folder does not exist. However it can be ignored if you are only interested in building the release version of TexGen. If you really want to compile the debug version please refer to the OpenCASCADE documentation.&lt;br /&gt;
&lt;br /&gt;
== Windows (Cygwin and gcc, alternate method) ==&lt;br /&gt;
A limited build (without graphics) can be made under cygwin, this is a UNIX emulation environment available at [http://www.cygwin.com www.cygwin.com]. &lt;br /&gt;
This can exist peacefully next to the native windows version. &lt;br /&gt;
Cygwin creates a unix-style file system within your windows installation. If you choose c:/cygwin as your install directory, your HOME will be at c:/cygwin/home/&amp;lt;username&amp;gt;/. &lt;br /&gt;
&lt;br /&gt;
=== Download cygwin and install packages ===&lt;br /&gt;
Install gcc, g++, wget, make and cmake using the setup.exe program from the cygwin website. &lt;br /&gt;
For the mesh generator and python interface to work we currently need VTK and swig. &lt;br /&gt;
&lt;br /&gt;
This downloads and installs swig from source (when starting the cygwin shell you can paste this into the command line, otherwise write it to a file and run it with sh). &lt;br /&gt;
 mkdir progs&lt;br /&gt;
 cd progs &lt;br /&gt;
 SWIG=swig-1.3.31&lt;br /&gt;
 wget -nc http://kent.dl.sourceforge.net/sourceforge/swig/$SWIG.tar.gz&lt;br /&gt;
 tar xzvf $SWIG.tar.gz &lt;br /&gt;
 cd $SWIG&lt;br /&gt;
 ./configure &lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
This downloads and installs VTK from source, in the ccmake stage, use the cmake graphical commands to get a working install. &lt;br /&gt;
 VTK=vtk-5.0.3&lt;br /&gt;
 wget -nc http://www.vtk.org/files/release/5.0/$VTK.tar.gz&lt;br /&gt;
 tar xzvf $VTK.tar.gz&lt;br /&gt;
 mkdir vtkbin&lt;br /&gt;
 cd vtkbin&lt;br /&gt;
 ccmake ../VTK&lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== Install TexGen from source ===&lt;br /&gt;
Now we can proceed to install texgen, as an example we&amp;#039;ll work in ~/temp/texgen&lt;br /&gt;
 cd ~; mkdir temp; cd temp; mkdir texgen; cd texgen&lt;br /&gt;
 svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen&lt;br /&gt;
 cd .. ; mkdir tbin; cd tbin&lt;br /&gt;
 ccmake ../texgen&lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
This should result in a working texgen install in ~/temp/texgen/tbin.&lt;br /&gt;
&lt;br /&gt;
== Unix ==&lt;br /&gt;
=== Notes ===&lt;br /&gt;
If you are installing to a system where you don&amp;#039;t have root access (i.e. this computer does not belong to you) you won&amp;#039;t be able to install the software using the default configure script. This is because by default software is installed to the /usr/local directory. If you are not a systems administrator then you will quite rightly not have write access to this folder. All is not lost! You can still install software into your home directory. In order to do this you should always call the configure script with the following parameter: --prefix=$HOME. This goes for all the software to be installed below. All executables will then be placed in ~/bin, libraries in ~/lib, includes in ~/include, etc...&lt;br /&gt;
&lt;br /&gt;
In the guide below the parameter is included in italic. If you do in fact have root access then it is recommended to omit this parameter and install to the default directory so that other users will also have access to the software.&lt;br /&gt;
&lt;br /&gt;
=== Get TexGen from Subversion repository ===&lt;br /&gt;
&lt;br /&gt;
==== Install Subversion ====&lt;br /&gt;
[http://subversion.tigris.org/servlets/ProjectDocumentList?collapseFolder=260&amp;amp;folderID=260 Download Subversion] and unpack.&lt;br /&gt;
Open a shell in extracted folder and type:&lt;br /&gt;
 ./configure --with-ssl &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* You will need to install Subversion with SSL support since TexGen is hosted on sourceforge which uses SSL. If you don&amp;#039;t configure with the --with-ssl flag you will get an error when trying to checkout TexGen in the next step.&lt;br /&gt;
* If you have trouble installing the latest version of Subversion, try installing version 1.3 as it does not require a seperate dependencies package.&lt;br /&gt;
&lt;br /&gt;
==== Checkout ====&lt;br /&gt;
Open a shell in folder you wish to place TexGen (e.g. ~/):&lt;br /&gt;
 svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The first parameter tells SVN to get the files for the first time&lt;br /&gt;
* The second parameter is the location of the TexGen svn repository&lt;br /&gt;
* The final parameter is the subfolder to put the files in&lt;br /&gt;
&lt;br /&gt;
==== Update ====&lt;br /&gt;
The checkout command only needs to performed once. SVN keeps track of where the code was originally obtained and can update to the latest version without having to re-specify the location. In order to do that open a shell in the folder where TexGen was originally checkout (e.g. ~/TexGen) and type:&lt;br /&gt;
 svn update&lt;br /&gt;
or if you are in a hurry you can type the shorter version:&lt;br /&gt;
 svn up&lt;br /&gt;
&lt;br /&gt;
=== Compile source ===&lt;br /&gt;
&lt;br /&gt;
==== Install CMake ====&lt;br /&gt;
&lt;br /&gt;
[http://www.cmake.org/HTML/Download.html Download CMake] and unpack.&lt;br /&gt;
Open a shell in extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
==== Compile TexGen core ====&lt;br /&gt;
Open a shell in the folder with the TexGen source code (e.g. ~/TexGen):&lt;br /&gt;
 mkdir bin&lt;br /&gt;
 cd bin&lt;br /&gt;
 ccmake ../&lt;br /&gt;
Press &amp;#039;c&amp;#039; to configure. When a warning pops up telling you it can&amp;#039;t find such and such a file press &amp;#039;e&amp;#039; to close it. You will now need to specify which components of TexGen to build and where their dependencies can be found. Use the up and down arrows to move the caret and press enter to modify options. Do this to set BUILD_GUI, BUILD_PYTHON_INTERFACE and BUILD_RENDERER to OFF. You are basically telling CMake not to attempt to build these components, which means that you won&amp;#039;t need to have installed their dependencies.&lt;br /&gt;
&lt;br /&gt;
Similarly to the --prefix=$HOME parameter to the configure script, you can tell CMake to install TexGen to your home directory by changing CMAKE_INSTALL_PREFIX to ~/. Note that it won&amp;#039;t actually install anything until you get type make install.&lt;br /&gt;
&lt;br /&gt;
Now press &amp;#039;c&amp;#039; again to update the changes.&lt;br /&gt;
&lt;br /&gt;
Hopefully now that all the additional modules have been switched off no errors will be shown. Press &amp;#039;g&amp;#039; to generate the makefiles and exit. At the shell type:&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Note that at this point you have only built and installed the TexGen Core library which doesn&amp;#039;t actually do anything on its own. If you plan to incorporate TexGen into your own C++ program then this is enough, however if you would like to interface with TexGen from a Python script or Graphical User Interface then follow the steps below.&lt;br /&gt;
&lt;br /&gt;
=== Compiling optional modules ===&lt;br /&gt;
==== Python interface ====&lt;br /&gt;
[http://www.python.org/download/ Download Python] and unpack.&lt;br /&gt;
Open a shell in the extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
[http://www.swig.org/download.html Download SWIG] and unpack.&lt;br /&gt;
Open a shell in the extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Open a shell in the folder where you called ccmake from for the first time (e.g. ~/TexGen/bin):&lt;br /&gt;
 ccmake ../&lt;br /&gt;
&lt;br /&gt;
Use the up and down arrows to reach BUILD_PYTHON_INTERFACE and press Enter to set it to ON. Then press &amp;#039;c&amp;#039; to configure. You will probably get a warning saying you need to specify the location of SWIG and/or Python, press &amp;#039;e&amp;#039; to close it.&lt;br /&gt;
&lt;br /&gt;
Set the PYTHON_INCLUDE_PATH, PYTHON_LIBRARY, PYTHON_SITEPACKAGES_DIR, SWIG_DIR and SWIG_EXECUTABLE parameters correctly where necessary. If you have installed packages to your home directory then they should look something like this:&lt;br /&gt;
&lt;br /&gt;
 PYTHON_INCLUDE_PATH: ~/include/python2.5&lt;br /&gt;
 PYTHON_LIBRARY: ~/lib/python2.5/config/libpython2.5.a&lt;br /&gt;
 PYTHON_SITEPACKAGES_DIR: ~/lib/python2.5/site-packages&lt;br /&gt;
 SWIG_DIR: ~/bin&lt;br /&gt;
 SWIG_EXECUTABLE: ~/bin/swig&lt;br /&gt;
&lt;br /&gt;
Once that is done press &amp;#039;c&amp;#039; again. You may need perform this process over several iterations. When everything is set correctly press &amp;#039;g&amp;#039; to generate the makefiles.&lt;br /&gt;
&lt;br /&gt;
At the shell type:&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Assuming the build completed without errors you should now be able to access TexGen functions from within Python. In order to check everything worked as planned open Python in interactive mode by typing:&lt;br /&gt;
 python&lt;br /&gt;
&lt;br /&gt;
Then from within Python type:&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
 CTexGen.GetInstance().GetVersion()&lt;br /&gt;
&lt;br /&gt;
This should display the version of TexGen installed.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when linking _Core.so:&lt;br /&gt;
 libpython2.5.a(abstract.o): relocation R_X86_64_32 against `a local symbol&amp;#039;&lt;br /&gt;
 can not be used when making a shared object; recompile with -fPIC&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; Try removing libpython2.5.a from the libraries to link to by setting PYTHON_LIBRARY to a bogus path, e.g.:&lt;br /&gt;
&lt;br /&gt;
PYTHON_LIBRARY: ~/&lt;br /&gt;
&lt;br /&gt;
By doing so you may receive a warning similar to this:&lt;br /&gt;
 Warning: Ignoring path found in link libraries for target: _Core, path is:&lt;br /&gt;
 /home/username. Expected a library name or a full path to a library name.&lt;br /&gt;
This warning may be ignored.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Compiling from Source</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-05-02T15:05:50Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In order to compile TexGen and &amp;#039;&amp;#039;&amp;#039;all&amp;#039;&amp;#039;&amp;#039; of its modules, the following software is required:&lt;br /&gt;
&lt;br /&gt;
The following programs are needed to build TexGen:&lt;br /&gt;
* [http://www.cmake.org/ CMake]&lt;br /&gt;
* [http://www.swig.org/ SWIG]&lt;br /&gt;
&lt;br /&gt;
The following libraries are needed to link to TexGen:&lt;br /&gt;
* [http://www.vtk.org/ VTK]&lt;br /&gt;
* [http://www.wxwidgets.org/ wxWidgets]&lt;br /&gt;
* [http://www.opencascade.org/ OpenCascade]&lt;br /&gt;
* [http://www.python.org/ Python]&lt;br /&gt;
&lt;br /&gt;
However to perform a minimum build of TexGen with none of the additional modules you only require CMake and a C++ compiler. It is recommended to begin with a minimum build, once that is working try adding modules one at a time. A list of modules along with dependencies is shown below:&lt;br /&gt;
&lt;br /&gt;
* Python interface: Python, SWIG&lt;br /&gt;
* Renderer: VTK&lt;br /&gt;
* Export: OpenCascade&lt;br /&gt;
* GUI: wxWidgets, Renderer, Python interface&lt;br /&gt;
* Unit tests: CPPUnit&lt;br /&gt;
&lt;br /&gt;
A graphical representation of the modules and their dependencies can also be found in the [http://texgen.sourceforge.net/api/ TexGen API].&lt;br /&gt;
&lt;br /&gt;
If you want to get the source code from the Subversion repository you will need to install [http://subversion.tigris.org/ Subversion] by following the instructions below. Note that this is the very latest development source and so may it contain some bugs and unfinished features. However it is very easy to keep up to date with the latest version of TexGen using this method and will allow you to keep any modifications you have made to the source when updating. If you find a bug or implement new features that may be usefull to the rest of the community they can also be submited as patch and incorporated into TexGen following review.&lt;br /&gt;
&lt;br /&gt;
Alternatively the stable source code can be downloaded as a [http://sourceforge.net/project/showfiles.php?group_id=181000 tarball]. Download the latest file release named &amp;#039;&amp;#039;texgen-3.x.x.tar.gz&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
== Windows (Microsoft Visual Studio C++, recommended method) ==&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
It is assumed that Microsoft Visual Studio is already installed.  If it isn&amp;#039;t and you plan to use it, then install it.  It may be possible to use the free [http://www.microsoft.com/express/ Visual Studio Express]; if anyone tries this and finds out one way or the other, please post the information either here or in the [http://texgen.sourceforge.net/phpBB2/index.php forum]. Brief instructions on how to install the various 3rd party libraries under windows are given below. Note that you do not need to install all of these in order to perform the minimal build. Only CMake is absolutely required.&lt;br /&gt;
&lt;br /&gt;
==== CMake ====&lt;br /&gt;
&lt;br /&gt;
[http://www.cmake.org/HTML/Download.html Download CMake] and install, selecting &amp;#039;Add CMake to the system PATH for all users&amp;#039; (select current user if this is not permissible on your system).&lt;br /&gt;
&lt;br /&gt;
==== TortoiseSVN ====&lt;br /&gt;
&lt;br /&gt;
[http://tortoisesvn.net/downloads Download TortoiseSVN] and install it.&lt;br /&gt;
&lt;br /&gt;
==== SWIG ====&lt;br /&gt;
&lt;br /&gt;
[http://www.swig.org/ Download] the latest release of the windows .zip files and extract to a suitable location (e.g. c:\Program Files\swigwin-1.3.31).&lt;br /&gt;
&lt;br /&gt;
==== Python ====&lt;br /&gt;
&lt;br /&gt;
[http://www.python.org/ Download Python] and install.&lt;br /&gt;
&lt;br /&gt;
==== OpenCascade ====&lt;br /&gt;
&lt;br /&gt;
[http://www.opencascade.org/getocc/download/ Download OpenCascade] and install; this extracts the files to a directory. If the installation doesn&amp;#039;t start automatically, run the &amp;#039;install.bat&amp;#039; file located the directory where the files where extracted (read &amp;#039;readme.htm&amp;#039; file in the same directory for more information).  Choose &amp;#039;complete installation&amp;#039; and tick the box to set the environment variables.&lt;br /&gt;
&lt;br /&gt;
==== VTK ====&lt;br /&gt;
&lt;br /&gt;
[http://www.vtk.org/get-software.php Download] the latest source files and extract them. Follow the instructions in &amp;#039;README.html&amp;#039; found in the extracted directory to compile VTK using CMake. The following CMake settings should be set:&lt;br /&gt;
&lt;br /&gt;
 BUILD_EXAMPLES           OFF&lt;br /&gt;
 BUILD_SHARED_LIBS        OFF&lt;br /&gt;
 VTK_USE_MPEG2_ENCODER    OFF&lt;br /&gt;
 VTK_USE_PARALLEL         OFF&lt;br /&gt;
 VTK_USE_RENDERING        ON&lt;br /&gt;
 VTK_WRAP_JAVA            OFF&lt;br /&gt;
 VTK_WRAP_PYTHON          OFF&lt;br /&gt;
 VTK_WRAP_TCL             OFF&lt;br /&gt;
&lt;br /&gt;
You may be able to get things working with different settings, however these are the settings I use and are known to work.&lt;br /&gt;
&lt;br /&gt;
==== wxWidgets ====&lt;br /&gt;
&lt;br /&gt;
[http://www.wxwidgets.org/downloads/ Download] and install the windows version of wxWidgets (wxMSW). It is then necessary to compile wxWidgets from source, detailed instructions on how to do this can be found in &amp;#039;install.txt&amp;#039; located in the &amp;#039;docs\msw&amp;#039; subfolder. The main steps are to open &amp;#039;wx.dsw&amp;#039; with MSVC located in the &amp;#039;build\msw&amp;#039; subfolder and compile both Release and Debug configurations (The configuration can be selected from the drop down box on the main toolbar in Visual Studio. Universal, Unicode and DLL versions need not be compiled).&lt;br /&gt;
&lt;br /&gt;
=== Checkout TexGen source code from subversion server ===&lt;br /&gt;
Create a directory where you would like to store the TexGen source code in Windows Explorer. Right click on this folder and select &amp;#039;SVN Checkout...&amp;#039; from the context menu that appears. In the dialog box which follows, enter &amp;#039;https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/&amp;#039; in the URL field. The Checkout directory field should have been filled in automatically. Click on OK to start downloading the TexGen source code. In future the latest version of the source code can be obtained simply by right clicking on the folder and selecting &amp;#039;SVN Update&amp;#039; from the context menu.&lt;br /&gt;
&lt;br /&gt;
=== Configuring the build system with CMake ===&lt;br /&gt;
Run CMake from its shortcut on the Start menu. There are some general instructions on using CMake on the [http://www.cmake.org/HTML/RunningCMake.html CMake website] which are worth reading. You will need to fill in the source code location, this should point to where you checkout out the latest TexGen SVN code or where you extracted the source code from the zip file. Also set where to place the binary files once they are compiled, this can be the same as the source directory, a subdirectory within the source directory or any other location.&lt;br /&gt;
&lt;br /&gt;
Once that is entered click &amp;#039;Configure&amp;#039; and choose the Visual Studio version which you have installed and click ok. You will initially get a number of error messages such as:&lt;br /&gt;
&lt;br /&gt;
 CMake Error: Swig was not found on the system. Please specify the location of Swig. (click OK)&lt;br /&gt;
 CMake Error: Error in configuration process, project files may be invalid. (click OK)&lt;br /&gt;
&lt;br /&gt;
This is normal, in order to get rid of the errors you will need to tell CMake where the various libraries you have installed can be found. This is done in the Cache Values sections.&lt;br /&gt;
&lt;br /&gt;
It is recommended to begin with a minimal build, this is achieved by setting the cache values as follows:&lt;br /&gt;
&lt;br /&gt;
 BUILD_CASCADE_EXPORT           OFF&lt;br /&gt;
 BUILD_DOCUMENTATION            OFF&lt;br /&gt;
 BUILD_EXAMPLES                 OFF&lt;br /&gt;
 BUILD_GUI                      OFF&lt;br /&gt;
 BUILD_PYTHON_INTERFACE         OFF&lt;br /&gt;
 BUILD_RENDERER                 OFF&lt;br /&gt;
 BUILD_SHARED                   ON&lt;br /&gt;
 BUILD_UNIT_TESTS               OFF&lt;br /&gt;
&lt;br /&gt;
Once these are set press configure again and you shouldn&amp;#039;t have any more errors/warnings. Press &amp;#039;OK&amp;#039; to generate the MSVC solution and project files. Configuring the various optional modules is explained in [[#Configuring optional modules]].&lt;br /&gt;
&lt;br /&gt;
=== Configuring optional modules ===&lt;br /&gt;
&lt;br /&gt;
Once the minimal build is working you may want to switch on the optional modules. To do this open up CMake again and switch the modules you want to ON in the Cache Values then click Configure. You will most likely see some errors telling you it is unable to automatically find certain directories. You will need to specify these manually. An explanation of the different locations is listed below:&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;PYTHON_SITEPACKAGES_DIR&amp;#039;&amp;#039;&amp;#039; - This should be the folder where the TexGen python modules will be placed. Usually located in &amp;#039;C:\Python25\Lib\site-packages&amp;#039;, but this will depend on the version of Python installed and where you decided to install it.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SWIG_DIR&amp;#039;&amp;#039;&amp;#039; -  This is the location where you extracted the SWIG executable. e.g. &amp;#039;C:\Program Files\swigwin-1.3.31&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;SWIG_EXECUTABLE&amp;#039;&amp;#039;&amp;#039; - Same as root directory followed by &amp;#039;swig.exe&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wxWidgets_ROOT_DIR&amp;#039;&amp;#039;&amp;#039; - Location where you install wxWidgets. e.g. &amp;#039;C:/wxWidgets-2.8.3&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wxWidgets_LIB_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the wxWidgets libraries were compiled to, should be the same as the root directory followed by &amp;#039;lib\vc_lib&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_INCLUDE_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade header files are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/inc&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_LIBRARY_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade libraries are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/win32/lib&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;OPENCASCADE_DEBUG_LIBRARY_DIR&amp;#039;&amp;#039;&amp;#039; - Location where the OpenCascade debug libraries are located. e.g. &amp;#039;C:/OpenCASCADE6.1.0/ros/win32/libd&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;VTK_DIR&amp;#039;&amp;#039;&amp;#039; - Location of the VTK binary directory (note: not the source directory).&lt;br /&gt;
&lt;br /&gt;
After setting the directories manually, click on configure again. You may need to go through several iterations of changing parameters then pressing configure. Once you have finished changing parameters and have successfully pressed configure without error messages you can press the OK button to generate the build. Note: you can always come back to this at a later time to make changes.&lt;br /&gt;
&lt;br /&gt;
=== Compiling ===&lt;br /&gt;
&lt;br /&gt;
Find &amp;#039;TexGen.sln&amp;#039; which should be located in the directory where you told CMake to output the binary files to and open it with Microsoft Visual Studio.&lt;br /&gt;
&lt;br /&gt;
Set the configuration to &amp;#039;Release&amp;#039; and build the solution. Hopefully the project will have been compiled without errors.&lt;br /&gt;
&lt;br /&gt;
If you want to compile and execute the Graphical User Interface you will need to install it, you will not be able to execute it directly from the build directory. This is done by right click on the &amp;#039;INSTALL&amp;#039; project in the Solution Explorer and selecting Build. This will copy the Python modules into the Python site-packages directory so that they can be imported into scripts, and it will copy the executable along with other necessary files into &amp;#039;C:\Program Files\TexGen\&amp;#039; by default (this can be changed with the CMAKE_INSTALL_PREFIX cache value in CMake). TexGenGUI.exe should then be run from the installed location, if you attempt to run it directly from where it was compiled you will get some errors on launch.&lt;br /&gt;
&lt;br /&gt;
=== Building the documentation ===&lt;br /&gt;
&lt;br /&gt;
To build the documentation, [http://www.stack.nl/~dimitri/doxygen/download.html Doxygen] is required.  Open a command prompt in the &amp;#039;Docs&amp;#039; subdirectory of the source code and run &amp;#039;doxygen&amp;#039;. If the doxygen directory is not in your path, you must add it, or give the full path on the command line.&lt;br /&gt;
&lt;br /&gt;
=== Integrating TexGen with ABAQUS ===&lt;br /&gt;
&lt;br /&gt;
If you are using ABAQUS and wish to use TexGen Python scripting from within the ABAQUS/CAE environment, there are a few extra steps to perform. This is because ABAQUS comes packaged with its own version of Python, so any modules added to your standalone python installation will not be accessible by ABAQUS. You must compile the TexGen Python modules with the same version of Python as ABAQUS uses. The following table shows which version of Python is used in specific ABAQUS versions:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! ABAQUS Version !! Python Version&lt;br /&gt;
|-&lt;br /&gt;
| 6.6-1 || 2.3.3&lt;br /&gt;
|- &lt;br /&gt;
| 6.7-1 || 2.4.3 &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
If your version of ABAQUS is not listed in the table above you can type &amp;#039;abaqus python -V&amp;#039; to check what version of Python is used (then please edit this page to update the table). You can obtain specific versions of Python from http://www.python.org/download/releases/x.y.z/ where x.y.z represents the version number.&lt;br /&gt;
&lt;br /&gt;
Additionally you will need to place the TexGen python modules inside ABAQUS&amp;#039; version of python. There are a few ways to accomplish this, the easiest is perhaps to set the CMake cache variable &amp;#039;PYTHON_SITEPACKAGES_DIR&amp;#039; point to the ABAQUS&amp;#039; python directory, e.g.:&lt;br /&gt;
&lt;br /&gt;
 PYTHON_SITEPACKAGES_DIR     C:\Abaqus\6.7-1\Python\Lib\&lt;br /&gt;
&lt;br /&gt;
Then when you build the INSTALL project in MSVC++ it will automatically copy the TexGen python modules to the ABAQUS&amp;#039; Python. Alternatively you can simply copy the files manually or modify Python&amp;#039;s search path to include the TexGen python modules, e.g. In python:&lt;br /&gt;
&lt;br /&gt;
 import sys&lt;br /&gt;
 sys.path.append(&amp;#039;C:/Python24/Lib/site-packages/&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when compiling:&lt;br /&gt;
 fatal error LNK1104: cannot open file &amp;#039;python25_d.lib&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; The windows installation of Python doesn&amp;#039;t come with the debug library (&amp;#039;python25_d.lib&amp;#039;, the _d part means debug). You should be able to compile in release mode however. If you really want to compile in debug mode you will need to compile Python from source and link to that. Or you can try to link to the release library &amp;#039;python25.lib&amp;#039; instead, easiest way to do that is to copy &amp;#039;python25.lib&amp;#039; to &amp;#039;python25_d.lib&amp;#039; but this may cause problems during linking or execution.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when compiling:&lt;br /&gt;
 fatal error C1083: Cannot open include file: &amp;#039;wx/wxprec.h&amp;#039;: No such file or directory&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; Make sure that you have compiled wxWidgets and that the wxWidgets_XXX cache variables are set correctly in CMake.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I do not have a &amp;#039;libd&amp;#039; folder in &amp;#039;ros/win32&amp;#039; for OpenCASCADE.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; If you do not compile OpenCASCADE yourself then this folder does not exist. However it can be ignored if you are only interested in building the release version of TexGen. If you really want to compile the debug version please refer to the OpenCASCADE documentation.&lt;br /&gt;
&lt;br /&gt;
== Windows (Cygwin and gcc, alternate method) ==&lt;br /&gt;
A limited build (without graphics) can be made under cygwin, this is a UNIX emulation environment available at [http://www.cygwin.com www.cygwin.com]. &lt;br /&gt;
This can exist peacefully next to the native windows version. &lt;br /&gt;
Cygwin creates a unix-style file system within your windows installation. If you choose c:/cygwin as your install directory, your HOME will be at c:/cygwin/home/&amp;lt;username&amp;gt;/. &lt;br /&gt;
&lt;br /&gt;
=== Download cygwin and install packages ===&lt;br /&gt;
Install gcc, g++, wget, make and cmake using the setup.exe program from the cygwin website. &lt;br /&gt;
For the mesh generator and python interface to work we currently need VTK and swig. &lt;br /&gt;
&lt;br /&gt;
This downloads and installs swig from source (when starting the cygwin shell you can paste this into the command line, otherwise write it to a file and run it with sh). &lt;br /&gt;
 mkdir progs&lt;br /&gt;
 cd progs &lt;br /&gt;
 SWIG=swig-1.3.31&lt;br /&gt;
 wget -nc http://kent.dl.sourceforge.net/sourceforge/swig/$SWIG.tar.gz&lt;br /&gt;
 tar xzvf $SWIG.tar.gz &lt;br /&gt;
 cd $SWIG&lt;br /&gt;
 ./configure &lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
This downloads and installs VTK from source, in the ccmake stage, use the cmake graphical commands to get a working install. &lt;br /&gt;
 VTK=vtk-5.0.3&lt;br /&gt;
 wget -nc http://www.vtk.org/files/release/5.0/$VTK.tar.gz&lt;br /&gt;
 tar xzvf $VTK.tar.gz&lt;br /&gt;
 mkdir vtkbin&lt;br /&gt;
 cd vtkbin&lt;br /&gt;
 ccmake ../VTK&lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
=== Install TexGen from source ===&lt;br /&gt;
Now we can proceed to install texgen, as an example we&amp;#039;ll work in ~/temp/texgen&lt;br /&gt;
 cd ~; mkdir temp; cd temp; mkdir texgen; cd texgen&lt;br /&gt;
 svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen&lt;br /&gt;
 cd .. ; mkdir tbin; cd tbin&lt;br /&gt;
 ccmake ../texgen&lt;br /&gt;
 make &lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
This should result in a working texgen install in ~/temp/texgen/tbin.&lt;br /&gt;
&lt;br /&gt;
== Unix ==&lt;br /&gt;
=== Notes ===&lt;br /&gt;
If you are installing to a system where you don&amp;#039;t have root access (i.e. this computer does not belong to you) you won&amp;#039;t be able to install the software using the default configure script. This is because by default software is installed to the /usr/local directory. If you are not a systems administrator then you will quite rightly not have write access to this folder. All is not lost! You can still install software into your home directory. In order to do this you should always call the configure script with the following parameter: --prefix=$HOME. This goes for all the software to be installed below. All executables will then be placed in ~/bin, libraries in ~/lib, includes in ~/include, etc...&lt;br /&gt;
&lt;br /&gt;
In the guide below the parameter is included in italic. If you do in fact have root access then it is recommended to omit this parameter and install to the default directory so that other users will also have access to the software.&lt;br /&gt;
&lt;br /&gt;
=== Get TexGen from Subversion repository ===&lt;br /&gt;
&lt;br /&gt;
==== Install Subversion ====&lt;br /&gt;
[http://subversion.tigris.org/servlets/ProjectDocumentList?collapseFolder=260&amp;amp;folderID=260 Download Subversion] and unpack.&lt;br /&gt;
Open a shell in extracted folder and type:&lt;br /&gt;
 ./configure --with-ssl &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* You will need to install Subversion with SSL support since TexGen is hosted on sourceforge which uses SSL. If you don&amp;#039;t configure with the --with-ssl flag you will get an error when trying to checkout TexGen in the next step.&lt;br /&gt;
* If you have trouble installing the latest version of Subversion, try installing version 1.3 as it does not require a seperate dependencies package.&lt;br /&gt;
&lt;br /&gt;
==== Checkout ====&lt;br /&gt;
Open a shell in folder you wish to place TexGen (e.g. ~/):&lt;br /&gt;
 svn checkout https://texgen.svn.sourceforge.net/svnroot/texgen/TexGen/trunk/ TexGen&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The first parameter tells SVN to get the files for the first time&lt;br /&gt;
* The second parameter is the location of the TexGen svn repository&lt;br /&gt;
* The final parameter is the subfolder to put the files in&lt;br /&gt;
&lt;br /&gt;
==== Update ====&lt;br /&gt;
The checkout command only needs to performed once. SVN keeps track of where the code was originally obtained and can update to the latest version without having to re-specify the location. In order to do that open a shell in the folder where TexGen was originally checkout (e.g. ~/TexGen) and type:&lt;br /&gt;
 svn update&lt;br /&gt;
or if you are in a hurry you can type the shorter version:&lt;br /&gt;
 svn up&lt;br /&gt;
&lt;br /&gt;
=== Compile source ===&lt;br /&gt;
&lt;br /&gt;
==== Install CMake ====&lt;br /&gt;
&lt;br /&gt;
[http://www.cmake.org/HTML/Download.html Download CMake] and unpack.&lt;br /&gt;
Open a shell in extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
==== Compile TexGen core ====&lt;br /&gt;
Open a shell in the folder with the TexGen source code (e.g. ~/TexGen):&lt;br /&gt;
 mkdir bin&lt;br /&gt;
 cd bin&lt;br /&gt;
 ccmake ../&lt;br /&gt;
Press &amp;#039;c&amp;#039; to configure. When a warning pops up telling you it can&amp;#039;t find such and such a file press &amp;#039;e&amp;#039; to close it. You will now need to specify which components of TexGen to build and where their dependencies can be found. Use the up and down arrows to move the caret and press enter to modify options. Do this to set BUILD_GUI, BUILD_PYTHON_INTERFACE and BUILD_RENDERER to OFF. You are basically telling CMake not to attempt to build these components, which means that you won&amp;#039;t need to have installed their dependencies.&lt;br /&gt;
&lt;br /&gt;
Similarly to the --prefix=$HOME parameter to the configure script, you can tell CMake to install TexGen to your home directory by changing CMAKE_INSTALL_PREFIX to ~/. Note that it won&amp;#039;t actually install anything until you get type make install.&lt;br /&gt;
&lt;br /&gt;
Now press &amp;#039;c&amp;#039; again to update the changes.&lt;br /&gt;
&lt;br /&gt;
Hopefully now that all the additional modules have been switched off no errors will be shown. Press &amp;#039;g&amp;#039; to generate the makefiles and exit. At the shell type:&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Note that at this point you have only built and installed the TexGen Core library which doesn&amp;#039;t actually do anything on its own. If you plan to incorporate TexGen into your own C++ program then this is enough, however if you would like to interface with TexGen from a Python script or Graphical User Interface then follow the steps below.&lt;br /&gt;
&lt;br /&gt;
=== Compiling optional modules ===&lt;br /&gt;
==== Python interface ====&lt;br /&gt;
[http://www.python.org/download/ Download Python] and unpack.&lt;br /&gt;
Open a shell in the extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
[http://www.swig.org/download.html Download SWIG] and unpack.&lt;br /&gt;
Open a shell in the extracted folder and type:&lt;br /&gt;
 ./configure &amp;#039;&amp;#039;--prefix=$HOME&amp;#039;&amp;#039;&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Open a shell in the folder where you called ccmake from for the first time (e.g. ~/TexGen/bin):&lt;br /&gt;
 ccmake ../&lt;br /&gt;
&lt;br /&gt;
Use the up and down arrows to reach BUILD_PYTHON_INTERFACE and press Enter to set it to ON. Then press &amp;#039;c&amp;#039; to configure. You will probably get a warning saying you need to specify the location of SWIG and/or Python, press &amp;#039;e&amp;#039; to close it.&lt;br /&gt;
&lt;br /&gt;
Set the PYTHON_INCLUDE_PATH, PYTHON_LIBRARY, PYTHON_SITEPACKAGES_DIR, SWIG_DIR and SWIG_EXECUTABLE parameters correctly where necessary. If you have installed packages to your home directory then they should look something like this:&lt;br /&gt;
&lt;br /&gt;
 PYTHON_INCLUDE_PATH: ~/include/python2.5&lt;br /&gt;
 PYTHON_LIBRARY: ~/lib/python2.5/config/libpython2.5.a&lt;br /&gt;
 PYTHON_SITEPACKAGES_DIR: ~/lib/python2.5/site-packages&lt;br /&gt;
 SWIG_DIR: ~/bin&lt;br /&gt;
 SWIG_EXECUTABLE: ~/bin/swig&lt;br /&gt;
&lt;br /&gt;
Once that is done press &amp;#039;c&amp;#039; again. You may need perform this process over several iterations. When everything is set correctly press &amp;#039;g&amp;#039; to generate the makefiles.&lt;br /&gt;
&lt;br /&gt;
At the shell type:&lt;br /&gt;
 make&lt;br /&gt;
 make install&lt;br /&gt;
&lt;br /&gt;
Assuming the build completed without errors you should now be able to access TexGen functions from within Python. In order to check everything worked as planned open Python in interactive mode by typing:&lt;br /&gt;
 python&lt;br /&gt;
&lt;br /&gt;
Then from within Python type:&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
 CTexGen.GetInstance().GetVersion()&lt;br /&gt;
&lt;br /&gt;
This should display the version of TexGen installed.&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Q:&amp;#039;&amp;#039;&amp;#039; I get the following error when linking _Core.so:&lt;br /&gt;
 libpython2.5.a(abstract.o): relocation R_X86_64_32 against `a local symbol&amp;#039;&lt;br /&gt;
 can not be used when making a shared object; recompile with -fPIC&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;A:&amp;#039;&amp;#039;&amp;#039; Try removing libpython2.5.a from the libraries to link to by setting PYTHON_LIBRARY to a bogus path, e.g.:&lt;br /&gt;
&lt;br /&gt;
PYTHON_LIBRARY: ~/&lt;br /&gt;
&lt;br /&gt;
By doing so you may receive a warning similar to this:&lt;br /&gt;
 Warning: Ignoring path found in link libraries for target: _Core, path is:&lt;br /&gt;
 /home/username. Expected a library name or a full path to a library name.&lt;br /&gt;
This warning may be ignored.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Roadmap</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-23T13:45:32Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Todo */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== ChangeLog ==&lt;br /&gt;
&lt;br /&gt;
== Todo ==&lt;br /&gt;
http://sourceforge.net/tracker/?group_id=181000&lt;br /&gt;
* Add ability to set textile name in the 2d weave wizard&lt;br /&gt;
* Memory management, may want to think about how the textile and yarn classes are stored. Currently the yarn has no knowledge of its parent. This can be troublesome for some functions. It is often useful for the yarn to have access to information about the textile it belongs to. Consider adding a parameter to yarn which points back to its parent. This removes the ability for the yarn to be copied, however this is not such a big deal anyway. There are few cases when this is necessary or useful.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Modeller&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
** Popup menu in the outliner when right clicking on a yarn to assign sections and whatnot (could also enable the pop-up in the main render window) - then remove the buttons on the modeller page to clean things up a bit&lt;br /&gt;
** Have option to see repeat vectors graphically along with some repeated yarns&lt;br /&gt;
** Do sorting based on camera position for transparency&lt;br /&gt;
** Box selection (paraview have made a plugin for this)&lt;br /&gt;
** Layers so that picking of nodes belonging to specific yarns made easier&lt;br /&gt;
** Add undo ability&lt;br /&gt;
** Make sure python code is generated for all important operations (e.g. python code should be generated when mouse is released from a move operation)&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Bugs&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
** GetYarnLength doesn&amp;#039;t seem to be working in python scripts&lt;br /&gt;
** Picking in the modeller seems screwed up sometimes (need to click a bit above desired position)&lt;br /&gt;
** White lines appear in the 3d modelling wizard&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:35:16Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Export a mesh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Create Models]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
Note that by adding this line does not prevent you from running your scripts through the GUI as well.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decided what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial section 7.2] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial section 7.1] and [http://docs.python.org/lib/typesseq-strings.html Python library reference 3.6.2] for more information on this.&lt;br /&gt;
&lt;br /&gt;
At this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points were written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it, you should now have a script which reads a TexGen tg3 file, extracts a mesh from it and writes the contents to a file in the VTK legacy file format. Your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&lt;br /&gt;
file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&lt;br /&gt;
# Get element information from the mesh&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&lt;br /&gt;
# Write the element information&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Verification==&lt;br /&gt;
&lt;br /&gt;
The first thing to do now is to run the script from the command line like so:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
replacing &amp;lt;code&amp;gt;myscript.py&amp;lt;/code&amp;gt; with the name of the script your created and ensuring you have a textile model named &amp;lt;code&amp;gt;textile.tg3&amp;lt;/code&amp;gt; in the some folder as the script. If it ran successfully you should see a file named &amp;lt;code&amp;gt;mesh.vtk&amp;lt;/code&amp;gt; being created. Load this up into [http://www.paraview.org/ ParaView] and you should see a mesh of your textile.&lt;br /&gt;
&lt;br /&gt;
When writing your own scripts it is unlikely that they will work straight away (even for professional programmers), so it is a good idea to check the output of your script at each step with a text editor to ensure that it is writing exactly what you want. This will enable you to isolate bugs early on and one at a time rather than having to fix a long script containing numerous bugs. The [http://docs.python.org/tut/node5.html#SECTION005200000000000000000 print statement] is your friend when it comes to debugging, it can be used to print out values and verify that they are what you expect.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Guide</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:34:17Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Python Interface==&lt;br /&gt;
[http://www.python.org/ Python] is a high level interpreted programming language. In this case it is used as a scripting language to allow easy access to TexGen functionality. Python has been embedded in the TexGen GUI which allows the GUI to run python scripts. The goal of this tutorial is not to teach Python programming, there are plenty of resources online for that. A few of them are listed below:&lt;br /&gt;
&lt;br /&gt;
* [http://www.poromenos.org/tutorials/python Learn Python in 10 minutes] - Quick introduction to Python for competent programmers.&lt;br /&gt;
* [http://docs.python.org/tut/tut.html Python Tutorial] - Official Python tutorial (requires some programming knowledge).&lt;br /&gt;
* [http://www.greenteapress.com/thinkpython/ How to Think Like a Computer Scientist: Learning with Python] - Book on Python programming for beginners. [http://www.greenteapress.com/thinkpython/html/ HTML Version]&lt;br /&gt;
* [http://diveintopython.org/ Dive Into Python] - In depth book covering advanced subjects in a comprehensive manner. [http://diveintopython.org/toc/index.html HTML Version]&lt;br /&gt;
&lt;br /&gt;
An advanced knowledge of Python is not needed in order to write simple TexGen scripts. However, bear in mind that Python is a very powerful language with many libraries included for performing common tasks.&lt;br /&gt;
&lt;br /&gt;
A series of tutorials on getting started with using Python in conjunction with TexGen are provided below. They have been written in such a way that they are best read sequentially since each one follows on from the previous:&lt;br /&gt;
&lt;br /&gt;
* [[Scripting Create Models]]&lt;br /&gt;
* [[Scripting Export Mesh]]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Create Models</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:31:15Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Example 1: A plain weave===&lt;br /&gt;
First of all, a Python script is just a plain ASCII text file with a .py extension. To create one simply open up your favorite text editor. Notepad will do if you have nothing else but I suggest a more powerful freeware text editor like [http://www.pspad.com/ PSPad] or [http://notepad-plus.sourceforge.net/ Notepad++]. Code that goes into the python script will be displayed like so:&lt;br /&gt;
&lt;br /&gt;
 # All Python code will be shown in a box like this one.&lt;br /&gt;
 # Lines begining with a &amp;#039;#&amp;#039; character are comments&lt;br /&gt;
&lt;br /&gt;
In this example, we will create a simple 2x2 plain weave model with a Python script. Its time to dive in and see some actual Python code. At this point if you are completely lost please refer back to the resources on Python programming. The first step is to create an instance of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class and give it a name, &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class takes 5 parameters in the order shown below:&lt;br /&gt;
* Number of weft yarns in the unit cell&lt;br /&gt;
* Number of warp yarns in the unit cell&lt;br /&gt;
* Spacing between the yarns&lt;br /&gt;
* Thickness of the fabrics&lt;br /&gt;
* Refine model (True/False)&lt;br /&gt;
&lt;br /&gt;
The only parameter that really needs an explanation here is the Refine model option, this controls whether or not the interference correction algorithm will be applied to keep the yarn volumes from intersecting which is a common problem. The interference correction algorithm generally does a good job but is not instantaneous so sometimes it can be beneficial to switch it off.&lt;br /&gt;
&lt;br /&gt;
This is the bare minimum information necessary to create a 2D woven fabric. In the following steps we will add more information to create the model the way we want it.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s set the weave pattern, this determines whether a warp or weft yarn will appear on top at a particular cross over. Cross overs are arranged in 2d grid where the size of the grid depends on the number of warp and weft yarns created. To swap the positions of the weft and warp yarns, we call the function &amp;lt;code&amp;gt;SwapPosition&amp;lt;/code&amp;gt; with the grid coordinates of the cross over. In order to create a plain weave we need to do this on two diagonally opposite cross overs like so:&lt;br /&gt;
&lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
&lt;br /&gt;
Now let&amp;#039;s add our &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt; model to the database of models so that TexGen can render it:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Thats it! This is a very simple script but it will generate a plain weave model. To recap your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
 &lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Save it to disk as &amp;#039;&amp;#039;PlainWeave.py&amp;#039;&amp;#039; or give it whatever name you want as long as it has a &amp;#039;&amp;#039;.py&amp;#039;&amp;#039; extension.&lt;br /&gt;
&lt;br /&gt;
In order to test the Script we need to load it into TexGen. So start up the TexGen GUI and from the &amp;#039;&amp;#039;Python menu&amp;#039;&amp;#039; select &amp;#039;&amp;#039;Run Script&amp;#039;&amp;#039;. Select the file you have just saved and click ok. With a bit of luck you should see a 2d plain weave on screen:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Congratulations you have created your first TexGen Python script!&lt;br /&gt;
&lt;br /&gt;
===Example 2: Another plain weave (the hard way)===&lt;br /&gt;
In the first example we made use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; which is the reason the script is so compact. This was great for creating a 2D Weave, but what if we want to create something other than a 2D Weave? Well, let&amp;#039;s stick to the 2D weave for now but in this example we will create geometric model in a generic way without the use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class. This takes a little bit longer to do, but gives more control over the final geometry.&lt;br /&gt;
&lt;br /&gt;
First we will define a general textile and call it &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextile&amp;lt;/code&amp;gt; class doesn&amp;#039;t take any parameters, instead yarns will be created and added to it. Next we will create 4 yarns to go inside our textile, it is convenient to make use of the Python lists to do this. Create a list called &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; with 4 elements, each one an instance of the class &amp;lt;code&amp;gt;CYarn&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; now contains 4 empty yarns. Note that the yarns are not currently associated with the Textile, first we must fill in the details then make them a part of the textile. The first thing to do is define their paths with nodes. This is done like so:&lt;br /&gt;
&lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
&lt;br /&gt;
We have added 3 nodes to each yarn creating a woven pattern. The number in the square brackets after &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; refers to a particular yarn in the list. The function &amp;lt;code&amp;gt;AddNode&amp;lt;/code&amp;gt; is then called for the yarn. The function takes an instance of the class &amp;lt;code&amp;gt;CNode&amp;lt;/code&amp;gt; which in turn is constructed with an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; representing the position of the node. The class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers representing the X, Y and Z coordinates of the point.&lt;br /&gt;
&lt;br /&gt;
We still need to define a few more things to obtain a model. For the sake of simplicity, we will give all the yarns the same cross sectional shape, width, height, etc... The easiest way to do this is to loop over the yarns and assign the same properties to each yarn one by one. The syntax for looping over &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
&lt;br /&gt;
Inside the loop, the variable &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; refers to the current yarn in the list. So within the loop we just assign properties to &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; and they will be applied to all the yarns in the list. In python the begining and end of a loop are defined by indentation, hence the following lines are indented to represent the contents of the loop.&lt;br /&gt;
&lt;br /&gt;
Let us define periodic cubic spline interpolation between the nodes:&lt;br /&gt;
&lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
&lt;br /&gt;
This is done with the function &amp;lt;code&amp;gt;AssignInterpolation&amp;lt;/code&amp;gt; which takes an instance of a class derived from &amp;lt;code&amp;gt;CInterpolation&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CInterpolationCubic&amp;lt;/code&amp;gt; to specify periodic cubic spline interpolation.&lt;br /&gt;
&lt;br /&gt;
Next we need to define a cross section for the yarn, to keep things simple a constant cross section all along the length of the yarn will be defined:&lt;br /&gt;
&lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignSection&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CYarnSection&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CYarnSectionConstant&amp;lt;/code&amp;gt; which in turns take an instance of a class derived from &amp;lt;code&amp;gt;CSection&amp;lt;/code&amp;gt; as a constructor. &amp;lt;code&amp;gt;CSectionEllipse&amp;lt;/code&amp;gt; defines an elliptical cross section with given width and height defined by the first and second parameters respectively.&lt;br /&gt;
&lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
This line sets the resolution of the surface mesh created. The first parameter to the function &amp;lt;code&amp;gt;SetResolution&amp;lt;/code&amp;gt; represents the number of points around a cross section. The number of points along the length of the yarns is automatically calculated such that the distance between points is similar to around the cross section.&lt;br /&gt;
&lt;br /&gt;
Next we must add repeat vectors to define how the yarns are repeated.&lt;br /&gt;
&lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AddRepeat&amp;lt;/code&amp;gt; takes an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;. As we saw earlier the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers defining the X, Y and Z components.&lt;br /&gt;
&lt;br /&gt;
Finally the yarn is fully defined, it can now be added to &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
This is the end of the loop, hence the following lines return to the original indentation. Now let&amp;#039;s define a Domain within which the textile will be placed:&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignDomain&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CDomain&amp;lt;/code&amp;gt;. In this case we will create a box shaped domain, this can be accomplished by using the class &amp;lt;code&amp;gt;CDomainPlanes&amp;lt;/code&amp;gt;. A box can be created by passing in opposite corners of the box (the minimum and maximum coordinates). This is done again with the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And finally &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt; must be added to so that it can be rendered. Each Textile added must be assigned a name to identify it, this is the name that will appear at the top in the TexGen GUI. This name can either be generated automatically or we can specify it explicitly like so:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! You now have the knowledge to create any type of fabric imaginable. Well, almost. The model created here is pretty simple, there is plenty of oppertunity to create more complex shapes. For example non-constant cross sections can be defined, complex domain shapes defined by arbritrary planes, different interpolation functions.&lt;br /&gt;
&lt;br /&gt;
Here is the completed script:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
 &lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
 &lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
 &lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
 &lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
 &lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
 &lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
 &lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create a domain and assign it to the textile&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example2.png]]&lt;br /&gt;
&lt;br /&gt;
===Example 3: A 3d weave===&lt;br /&gt;
This example is similar to the [[Scripting Guide#Example 2: Another plain weave (the hard way)|Example 2]] in that the yarns will be defined by nodes. This time we will create a 3d woven fabric that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example3.png]]&lt;br /&gt;
&lt;br /&gt;
We start by defining a new CTextile instance:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
Before starting to define the geometry using TexGen it is helpful to define a list of parameters which may need to be changed later. These typically include spacing between yarns and yarn dimensions:&lt;br /&gt;
&lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
&lt;br /&gt;
It is a good idea to define these up front rather than hard coding them in the rest of the script because if you want to tweak any parameters they can easily be located and will only need to be changed once. Lets start by defining the warp stuffer yarns, these are fairly easy to define since they all straight and parallel to each other:&lt;br /&gt;
&lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Next we define the weft stuffer yarns, again these are easy to define:&lt;br /&gt;
&lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
And finally we need to insert the binder yarns. Making clever use of the repeat vectors it is only necessary to define a single instance of the binder yarn.&lt;br /&gt;
&lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Now that the geometry is defined we shall define a domain and add the textile so that TexGen knows about it.&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
The completed scripts is shown below:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
 &lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
===Saving to TG3 file format===&lt;br /&gt;
TexGen has it&amp;#039;s own file format for storing textile geometry with the extension .tg3. For more details on this file format please read the [[TG3 File Format]] page. Any textile models saved to this file format can be reloaded at a later time however it is also a good idea to keep the python script used to generate the geometry in case modifications need to be made. To save such a file it is simply a matter of adding an additional like at the end of your script like so:&lt;br /&gt;
&lt;br /&gt;
 SaveToXML(&amp;quot;MyTextile.tg3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The first parameter is the name of the file to save, note that if the .tg3 extension is omitted then it will automatically be appended for you. The second parameter is optional and if used should be the name of the textile to save, this is useful if you have several textiles loaded at once (i.e. you called AddTextile more than once) and you only want to save one of them. Note that if you don&amp;#039;t specify the second parameter and you do have several textiles loaded then it will save all of them to a single .tg3 file. The third parameter determines how much information is saved in the .tg3 file, see the [[TG3 File Format]] for more details.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:28:34Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Verification */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
Note that by adding this line does not prevent you from running your scripts through the GUI as well.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decided what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial section 7.2] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial section 7.1] and [http://docs.python.org/lib/typesseq-strings.html Python library reference 3.6.2] for more information on this.&lt;br /&gt;
&lt;br /&gt;
At this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points were written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it, you should now have a script which reads a TexGen tg3 file, extracts a mesh from it and writes the contents to a file in the VTK legacy file format. Your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&lt;br /&gt;
file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&lt;br /&gt;
# Get element information from the mesh&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&lt;br /&gt;
# Write the element information&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Verification==&lt;br /&gt;
&lt;br /&gt;
The first thing to do now is to run the script from the command line like so:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
replacing &amp;lt;code&amp;gt;myscript.py&amp;lt;/code&amp;gt; with the name of the script your created and ensuring you have a textile model named &amp;lt;code&amp;gt;textile.tg3&amp;lt;/code&amp;gt; in the some folder as the script. If it ran successfully you should see a file named &amp;lt;code&amp;gt;mesh.vtk&amp;lt;/code&amp;gt; being created. Load this up into [http://www.paraview.org/ ParaView] and you should see a mesh of your textile.&lt;br /&gt;
&lt;br /&gt;
When writing your own scripts it is unlikely that they will work straight away (even for professional programmers), so it is a good idea to check the output of your script at each step with a text editor to ensure that it is writing exactly what you want. This will enable you to isolate bugs early on and one at a time rather than having to fix a long script containing numerous bugs. The [http://docs.python.org/tut/node5.html#SECTION005200000000000000000 print statement] is your friend when it comes to debugging, it can be used to print out values and verify that they are what you expect.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:25:20Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
Note that by adding this line does not prevent you from running your scripts through the GUI as well.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decided what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial section 7.2] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial section 7.1] and [http://docs.python.org/lib/typesseq-strings.html Python library reference 3.6.2] for more information on this.&lt;br /&gt;
&lt;br /&gt;
At this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points were written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it, you should now have a script which reads a TexGen tg3 file, extracts a mesh from it and writes the contents to a file in the VTK legacy file format. Your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&lt;br /&gt;
file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&lt;br /&gt;
# Get element information from the mesh&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&lt;br /&gt;
# Write the element information&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Verification==&lt;br /&gt;
&lt;br /&gt;
The first thing to do now is to run the script from the command line like so:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
replacing &amp;lt;code&amp;gt;myscript.py&amp;lt;/code&amp;gt; with the name of the script your created and ensuring you have a textile model named &amp;lt;code&amp;gt;textile.tg3&amp;lt;/code&amp;gt; in the some folder as the script. If it ran successfully you should see a file named &amp;lt;code&amp;gt;mesh.vtk&amp;lt;/code&amp;gt; being created. Load this up into [http://www.paraview.org/ ParaView] and you should a mesh of your textile.&lt;br /&gt;
&lt;br /&gt;
When writing your own scripts it is likely that it will not work straight away, so it is a good idea to check the output of your script at each step with a text editor to ensure that it is writing exactly what you want. This will enable you to isolate bugs early on and one at a time rather than having to fix a long script contain numerous bugs. The [http://docs.python.org/tut/node5.html#SECTION005200000000000000000 print statement] is your friend when it comes to debugging, it can be used to print out values and verify that they are what you expect.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:14:58Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
Note that by adding this line does not prevent you from running your scripts through the GUI as well.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decided what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial section 7.2] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial section 7.1] and [http://docs.python.org/lib/typesseq-strings.html Python library reference 3.6.2] for more information on this.&lt;br /&gt;
&lt;br /&gt;
At this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points were written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it, you should now have a script which reads a TexGen tg3 file, extracts a mesh from it and writes the contents to a file in the VTK legacy file format. Your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&lt;br /&gt;
file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&lt;br /&gt;
# Get element information from the mesh&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&lt;br /&gt;
# Write the element information&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:13:20Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Writing the data to file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
Note that by adding this line does not prevent you from running your scripts through the GUI as well.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decided what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial section 7.2] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial section 7.1] and [http://docs.python.org/lib/typesseq-strings.html Python library reference 3.6.2] for more information on this.&lt;br /&gt;
&lt;br /&gt;
At this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points were written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it, you should now have a script which reads a TexGen tg3 file, extracts a mesh from it and writes the contents to a file in the VTK legacy file format.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:09:12Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Standalone scripts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
Note that by adding this line does not prevent you from running your scripts through the GUI as well.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decide what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial section 7.2] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial section 7.1] and [http://docs.python.org/lib/typesseq-strings.html Python library reference 3.6.2] for more information on this.&lt;br /&gt;
&lt;br /&gt;
It this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points where written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:07:23Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Writing the data to file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
You don&amp;#039;t need to do this if you go through the GUI because this step is done automatically for you. Note that by adding this line does not prevent you from running your scripts through the GUI.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decide what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial section 7.2] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial section 7.1] and [http://docs.python.org/lib/typesseq-strings.html Python library reference 3.6.2] for more information on this.&lt;br /&gt;
&lt;br /&gt;
It this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points where written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T11:05:46Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Writing the data to file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
You don&amp;#039;t need to do this if you go through the GUI because this step is done automatically for you. Note that by adding this line does not prevent you from running your scripts through the GUI.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decide what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial] and [http://docs.python.org/lib/typesseq-strings.html Python library reference] for more information on this.&lt;br /&gt;
&lt;br /&gt;
It this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points where written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here I have made use of slicing (wedgeIndices&amp;#039;&amp;#039;&amp;#039;[&amp;#039;&amp;#039;&amp;#039;i*6&amp;#039;&amp;#039;&amp;#039;:&amp;#039;&amp;#039;&amp;#039;(i+1)*6&amp;#039;&amp;#039;&amp;#039;]&amp;#039;&amp;#039;&amp;#039;) to reduce the amount of code necessary to output the data. See the [http://docs.python.org/tut/node5.html#SECTION005140000000000000000 Python tutorial section 3.1.4] for information about how slicing works.&lt;br /&gt;
&lt;br /&gt;
And finally we need to output the type of each of these elements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELL_TYPES %d\n&amp;quot; % (numWedges+numHexes))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;13\n&amp;quot;)&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;12\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The VTK file format defines wedges to be of element type 13 and hexes to be of element type 12.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T10:58:25Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Writing the data to file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
You don&amp;#039;t need to do this if you go through the GUI because this step is done automatically for you. Note that by adding this line does not prevent you from running your scripts through the GUI.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decide what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the header&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;DATASET UNSTRUCTURED_GRID\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation]. A mesh consists of a number of nodes (or points) and a number of elements (or cells). Each corner of an element is defined as an index into the list of points. An index of 0 refers to the first point, index 1 refers to the second and so on. So first of all we shall write the list of points to the file in the correct format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Write the points&lt;br /&gt;
file.write(&amp;quot;POINTS %d float\n&amp;quot; % mesh.GetNumNodes())&lt;br /&gt;
for node in mesh.GetNodes():&lt;br /&gt;
	file.write(&amp;quot;%g %g %g\n&amp;quot; % (node.x, node.y, node.z))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The % operator is known as the string formatting or interpolation operator. It is important to understand how this works when writing data to files in ASCII format. Read the [http://docs.python.org/tut/node9.html#SECTION009100000000000000000 Python tutorial] and [http://docs.python.org/lib/typesseq-strings.html Python library reference] for more information on this.&lt;br /&gt;
&lt;br /&gt;
It this point, if you run the script it should create a valid VTK file that you can load into the free [http://www.paraview.org/ ParaView] visualisation software. You may want to try this now to check that what you have done so far works correctly. Initially you will not see anything when loaded into ParaView because we have just defined points and nothing else. In order to visualise these points you must apply the Glyph filter. Assuming this works, let&amp;#039;s continue and write the elements.&lt;br /&gt;
&lt;br /&gt;
Defining the elements is a little more tricky because there are different types of elements. When meshing the yarns TexGen will use a mix of wedge and hexahedral elements, so we only need to deal with these element types. The [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] class stores a long list of indices for each element type. For example, a mesh containing 2 wedge elements and 3 hex elements would contain a list of 12 indices for the wedges and a list of 24 for the hex elements. The first thing to do is to define some variables to contain this data:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wedgeIndices = list(mesh.GetIndices(CMesh.WEDGE))&lt;br /&gt;
hexIndices = list(mesh.GetIndices(CMesh.HEX))&lt;br /&gt;
numWedges = len(wedgeIndices)/6&lt;br /&gt;
numHexes = len(hexIndices)/8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Next we actually write the data to the file similarly to the way the points where written:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;CELLS %d %d\n&amp;quot; % (numWedges+numHexes, numWedges*7+numHexes*9))&lt;br /&gt;
for i in range(numWedges):&lt;br /&gt;
	file.write(&amp;quot;6 %d %d %d %d %d %d\n&amp;quot; % tuple(wedgeIndices[i*6:(i+1)*6]))&lt;br /&gt;
for i in range(numHexes):&lt;br /&gt;
	file.write(&amp;quot;8 %d %d %d %d %d %d %d %d\n&amp;quot; % tuple(hexIndices[i*8:(i+1)*8]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T10:33:44Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Getting started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
You don&amp;#039;t need to do this if you go through the GUI because this step is done automatically for you. Note that by adding this line does not prevent you from running your scripts through the GUI.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh and trim the mesh to the domain&lt;br /&gt;
textile.AddVolumeToMesh(mesh, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decide what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation].&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T09:52:51Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Writing the data to file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
You don&amp;#039;t need to do this if you go through the GUI because this step is done automatically for you. Note that by adding this line does not prevent you from running your scripts through the GUI.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh&lt;br /&gt;
textile.AddVolumeToMesh(mesh)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decide what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial] for more details on writing to files in Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation].&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T09:51:39Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Getting started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
You don&amp;#039;t need to do this if you go through the GUI because this step is done automatically for you. Note that by adding this line does not prevent you from running your scripts through the GUI.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model. Let&amp;#039;s now extract a mesh for this textile, fortunately TexGen has some built-in functionality to do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Create a mesh instance&lt;br /&gt;
mesh = CMesh()&lt;br /&gt;
# Add the volume of the textile to the mesh&lt;br /&gt;
textile.AddVolumeToMesh(mesh)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We declare &amp;lt;code&amp;gt;mesh&amp;lt;/code&amp;gt; to be an instance of [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_mesh.html CMesh] and then use it to store a volume mesh of the textile. So with just a few lines of code we now have a volume mesh of the textile stored in memory. The problem we are now faced with is how do we transfer this mesh from memory to the hard disk in the file format that we want so that it can be understood by our software of choice? Read on to find out.&lt;br /&gt;
&lt;br /&gt;
==Defining the file format==&lt;br /&gt;
&lt;br /&gt;
In this example I will be showing you how to save to the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format]. I have chosen this file format because it is simple and well documented. Unfortunately, in a lot of cases, file formats are poorly documented (if at all) and are complex due to poor design.&lt;br /&gt;
&lt;br /&gt;
Note that TexGen already has a function to export to the VTK XML file format along with a number of other common file formats, and can be called in a single line of code like so: &amp;lt;code&amp;gt;mesh.SaveToVTK(&amp;quot;mesh.vtu&amp;quot;)&amp;lt;/code&amp;gt;. But in this tutorial I want to explain how to actually write the data out line by line so that you can hopefully translate that to any other file format of your choice.&lt;br /&gt;
&lt;br /&gt;
==Writing the data to file==&lt;br /&gt;
&lt;br /&gt;
Now that we have decide what format the data will be written in, let&amp;#039;s get down to actually writing it. First we will open a file for writing:&lt;br /&gt;
 file = open(&amp;quot;mesh.vtk&amp;quot;, &amp;quot;w&amp;quot;)&lt;br /&gt;
See the [http://docs.python.org/tut/node9.html#SECTION009200000000000000000 Python tutorial] for more details on reading/writing to files from Python. Next we need to write the header:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
file.write(&amp;quot;# vtk DataFile Version 2.0\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;Textile mesh data\n&amp;quot;)&lt;br /&gt;
file.write(&amp;quot;ASCII\n&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As defined in the [http://www.vtk.org/pdf/file-formats.pdf VTK legacy file format documentation].&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T09:21:35Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Export a mesh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a volume mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
You don&amp;#039;t need to do this if you go through the GUI because this step is done automatically for you. Note that by adding this line does not prevent you from running your scripts through the GUI.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T09:20:31Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Export a mesh */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;br /&gt;
&lt;br /&gt;
==Standalone scripts==&lt;br /&gt;
I am going to diverge a bit from this tutorial to talk about standalone scripts. In the previous guide it was assumed that the scripts you were writing would be run from within TexGen. However in some situations you may find it useful to simply run the scripts on their own from the command line without loading up the graphical user interface. In order to do this you must have installed [http://www.python.org/ Python] and installed the non-bundle version of TexGen (see [[Windows Installation]] for more details). To run your script you can then type the following from the command line:&lt;br /&gt;
&lt;br /&gt;
 python myscript.py&lt;br /&gt;
&lt;br /&gt;
However before your scripts will work on their own, you must import the TexGen modules at the start of your script. In order to do that simply add the following line to the top of your script:&lt;br /&gt;
&lt;br /&gt;
 from TexGen.Core import *&lt;br /&gt;
&lt;br /&gt;
You don&amp;#039;t need to do this if you go through the GUI because this step is done automatically for you. Note that by adding this line does not prevent you from running your scripts through the GUI.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to assume you already have a textile model you want to get a mesh of and have saved it to a .tg3 file named &amp;quot;textile.tg3&amp;quot;. So the first step is to load this model so that we can go about extracting a mesh from it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from TexGen.Core import *&lt;br /&gt;
# Read in the textile&lt;br /&gt;
ReadFromXML(&amp;#039;textile.tg3&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
# Get a hold of the textile we just loaded in&lt;br /&gt;
textile = GetTextile()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The variable &amp;lt;code&amp;gt;textile&amp;lt;/code&amp;gt; now contains an instance of the [http://texgen.sourceforge.net/api/class_tex_gen_1_1_c_textile.html CTextile] class representing the textile model.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Guide</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T08:48:50Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Saving to TG3 file format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Python Interface==&lt;br /&gt;
[http://www.python.org/ Python] is a high level interpreted programming language. In this case it is used as a scripting language to allow easy access to TexGen functionality. Python has been embedded in the TexGen GUI which allows the GUI to run python scripts. The goal of this tutorial is not to teach Python programming, there are plenty of resources online for that. A few of them are listed below:&lt;br /&gt;
&lt;br /&gt;
* [http://www.poromenos.org/tutorials/python Learn Python in 10 minutes] - Quick introduction to Python for competent programmers.&lt;br /&gt;
* [http://docs.python.org/tut/tut.html Python Tutorial] - Official Python tutorial (requires some programming knowledge).&lt;br /&gt;
* [http://www.greenteapress.com/thinkpython/ How to Think Like a Computer Scientist: Learning with Python] - Book on Python programming for beginners. [http://www.greenteapress.com/thinkpython/html/ HTML Version]&lt;br /&gt;
* [http://diveintopython.org/ Dive Into Python] - In depth book covering advanced subjects in a comprehensive manner. [http://diveintopython.org/toc/index.html HTML Version]&lt;br /&gt;
&lt;br /&gt;
An advanced knowledge of Python is not needed in order to write simple TexGen scripts. However, bear in mind that Python is a very powerful language with many libraries included for performing common tasks. I suggest you try to follow through the examples below and if you get stuck refer to one of the documents above.&lt;br /&gt;
&lt;br /&gt;
===Example 1: A plain weave===&lt;br /&gt;
First of all, a Python script is just a plain ASCII text file with a .py extension. To create one simply open up your favorite text editor. Notepad will do if you have nothing else but I suggest a more powerful freeware text editor like [http://www.pspad.com/ PSPad] or [http://notepad-plus.sourceforge.net/ Notepad++]. Code that goes into the python script will be displayed like so:&lt;br /&gt;
&lt;br /&gt;
 # All Python code will be shown in a box like this one.&lt;br /&gt;
 # Lines begining with a &amp;#039;#&amp;#039; character are comments&lt;br /&gt;
&lt;br /&gt;
In this example, we will create a simple 2x2 plain weave model with a Python script. Its time to dive in and see some actual Python code. At this point if you are completely lost please refer back to the resources on Python programming. The first step is to create an instance of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class and give it a name, &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class takes 5 parameters in the order shown below:&lt;br /&gt;
* Number of weft yarns in the unit cell&lt;br /&gt;
* Number of warp yarns in the unit cell&lt;br /&gt;
* Spacing between the yarns&lt;br /&gt;
* Thickness of the fabrics&lt;br /&gt;
* Refine model (True/False)&lt;br /&gt;
&lt;br /&gt;
The only parameter that really needs an explanation here is the Refine model option, this controls whether or not the interference correction algorithm will be applied to keep the yarn volumes from intersecting which is a common problem. The interference correction algorithm generally does a good job but is not instantaneous so sometimes it can be beneficial to switch it off.&lt;br /&gt;
&lt;br /&gt;
This is the bare minimum information necessary to create a 2D woven fabric. In the following steps we will add more information to create the model the way we want it.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s set the weave pattern, this determines whether a warp or weft yarn will appear on top at a particular cross over. Cross overs are arranged in 2d grid where the size of the grid depends on the number of warp and weft yarns created. To swap the positions of the weft and warp yarns, we call the function &amp;lt;code&amp;gt;SwapPosition&amp;lt;/code&amp;gt; with the grid coordinates of the cross over. In order to create a plain weave we need to do this on two diagonally opposite cross overs like so:&lt;br /&gt;
&lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
&lt;br /&gt;
Now let&amp;#039;s add our &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt; model to the database of models so that TexGen can render it:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Thats it! This is a very simple script but it will generate a plain weave model. To recap your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
 &lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Save it to disk as &amp;#039;&amp;#039;PlainWeave.py&amp;#039;&amp;#039; or give it whatever name you want as long as it has a &amp;#039;&amp;#039;.py&amp;#039;&amp;#039; extension.&lt;br /&gt;
&lt;br /&gt;
In order to test the Script we need to load it into TexGen. So start up the TexGen GUI and from the &amp;#039;&amp;#039;Python menu&amp;#039;&amp;#039; select &amp;#039;&amp;#039;Run Script&amp;#039;&amp;#039;. Select the file you have just saved and click ok. With a bit of luck you should see a 2d plain weave on screen:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Congratulations you have created your first TexGen Python script!&lt;br /&gt;
&lt;br /&gt;
===Example 2: Another plain weave (the hard way)===&lt;br /&gt;
In the first example we made use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; which is the reason the script is so compact. This was great for creating a 2D Weave, but what if we want to create something other than a 2D Weave? Well, let&amp;#039;s stick to the 2D weave for now but in this example we will create geometric model in a generic way without the use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class. This takes a little bit longer to do, but gives more control over the final geometry.&lt;br /&gt;
&lt;br /&gt;
First we will define a general textile and call it &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextile&amp;lt;/code&amp;gt; class doesn&amp;#039;t take any parameters, instead yarns will be created and added to it. Next we will create 4 yarns to go inside our textile, it is convenient to make use of the Python lists to do this. Create a list called &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; with 4 elements, each one an instance of the class &amp;lt;code&amp;gt;CYarn&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; now contains 4 empty yarns. Note that the yarns are not currently associated with the Textile, first we must fill in the details then make them a part of the textile. The first thing to do is define their paths with nodes. This is done like so:&lt;br /&gt;
&lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
&lt;br /&gt;
We have added 3 nodes to each yarn creating a woven pattern. The number in the square brackets after &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; refers to a particular yarn in the list. The function &amp;lt;code&amp;gt;AddNode&amp;lt;/code&amp;gt; is then called for the yarn. The function takes an instance of the class &amp;lt;code&amp;gt;CNode&amp;lt;/code&amp;gt; which in turn is constructed with an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; representing the position of the node. The class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers representing the X, Y and Z coordinates of the point.&lt;br /&gt;
&lt;br /&gt;
We still need to define a few more things to obtain a model. For the sake of simplicity, we will give all the yarns the same cross sectional shape, width, height, etc... The easiest way to do this is to loop over the yarns and assign the same properties to each yarn one by one. The syntax for looping over &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
&lt;br /&gt;
Inside the loop, the variable &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; refers to the current yarn in the list. So within the loop we just assign properties to &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; and they will be applied to all the yarns in the list. In python the begining and end of a loop are defined by indentation, hence the following lines are indented to represent the contents of the loop.&lt;br /&gt;
&lt;br /&gt;
Let us define periodic cubic spline interpolation between the nodes:&lt;br /&gt;
&lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
&lt;br /&gt;
This is done with the function &amp;lt;code&amp;gt;AssignInterpolation&amp;lt;/code&amp;gt; which takes an instance of a class derived from &amp;lt;code&amp;gt;CInterpolation&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CInterpolationCubic&amp;lt;/code&amp;gt; to specify periodic cubic spline interpolation.&lt;br /&gt;
&lt;br /&gt;
Next we need to define a cross section for the yarn, to keep things simple a constant cross section all along the length of the yarn will be defined:&lt;br /&gt;
&lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignSection&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CYarnSection&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CYarnSectionConstant&amp;lt;/code&amp;gt; which in turns take an instance of a class derived from &amp;lt;code&amp;gt;CSection&amp;lt;/code&amp;gt; as a constructor. &amp;lt;code&amp;gt;CSectionEllipse&amp;lt;/code&amp;gt; defines an elliptical cross section with given width and height defined by the first and second parameters respectively.&lt;br /&gt;
&lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
This line sets the resolution of the surface mesh created. The first parameter to the function &amp;lt;code&amp;gt;SetResolution&amp;lt;/code&amp;gt; represents the number of points around a cross section. The number of points along the length of the yarns is automatically calculated such that the distance between points is similar to around the cross section.&lt;br /&gt;
&lt;br /&gt;
Next we must add repeat vectors to define how the yarns are repeated.&lt;br /&gt;
&lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AddRepeat&amp;lt;/code&amp;gt; takes an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;. As we saw earlier the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers defining the X, Y and Z components.&lt;br /&gt;
&lt;br /&gt;
Finally the yarn is fully defined, it can now be added to &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
This is the end of the loop, hence the following lines return to the original indentation. Now let&amp;#039;s define a Domain within which the textile will be placed:&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignDomain&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CDomain&amp;lt;/code&amp;gt;. In this case we will create a box shaped domain, this can be accomplished by using the class &amp;lt;code&amp;gt;CDomainPlanes&amp;lt;/code&amp;gt;. A box can be created by passing in opposite corners of the box (the minimum and maximum coordinates). This is done again with the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And finally &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt; must be added to so that it can be rendered. Each Textile added must be assigned a name to identify it, this is the name that will appear at the top in the TexGen GUI. This name can either be generated automatically or we can specify it explicitly like so:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! You now have the knowledge to create any type of fabric imaginable. Well, almost. The model created here is pretty simple, there is plenty of oppertunity to create more complex shapes. For example non-constant cross sections can be defined, complex domain shapes defined by arbritrary planes, different interpolation functions.&lt;br /&gt;
&lt;br /&gt;
Here is the completed script:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
 &lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
 &lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
 &lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
 &lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
 &lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
 &lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
 &lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create a domain and assign it to the textile&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example2.png]]&lt;br /&gt;
&lt;br /&gt;
===Example 3: A 3d weave===&lt;br /&gt;
This example is similar to the [[Scripting Guide#Example 2: Another plain weave (the hard way)|Example 2]] in that the yarns will be defined by nodes. This time we will create a 3d woven fabric that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example3.png]]&lt;br /&gt;
&lt;br /&gt;
We start by defining a new CTextile instance:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
Before starting to define the geometry using TexGen it is helpful to define a list of parameters which may need to be changed later. These typically include spacing between yarns and yarn dimensions:&lt;br /&gt;
&lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
&lt;br /&gt;
It is a good idea to define these up front rather than hard coding them in the rest of the script because if you want to tweak any parameters they can easily be located and will only need to be changed once. Lets start by defining the warp stuffer yarns, these are fairly easy to define since they all straight and parallel to each other:&lt;br /&gt;
&lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Next we define the weft stuffer yarns, again these are easy to define:&lt;br /&gt;
&lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
And finally we need to insert the binder yarns. Making clever use of the repeat vectors it is only necessary to define a single instance of the binder yarn.&lt;br /&gt;
&lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Now that the geometry is defined we shall define a domain and add the textile so that TexGen knows about it.&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
The completed scripts is shown below:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
 &lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
===Saving to TG3 file format===&lt;br /&gt;
TexGen has it&amp;#039;s own file format for storing textile geometry with the extension .tg3. For more details on this file format please read the [[TG3 File Format]] page. Any textile models saved to this file format can be reloaded at a later time however it is also a good idea to keep the python script used to generate the geometry in case modifications need to be made. To save such a file it is simply a matter of adding an additional like at the end of your script like so:&lt;br /&gt;
&lt;br /&gt;
 SaveToXML(&amp;quot;MyTextile.tg3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The first parameter is the name of the file to save, note that if the .tg3 extension is omitted then it will automatically be appended for you. The second parameter is optional and if used should be the name of the textile to save, this is useful if you have several textiles loaded at once (i.e. you called AddTextile more than once) and you only want to save one of them. Note that if you don&amp;#039;t specify the second parameter and you do have several textiles loaded then it will save all of them to a single .tg3 file. The third parameter determines how much information is saved in the .tg3 file, see the [[TG3 File Format]] for more details.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Guide</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T08:45:42Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Saving to TG3 file format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Python Interface==&lt;br /&gt;
[http://www.python.org/ Python] is a high level interpreted programming language. In this case it is used as a scripting language to allow easy access to TexGen functionality. Python has been embedded in the TexGen GUI which allows the GUI to run python scripts. The goal of this tutorial is not to teach Python programming, there are plenty of resources online for that. A few of them are listed below:&lt;br /&gt;
&lt;br /&gt;
* [http://www.poromenos.org/tutorials/python Learn Python in 10 minutes] - Quick introduction to Python for competent programmers.&lt;br /&gt;
* [http://docs.python.org/tut/tut.html Python Tutorial] - Official Python tutorial (requires some programming knowledge).&lt;br /&gt;
* [http://www.greenteapress.com/thinkpython/ How to Think Like a Computer Scientist: Learning with Python] - Book on Python programming for beginners. [http://www.greenteapress.com/thinkpython/html/ HTML Version]&lt;br /&gt;
* [http://diveintopython.org/ Dive Into Python] - In depth book covering advanced subjects in a comprehensive manner. [http://diveintopython.org/toc/index.html HTML Version]&lt;br /&gt;
&lt;br /&gt;
An advanced knowledge of Python is not needed in order to write simple TexGen scripts. However, bear in mind that Python is a very powerful language with many libraries included for performing common tasks. I suggest you try to follow through the examples below and if you get stuck refer to one of the documents above.&lt;br /&gt;
&lt;br /&gt;
===Example 1: A plain weave===&lt;br /&gt;
First of all, a Python script is just a plain ASCII text file with a .py extension. To create one simply open up your favorite text editor. Notepad will do if you have nothing else but I suggest a more powerful freeware text editor like [http://www.pspad.com/ PSPad] or [http://notepad-plus.sourceforge.net/ Notepad++]. Code that goes into the python script will be displayed like so:&lt;br /&gt;
&lt;br /&gt;
 # All Python code will be shown in a box like this one.&lt;br /&gt;
 # Lines begining with a &amp;#039;#&amp;#039; character are comments&lt;br /&gt;
&lt;br /&gt;
In this example, we will create a simple 2x2 plain weave model with a Python script. Its time to dive in and see some actual Python code. At this point if you are completely lost please refer back to the resources on Python programming. The first step is to create an instance of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class and give it a name, &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class takes 5 parameters in the order shown below:&lt;br /&gt;
* Number of weft yarns in the unit cell&lt;br /&gt;
* Number of warp yarns in the unit cell&lt;br /&gt;
* Spacing between the yarns&lt;br /&gt;
* Thickness of the fabrics&lt;br /&gt;
* Refine model (True/False)&lt;br /&gt;
&lt;br /&gt;
The only parameter that really needs an explanation here is the Refine model option, this controls whether or not the interference correction algorithm will be applied to keep the yarn volumes from intersecting which is a common problem. The interference correction algorithm generally does a good job but is not instantaneous so sometimes it can be beneficial to switch it off.&lt;br /&gt;
&lt;br /&gt;
This is the bare minimum information necessary to create a 2D woven fabric. In the following steps we will add more information to create the model the way we want it.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s set the weave pattern, this determines whether a warp or weft yarn will appear on top at a particular cross over. Cross overs are arranged in 2d grid where the size of the grid depends on the number of warp and weft yarns created. To swap the positions of the weft and warp yarns, we call the function &amp;lt;code&amp;gt;SwapPosition&amp;lt;/code&amp;gt; with the grid coordinates of the cross over. In order to create a plain weave we need to do this on two diagonally opposite cross overs like so:&lt;br /&gt;
&lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
&lt;br /&gt;
Now let&amp;#039;s add our &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt; model to the database of models so that TexGen can render it:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Thats it! This is a very simple script but it will generate a plain weave model. To recap your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
 &lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Save it to disk as &amp;#039;&amp;#039;PlainWeave.py&amp;#039;&amp;#039; or give it whatever name you want as long as it has a &amp;#039;&amp;#039;.py&amp;#039;&amp;#039; extension.&lt;br /&gt;
&lt;br /&gt;
In order to test the Script we need to load it into TexGen. So start up the TexGen GUI and from the &amp;#039;&amp;#039;Python menu&amp;#039;&amp;#039; select &amp;#039;&amp;#039;Run Script&amp;#039;&amp;#039;. Select the file you have just saved and click ok. With a bit of luck you should see a 2d plain weave on screen:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Congratulations you have created your first TexGen Python script!&lt;br /&gt;
&lt;br /&gt;
===Example 2: Another plain weave (the hard way)===&lt;br /&gt;
In the first example we made use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; which is the reason the script is so compact. This was great for creating a 2D Weave, but what if we want to create something other than a 2D Weave? Well, let&amp;#039;s stick to the 2D weave for now but in this example we will create geometric model in a generic way without the use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class. This takes a little bit longer to do, but gives more control over the final geometry.&lt;br /&gt;
&lt;br /&gt;
First we will define a general textile and call it &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextile&amp;lt;/code&amp;gt; class doesn&amp;#039;t take any parameters, instead yarns will be created and added to it. Next we will create 4 yarns to go inside our textile, it is convenient to make use of the Python lists to do this. Create a list called &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; with 4 elements, each one an instance of the class &amp;lt;code&amp;gt;CYarn&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; now contains 4 empty yarns. Note that the yarns are not currently associated with the Textile, first we must fill in the details then make them a part of the textile. The first thing to do is define their paths with nodes. This is done like so:&lt;br /&gt;
&lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
&lt;br /&gt;
We have added 3 nodes to each yarn creating a woven pattern. The number in the square brackets after &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; refers to a particular yarn in the list. The function &amp;lt;code&amp;gt;AddNode&amp;lt;/code&amp;gt; is then called for the yarn. The function takes an instance of the class &amp;lt;code&amp;gt;CNode&amp;lt;/code&amp;gt; which in turn is constructed with an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; representing the position of the node. The class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers representing the X, Y and Z coordinates of the point.&lt;br /&gt;
&lt;br /&gt;
We still need to define a few more things to obtain a model. For the sake of simplicity, we will give all the yarns the same cross sectional shape, width, height, etc... The easiest way to do this is to loop over the yarns and assign the same properties to each yarn one by one. The syntax for looping over &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
&lt;br /&gt;
Inside the loop, the variable &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; refers to the current yarn in the list. So within the loop we just assign properties to &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; and they will be applied to all the yarns in the list. In python the begining and end of a loop are defined by indentation, hence the following lines are indented to represent the contents of the loop.&lt;br /&gt;
&lt;br /&gt;
Let us define periodic cubic spline interpolation between the nodes:&lt;br /&gt;
&lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
&lt;br /&gt;
This is done with the function &amp;lt;code&amp;gt;AssignInterpolation&amp;lt;/code&amp;gt; which takes an instance of a class derived from &amp;lt;code&amp;gt;CInterpolation&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CInterpolationCubic&amp;lt;/code&amp;gt; to specify periodic cubic spline interpolation.&lt;br /&gt;
&lt;br /&gt;
Next we need to define a cross section for the yarn, to keep things simple a constant cross section all along the length of the yarn will be defined:&lt;br /&gt;
&lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignSection&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CYarnSection&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CYarnSectionConstant&amp;lt;/code&amp;gt; which in turns take an instance of a class derived from &amp;lt;code&amp;gt;CSection&amp;lt;/code&amp;gt; as a constructor. &amp;lt;code&amp;gt;CSectionEllipse&amp;lt;/code&amp;gt; defines an elliptical cross section with given width and height defined by the first and second parameters respectively.&lt;br /&gt;
&lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
This line sets the resolution of the surface mesh created. The first parameter to the function &amp;lt;code&amp;gt;SetResolution&amp;lt;/code&amp;gt; represents the number of points around a cross section. The number of points along the length of the yarns is automatically calculated such that the distance between points is similar to around the cross section.&lt;br /&gt;
&lt;br /&gt;
Next we must add repeat vectors to define how the yarns are repeated.&lt;br /&gt;
&lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AddRepeat&amp;lt;/code&amp;gt; takes an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;. As we saw earlier the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers defining the X, Y and Z components.&lt;br /&gt;
&lt;br /&gt;
Finally the yarn is fully defined, it can now be added to &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
This is the end of the loop, hence the following lines return to the original indentation. Now let&amp;#039;s define a Domain within which the textile will be placed:&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignDomain&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CDomain&amp;lt;/code&amp;gt;. In this case we will create a box shaped domain, this can be accomplished by using the class &amp;lt;code&amp;gt;CDomainPlanes&amp;lt;/code&amp;gt;. A box can be created by passing in opposite corners of the box (the minimum and maximum coordinates). This is done again with the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And finally &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt; must be added to so that it can be rendered. Each Textile added must be assigned a name to identify it, this is the name that will appear at the top in the TexGen GUI. This name can either be generated automatically or we can specify it explicitly like so:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! You now have the knowledge to create any type of fabric imaginable. Well, almost. The model created here is pretty simple, there is plenty of oppertunity to create more complex shapes. For example non-constant cross sections can be defined, complex domain shapes defined by arbritrary planes, different interpolation functions.&lt;br /&gt;
&lt;br /&gt;
Here is the completed script:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
 &lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
 &lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
 &lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
 &lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
 &lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
 &lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
 &lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create a domain and assign it to the textile&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example2.png]]&lt;br /&gt;
&lt;br /&gt;
===Example 3: A 3d weave===&lt;br /&gt;
This example is similar to the [[Scripting Guide#Example 2: Another plain weave (the hard way)|Example 2]] in that the yarns will be defined by nodes. This time we will create a 3d woven fabric that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example3.png]]&lt;br /&gt;
&lt;br /&gt;
We start by defining a new CTextile instance:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
Before starting to define the geometry using TexGen it is helpful to define a list of parameters which may need to be changed later. These typically include spacing between yarns and yarn dimensions:&lt;br /&gt;
&lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
&lt;br /&gt;
It is a good idea to define these up front rather than hard coding them in the rest of the script because if you want to tweak any parameters they can easily be located and will only need to be changed once. Lets start by defining the warp stuffer yarns, these are fairly easy to define since they all straight and parallel to each other:&lt;br /&gt;
&lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Next we define the weft stuffer yarns, again these are easy to define:&lt;br /&gt;
&lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
And finally we need to insert the binder yarns. Making clever use of the repeat vectors it is only necessary to define a single instance of the binder yarn.&lt;br /&gt;
&lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Now that the geometry is defined we shall define a domain and add the textile so that TexGen knows about it.&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
The completed scripts is shown below:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
 &lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
===Saving to TG3 file format===&lt;br /&gt;
TexGen has it&amp;#039;s own file format for storing textile geometry with the extension .TG3. For more details on this file format please read the [[TG3 File Format]] page. Any textile models saved to this file format can be reloaded at a later time however it is also a good idea to keep the python script used to generate the geometry in case modifications need to be made. To save such a file it is simply a matter of adding an additional like at the end of your script like so:&lt;br /&gt;
&lt;br /&gt;
 SaveToXML(&amp;quot;MyTextile.tg3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The first parameter is the name of the file to save, note that if the .tg3 extension is omitted then it will automatically be appended for you. The second parameter is optional and if used should be the name of the textile to save, this is useful if you have several textiles loaded at once (i.e. you called AddTextile more than once) and you only want to save one of them. Note that if you don&amp;#039;t specify the second parameter and you do have several textiles loaded then it will save all of them. The third parameter determines how much information is saved in the .tg3 file, see the [[TG3 File Format]] for more details.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Guide</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-15T08:44:48Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Python Interface==&lt;br /&gt;
[http://www.python.org/ Python] is a high level interpreted programming language. In this case it is used as a scripting language to allow easy access to TexGen functionality. Python has been embedded in the TexGen GUI which allows the GUI to run python scripts. The goal of this tutorial is not to teach Python programming, there are plenty of resources online for that. A few of them are listed below:&lt;br /&gt;
&lt;br /&gt;
* [http://www.poromenos.org/tutorials/python Learn Python in 10 minutes] - Quick introduction to Python for competent programmers.&lt;br /&gt;
* [http://docs.python.org/tut/tut.html Python Tutorial] - Official Python tutorial (requires some programming knowledge).&lt;br /&gt;
* [http://www.greenteapress.com/thinkpython/ How to Think Like a Computer Scientist: Learning with Python] - Book on Python programming for beginners. [http://www.greenteapress.com/thinkpython/html/ HTML Version]&lt;br /&gt;
* [http://diveintopython.org/ Dive Into Python] - In depth book covering advanced subjects in a comprehensive manner. [http://diveintopython.org/toc/index.html HTML Version]&lt;br /&gt;
&lt;br /&gt;
An advanced knowledge of Python is not needed in order to write simple TexGen scripts. However, bear in mind that Python is a very powerful language with many libraries included for performing common tasks. I suggest you try to follow through the examples below and if you get stuck refer to one of the documents above.&lt;br /&gt;
&lt;br /&gt;
===Example 1: A plain weave===&lt;br /&gt;
First of all, a Python script is just a plain ASCII text file with a .py extension. To create one simply open up your favorite text editor. Notepad will do if you have nothing else but I suggest a more powerful freeware text editor like [http://www.pspad.com/ PSPad] or [http://notepad-plus.sourceforge.net/ Notepad++]. Code that goes into the python script will be displayed like so:&lt;br /&gt;
&lt;br /&gt;
 # All Python code will be shown in a box like this one.&lt;br /&gt;
 # Lines begining with a &amp;#039;#&amp;#039; character are comments&lt;br /&gt;
&lt;br /&gt;
In this example, we will create a simple 2x2 plain weave model with a Python script. Its time to dive in and see some actual Python code. At this point if you are completely lost please refer back to the resources on Python programming. The first step is to create an instance of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class and give it a name, &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class takes 5 parameters in the order shown below:&lt;br /&gt;
* Number of weft yarns in the unit cell&lt;br /&gt;
* Number of warp yarns in the unit cell&lt;br /&gt;
* Spacing between the yarns&lt;br /&gt;
* Thickness of the fabrics&lt;br /&gt;
* Refine model (True/False)&lt;br /&gt;
&lt;br /&gt;
The only parameter that really needs an explanation here is the Refine model option, this controls whether or not the interference correction algorithm will be applied to keep the yarn volumes from intersecting which is a common problem. The interference correction algorithm generally does a good job but is not instantaneous so sometimes it can be beneficial to switch it off.&lt;br /&gt;
&lt;br /&gt;
This is the bare minimum information necessary to create a 2D woven fabric. In the following steps we will add more information to create the model the way we want it.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s set the weave pattern, this determines whether a warp or weft yarn will appear on top at a particular cross over. Cross overs are arranged in 2d grid where the size of the grid depends on the number of warp and weft yarns created. To swap the positions of the weft and warp yarns, we call the function &amp;lt;code&amp;gt;SwapPosition&amp;lt;/code&amp;gt; with the grid coordinates of the cross over. In order to create a plain weave we need to do this on two diagonally opposite cross overs like so:&lt;br /&gt;
&lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
&lt;br /&gt;
Now let&amp;#039;s add our &amp;lt;code&amp;gt;weave&amp;lt;/code&amp;gt; model to the database of models so that TexGen can render it:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Thats it! This is a very simple script but it will generate a plain weave model. To recap your Python script should look like this:&lt;br /&gt;
&lt;br /&gt;
 # Create a 2D weave textile&lt;br /&gt;
 weave = CTextileWeave2D(2, 2, 1, 0.2, True)&lt;br /&gt;
 &lt;br /&gt;
 # Set the weave pattern&lt;br /&gt;
 weave.SwapPosition(0, 0)&lt;br /&gt;
 weave.SwapPosition(1, 1)&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile&lt;br /&gt;
 AddTextile(weave)&lt;br /&gt;
&lt;br /&gt;
Save it to disk as &amp;#039;&amp;#039;PlainWeave.py&amp;#039;&amp;#039; or give it whatever name you want as long as it has a &amp;#039;&amp;#039;.py&amp;#039;&amp;#039; extension.&lt;br /&gt;
&lt;br /&gt;
In order to test the Script we need to load it into TexGen. So start up the TexGen GUI and from the &amp;#039;&amp;#039;Python menu&amp;#039;&amp;#039; select &amp;#039;&amp;#039;Run Script&amp;#039;&amp;#039;. Select the file you have just saved and click ok. With a bit of luck you should see a 2d plain weave on screen:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example1.png]]&lt;br /&gt;
&lt;br /&gt;
Congratulations you have created your first TexGen Python script!&lt;br /&gt;
&lt;br /&gt;
===Example 2: Another plain weave (the hard way)===&lt;br /&gt;
In the first example we made use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; which is the reason the script is so compact. This was great for creating a 2D Weave, but what if we want to create something other than a 2D Weave? Well, let&amp;#039;s stick to the 2D weave for now but in this example we will create geometric model in a generic way without the use of the &amp;lt;code&amp;gt;CTextileWeave2D&amp;lt;/code&amp;gt; class. This takes a little bit longer to do, but gives more control over the final geometry.&lt;br /&gt;
&lt;br /&gt;
First we will define a general textile and call it &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;CTextile&amp;lt;/code&amp;gt; class doesn&amp;#039;t take any parameters, instead yarns will be created and added to it. Next we will create 4 yarns to go inside our textile, it is convenient to make use of the Python lists to do this. Create a list called &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; with 4 elements, each one an instance of the class &amp;lt;code&amp;gt;CYarn&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; now contains 4 empty yarns. Note that the yarns are not currently associated with the Textile, first we must fill in the details then make them a part of the textile. The first thing to do is define their paths with nodes. This is done like so:&lt;br /&gt;
&lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
&lt;br /&gt;
We have added 3 nodes to each yarn creating a woven pattern. The number in the square brackets after &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; refers to a particular yarn in the list. The function &amp;lt;code&amp;gt;AddNode&amp;lt;/code&amp;gt; is then called for the yarn. The function takes an instance of the class &amp;lt;code&amp;gt;CNode&amp;lt;/code&amp;gt; which in turn is constructed with an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; representing the position of the node. The class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers representing the X, Y and Z coordinates of the point.&lt;br /&gt;
&lt;br /&gt;
We still need to define a few more things to obtain a model. For the sake of simplicity, we will give all the yarns the same cross sectional shape, width, height, etc... The easiest way to do this is to loop over the yarns and assign the same properties to each yarn one by one. The syntax for looping over &amp;lt;code&amp;gt;Yarns&amp;lt;/code&amp;gt; is shown here:&lt;br /&gt;
&lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
&lt;br /&gt;
Inside the loop, the variable &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; refers to the current yarn in the list. So within the loop we just assign properties to &amp;lt;code&amp;gt;Yarn&amp;lt;/code&amp;gt; and they will be applied to all the yarns in the list. In python the begining and end of a loop are defined by indentation, hence the following lines are indented to represent the contents of the loop.&lt;br /&gt;
&lt;br /&gt;
Let us define periodic cubic spline interpolation between the nodes:&lt;br /&gt;
&lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
&lt;br /&gt;
This is done with the function &amp;lt;code&amp;gt;AssignInterpolation&amp;lt;/code&amp;gt; which takes an instance of a class derived from &amp;lt;code&amp;gt;CInterpolation&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CInterpolationCubic&amp;lt;/code&amp;gt; to specify periodic cubic spline interpolation.&lt;br /&gt;
&lt;br /&gt;
Next we need to define a cross section for the yarn, to keep things simple a constant cross section all along the length of the yarn will be defined:&lt;br /&gt;
&lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignSection&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CYarnSection&amp;lt;/code&amp;gt;. In this case we used &amp;lt;code&amp;gt;CYarnSectionConstant&amp;lt;/code&amp;gt; which in turns take an instance of a class derived from &amp;lt;code&amp;gt;CSection&amp;lt;/code&amp;gt; as a constructor. &amp;lt;code&amp;gt;CSectionEllipse&amp;lt;/code&amp;gt; defines an elliptical cross section with given width and height defined by the first and second parameters respectively.&lt;br /&gt;
&lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
&lt;br /&gt;
This line sets the resolution of the surface mesh created. The first parameter to the function &amp;lt;code&amp;gt;SetResolution&amp;lt;/code&amp;gt; represents the number of points around a cross section. The number of points along the length of the yarns is automatically calculated such that the distance between points is similar to around the cross section.&lt;br /&gt;
&lt;br /&gt;
Next we must add repeat vectors to define how the yarns are repeated.&lt;br /&gt;
&lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AddRepeat&amp;lt;/code&amp;gt; takes an instance of the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;. As we saw earlier the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt; is constructed with 3 numbers defining the X, Y and Z components.&lt;br /&gt;
&lt;br /&gt;
Finally the yarn is fully defined, it can now be added to &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
&lt;br /&gt;
This is the end of the loop, hence the following lines return to the original indentation. Now let&amp;#039;s define a Domain within which the textile will be placed:&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;AssignDomain&amp;lt;/code&amp;gt; takes an instance of a class derived from &amp;lt;code&amp;gt;CDomain&amp;lt;/code&amp;gt;. In this case we will create a box shaped domain, this can be accomplished by using the class &amp;lt;code&amp;gt;CDomainPlanes&amp;lt;/code&amp;gt;. A box can be created by passing in opposite corners of the box (the minimum and maximum coordinates). This is done again with the class &amp;lt;code&amp;gt;XYZ&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
And finally &amp;lt;code&amp;gt;Textile&amp;lt;/code&amp;gt; must be added to so that it can be rendered. Each Textile added must be assigned a name to identify it, this is the name that will appear at the top in the TexGen GUI. This name can either be generated automatically or we can specify it explicitly like so:&lt;br /&gt;
&lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it! You now have the knowledge to create any type of fabric imaginable. Well, almost. The model created here is pretty simple, there is plenty of oppertunity to create more complex shapes. For example non-constant cross sections can be defined, complex domain shapes defined by arbritrary planes, different interpolation functions.&lt;br /&gt;
&lt;br /&gt;
Here is the completed script:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Create a python list containing 4 yarns&lt;br /&gt;
 Yarns = [CYarn(), CYarn(), CYarn(), CYarn()]&lt;br /&gt;
 &lt;br /&gt;
 # Add nodes to the yarns to describe their paths&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0, 0, 0)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.22, 0, 0.05)))&lt;br /&gt;
 Yarns[0].AddNode(CNode(XYZ(0.44, 0, 0)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0, 0.22, 0.05)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.22, 0.22, 0)))&lt;br /&gt;
 Yarns[1].AddNode(CNode(XYZ(0.44, 0.22, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0, 0.05)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.22, 0)))&lt;br /&gt;
 Yarns[2].AddNode(CNode(XYZ(0, 0.44, 0.05)))&lt;br /&gt;
 &lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0, 0)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.22, 0.05)))&lt;br /&gt;
 Yarns[3].AddNode(CNode(XYZ(0.22, 0.44, 0)))&lt;br /&gt;
 &lt;br /&gt;
 # Loop over all the yarns in the list&lt;br /&gt;
 for Yarn in Yarns:&lt;br /&gt;
 &lt;br /&gt;
     # Set the interpolation function&lt;br /&gt;
     Yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
 &lt;br /&gt;
     # Assign a constant cross-section all along the yarn of elliptical shape&lt;br /&gt;
     Yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(0.18, 0.04)))&lt;br /&gt;
 &lt;br /&gt;
     # Set the resolution of the surface mesh created&lt;br /&gt;
     Yarn.SetResolution(20)&lt;br /&gt;
 &lt;br /&gt;
     # Add repeat vectors to the yarn&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0.44, 0, 0))&lt;br /&gt;
     Yarn.AddRepeat(XYZ(0, 0.44, 0))&lt;br /&gt;
 &lt;br /&gt;
     # Add the yarn to our textile&lt;br /&gt;
     Textile.AddYarn(Yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create a domain and assign it to the textile&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.02), XYZ(0.44, 0.44, 0.07)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile with the name &amp;quot;polyester&amp;quot;&lt;br /&gt;
 AddTextile(&amp;quot;polyester&amp;quot;, Textile)&lt;br /&gt;
&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example2.png]]&lt;br /&gt;
&lt;br /&gt;
===Example 3: A 3d weave===&lt;br /&gt;
This example is similar to the [[Scripting Guide#Example 2: Another plain weave (the hard way)|Example 2]] in that the yarns will be defined by nodes. This time we will create a 3d woven fabric that looks like this:&lt;br /&gt;
&lt;br /&gt;
[[Image:Example3.png]]&lt;br /&gt;
&lt;br /&gt;
We start by defining a new CTextile instance:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
&lt;br /&gt;
Before starting to define the geometry using TexGen it is helpful to define a list of parameters which may need to be changed later. These typically include spacing between yarns and yarn dimensions:&lt;br /&gt;
&lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
&lt;br /&gt;
It is a good idea to define these up front rather than hard coding them in the rest of the script because if you want to tweak any parameters they can easily be located and will only need to be changed once. Lets start by defining the warp stuffer yarns, these are fairly easy to define since they all straight and parallel to each other:&lt;br /&gt;
&lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Next we define the weft stuffer yarns, again these are easy to define:&lt;br /&gt;
&lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
And finally we need to insert the binder yarns. Making clever use of the repeat vectors it is only necessary to define a single instance of the binder yarn.&lt;br /&gt;
&lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
&lt;br /&gt;
Now that the geometry is defined we shall define a domain and add the textile so that TexGen knows about it.&lt;br /&gt;
&lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
The completed scripts is shown below:&lt;br /&gt;
&lt;br /&gt;
 # Create a textile&lt;br /&gt;
 Textile = CTextile()&lt;br /&gt;
 &lt;br /&gt;
 # Define some parameters&lt;br /&gt;
 # Spacing between weft yarns&lt;br /&gt;
 sx = 2&lt;br /&gt;
 # Spacing between warp yarns&lt;br /&gt;
 sy = 0.8&lt;br /&gt;
 # Vertical distance between yarns at cross overs&lt;br /&gt;
 sz = 0.16&lt;br /&gt;
 &lt;br /&gt;
 # Width of the weft yarns is less than the weft spacing&lt;br /&gt;
 weftyarnwidth = 1.2&lt;br /&gt;
 # Width of the warp yarns set equal to the warp spacing&lt;br /&gt;
 warpyarnwidth = sy&lt;br /&gt;
 # Yarn height equal to the vertical distance between yarns at cross overs&lt;br /&gt;
 yarnheight = sz&lt;br /&gt;
 &lt;br /&gt;
 # Create warp stuffer yarns&lt;br /&gt;
 for i in range(3):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, 2*i*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(2*sx, 0, 2*i*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create weft stuffer yarns&lt;br /&gt;
 for i in range(4):&lt;br /&gt;
     yarn = CYarn()&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 0, (2*i-1)*sz)))&lt;br /&gt;
     yarn.AddNode(CNode(XYZ(0, 2*sy, (2*i-1)*sz)))&lt;br /&gt;
 &lt;br /&gt;
     yarn.AssignInterpolation(CInterpolationCubic())&lt;br /&gt;
     yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(weftyarnwidth, yarnheight)))&lt;br /&gt;
     yarn.SetResolution(20)&lt;br /&gt;
     yarn.AddRepeat(XYZ(sx, 0, 0))&lt;br /&gt;
     yarn.AddRepeat(XYZ(0, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
     Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 # Create warp binder yarns&lt;br /&gt;
 top = 6*sz&lt;br /&gt;
 bottom = -2*sz&lt;br /&gt;
 &lt;br /&gt;
 oh = 0.5*weftyarnwidth+0.12&lt;br /&gt;
 ov = 0.8*sz&lt;br /&gt;
 &lt;br /&gt;
 yarn = CYarn()&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(0, sy, top)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx-oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx, sy, bottom)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(sx+oh, sy, bottom+ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx-oh, sy, top-ov)))&lt;br /&gt;
 yarn.AddNode(CNode(XYZ(2*sx, sy, top)))&lt;br /&gt;
 &lt;br /&gt;
 yarn.AssignInterpolation(CInterpolationBezier())&lt;br /&gt;
 yarn.AssignSection(CYarnSectionConstant(CSectionEllipse(warpyarnwidth, yarnheight)))&lt;br /&gt;
 yarn.SetResolution(20)&lt;br /&gt;
 yarn.AddRepeat(XYZ(2*sx, 0, 0))&lt;br /&gt;
 yarn.AddRepeat(XYZ(sx, 2*sy, 0))&lt;br /&gt;
 &lt;br /&gt;
 Textile.AddYarn(yarn)&lt;br /&gt;
 &lt;br /&gt;
 Textile.AssignDomain(CDomainPlanes(XYZ(-0.5*sx,-0.5*sy,bottom-sz), XYZ(1.5*sx,3.5*sy,top+sz)))&lt;br /&gt;
 &lt;br /&gt;
 # Add the textile to our TexGen singleton&lt;br /&gt;
 AddTextile(Textile)&lt;br /&gt;
&lt;br /&gt;
===Saving to TG3 file format===&lt;br /&gt;
TexGen has it&amp;#039;s own file format for storing textile geometry with the extension .TG3. For more details on this file format please read the [[TG3 File Format]] page. Any textile models saved to this file format can be reloaded at a later time however it is also a good idea to keep the python script used to generate the geometry in case modifications need to be made. To save such a file it is simply a matter of adding an additional like at the end of your script like so:&lt;br /&gt;
&lt;br /&gt;
 SaveToXML(&amp;quot;MyTextile.tg3&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
The first parameter is the name of the file to save, note that if the .tg3 extension is omitted then it will automatically be appended for you. The second parameter is optional and if used should be the name of the textile to save, this is useful if you have several textiles loaded at once and you only want to save one of them. Note that if you don&amp;#039;t specify the second parameter and you do have several textiles loaded then it will save all of them. The third parameter determines how much information is saved in the .tg3 file, see the [[TG3 File Format]] for more details.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id></id>
		<title>Scripting Export Mesh</title>
		<link rel="alternate" type="text/html" href=""/>
		<updated>2008-04-14T15:39:30Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Export a mesh==&lt;br /&gt;
&lt;br /&gt;
In the [[Scripting Guide]] section you learnt how to create TexGen models from Python scripts. In this tutorial I will explain how to get a mesh of the textile and save it to an arbitrary file format. This is a fairly common task but unfortunately one that must often be repeated due to the fact that there is very little standardisation on the file format for meshes. Each software package uses its own mesh file format and so we must learn to read and write to these different formats. Fortunately the Python language is ideal for performing these tasks with relative ease.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>