A file named test.txt should have been created in
the root directory of the application. Now create a new file named
demo.py
in a text editor like Notepad, and type the five lines you has entered
in the Python shell. Save and close the file. In ModelSphere Python shell,
press the Execute file... button and select the demo.py file.
The test.txt file is generated again.
A file containing Python statements in called a Python script.
To know more about Python statements, consult its documentation at http://www.python.org/.
#
# import clauses
#
from org.modelsphere.jack.srtool import ApplicationContext
#
# script's entry point
#
name = ApplicationContext.APPLICATION_NAME
vers = ApplicationContext.APPLICATION_BUILD_ID
out_file = open("test.txt","w")
out_file.write("You are working on " + name + " build", vers)
out_file.close()
The script writes the name and the build ID of the application in the test.txt file. The next example (demo2.py) outputs the name of the project in the test.txt file.
#
# import classes
#
from org.modelsphere.jack.srtool import ApplicationContext
from org.modelsphere.jack.baseDb.db import Db
from org.modelsphere.sms.templates import GenericMapping
#
# script's entry point
#
def main() :
try:
project = ApplicationContext.getFocusManager().getCurrentProject()
db = project.getDb()
db.beginTrans(Db.READ_TRANS)
metafield = GenericMapping.getMetaField("ProjectName")
name = project.get(metafield)
out_file = open("test.txt","w")
out_file.write("Project name:")
out_file.write(name)
out_file.close()
finally:
db.commitTrans()
main()
The API documentation (javadoc) of GenericMapping is provided with the application (see index.html under the doc\template-api\ directory).