The following excerpt shows how the XML file for a scripted extension can reference multiple IronPython scripts:
<extension version="2" minorversion="1" name="WizardDemos"> <guid shortid="WizardDemos">7fdb141e-3383-433a-a5af-32cb19971771</guid> <author>Ansys, Inc.</author> <description>Simple extension to test wizards in different contexts.</description> <script src="main.py" /> <script src="ds.py" /> <script src="dm.py" /> <script src="sc.py" />
The element <script>
appears four times. All four of these
scripts are placed in the extension folder. When ACT processes multiple scripts, it
loads them into a single scope, as if the contents of all scripts are contained in a
single flat file. This works for a scripted extension that uses
import
statements because all scripts reside in the extension
folder.
Before using the binary extension builder to compile a scripted extension into a WBEX
file, you can specify which scripts to compile by setting the attribute
compiled
to true
for the element
<script>
:
<script src="main.py" compiled="true" /> <script src="ds.py" compiled="true" /> <script src="dm.py" compiled="true" /> <script src="sc.py" compiled="true" />
When multiple scripts are marked as compiled
, the binary
extension essentially pushes all of the content in these scripts into the binary buffer
stream. When you install and load the WBEX file, ACT reads each script from the binary
buffer and loads the script content into a single scope.
Consequently, the result for the binary version is the same as the scripted version. All contents in the multiple scripts are loaded into a single scope without any module designations, just as if you had originally combined the different scripts into one large, single script.
Unlike a scripted extension, the installed binary extension can no longer import another script as a module because the scripts no longer reside in an extension folder. Because methods and classes are invoked as if all scripts are in one large, single script, you must remove import statements and module prefixes before building a binary extension. By flattening the scripts in this way, both the scripted and binary versions of the extension run successfully.
This flattening does make it difficult to test the scripted extension before building the binary version because you cannot truly test the implementation until after you create and install the WBEX file. However, you can compile your IronPython modules into DLLs, remove the corresponding elements for the scripts from the XML file, and import them as required in your main script.
Note: You cannot currently flag files to have the binary extension builder skip them.
During the building of a WBEX file, any messages that you see about files being
skipped are the result of ACT no longer needing the plain-text scripts because the
elements for the scripts are marked as
compiled="true"
.