Scripts
Scripts
2
User's Manual
Scripts
JSOL Corporation
Issue date of 1st Edition: August 2023
COPYRIGHTS
Copyright © 2023 JSOL Corporation All Rights Reserved.
• Information in this document is subject to change without notice.
• No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or any means electronic or
mechanical, including photocopying and recording for any purpose other than the purchaser’s personal use without the written per-
mission of JSOL Corporation.
JMAG Division
JSOL Corporation
Tokyo/ KUDAN-KAIKAN TERRACE 11th Floor, 1-6-5 Kudanminami, Chiyoda-ku, Tokyo 102-0074, Japan
Phone: +81(03)6261-7361 Phone (Support): +81(03)6261-7362 FAX: +81(03)5210-1142
Osaka/ Tosabori Daibiru Bldg. 2-2-4 Tosabori, Nishi-ku, Osaka 550-0001, Japan
Phone: +81(06)4803-5820 FAX: +81(06)6225-3517
Email: [email protected] URL: https://www.jmag-international.com/
Trademarks
• JMAG and JMAG-RT are registered trademarks of JSOL Corporation.
• Abaqus, CATIA, SIMULIA and SOLIDWORKS are trademarks or registered trademarks of Dassault Systemes or its subsidiaries in
the United States and/or other countries.
• AMD and AMD Opteron is a trademark of Advanced Micro Devices, Inc.
• Amesim, LMS Virtual.Lab, NX, Parasolid, Siemens, Simcenter, Simcenter 3D, Solid Edge, and STAR-CCM+ are trademarks or reg-
istered trademarks of Siemens Industry Software Inc., or its subsidiaries or affiliates, in the United States and in other countries.
• CAPRI CAE Gateway is a registered trademark of CADNexus Inc. in the United States and other countries.
• Creo and Pro/ENGINEER are registered trademarks of PTC, inc.
• DXF and Inventor are trademark or registered trademark of Autodesk, Inc. in the United States and/or other countries.
• Excel, Microsoft, Visual C++, Windows, and Windows 10 are either registered trademarks of Microsoft Corporation in the United
States and/or other countries.
• Flexera Software and FLEXlm are registered trademarks of Flexera Software LLC in the United States and other countries.
• Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other
countries.
• LabVIEW is a registered trademark of National Instruments Corporation.
• Linux is a registered trademark of Linus Torvalds in the United States and other countries.
• LSF is a registered trademark of IBM Corporation in the United States, other countries, or both.
• MATLAB and Simulink are registered trademarks of The MathWorks, Inc.
• MSC NASTRAN is a trademark of MSC Software Corporation.
• NASTRAN is a registered trademark of the National Aeronautics and Space Administration.
• NX Nastran is an enhanced proprietary version developed and maintained by Siemens Product Lifecycle Management Software Inc.
• NVIDIA is a trademark or registered trademark of NVIDIA Corporation in the United States and/or other countries.
• OpenOffice.org and Apache OpenOffice are registered trademarks of the Apache Software Foundation.
• PSIM is a registered trademark of Powersim Inc.
• ROMAX is a trademark of Romax Technology, LTD.
• Tecplot is a registered trademark of Tecplot, Inc. in the United States and other countries.
• Trademark information for PowerCore, owned by ThyssenKrupp Electrical Steel GmbH.
• All other product and company names are trademarks, registered trademarks, or service marks of their respective companies, organiza-
tions, or holders.
• This document does not include the letters ® and TM.
CONTENTS
3
JMAG Version 22.2 User's Manual
Scripts
4
About This Edition
“JMAG User’s Manual Scripts” explains how to use scripts in JMAG-Designer, JMAG-Scheduler, and Geometry Edi-
tor.
MEMO JMAG user's manual is divided into contents.
• “JMAG Installation Manual”.
• “JMAG User's Manual Screen Configuration Edition”
• “JMAG User's Manual Operations Edition”
• “JMAG User's Manual Parameter Explanation Edition”
• “JMAG User's Manual JMAG-Express, JMAG-RT, JMAG-RT Viewer Edition”
• “JMAG User's Manual Coupled Analysis Edition”
• “JMAG User's Manual Files Edition”
• “JMAG User's Manual Licenses”
• “JMAG User's Manual Scripts Edition” and “Script Help”.
• “JMAG User's Manual Analysis Guide”
• “JMAG User's Manual Iron Loss Formulas”
5
JMAG Version 22.2 User's Manual
Scripts
6
Using the Scripts
7
JMAG Version 22.2 User's Manual
Scripts
Scripts
A script is a sequence of commands described with scripting language used to pass orders to a com-
puter in order to execute various hardware and software functions.
With exception to a few tools, all the functions in JMAG Designer can be executed with scripts.
Using a script allows execution of JMAG-Designer functions to be automated, letting the user work
more efficiently.
GUI operations can also be automatically recorded to a script in JMAG-Designer. Operations can
be performed again by executing a recorded script. Instead of creating a new script, pre-recorded
scripts can be easily customized to run the exact processes needed by the user.
MEMO Use the command line to run tools that cannot be used in a script.
8
Using the Scripts
Notes
VBScript and JScript require no preparation because they are included with Windows.
Python
Notes
Python needs to be installed to use Python.
• Python is case sensitive. For example, a script cannot be executed when “Run” is used instead of
“run.”
• “true” and “false” are used for VBScript and JScript; however, “1” and “0” must be used for
Python to set on/off for the property.
• If two byte characters are used in the script, encoding error occurs, and the file may not be read
or written or the characters may appear garbled.
A script can be executed without any problem in JMAG-Designer because Script Editor and the
Python console included with JMAG-Designer support UTF-8; however, if an external file needs
to be imported, Python needs to be set as follows:
i. Create a file named “sitecustomize.py” in the folder “\Lib\site-packages” located in
the Python installation folder.
ii. Insert the following commands to specify encoding in the file “sitecustomize.py”.
import sys
sys.setdefaultencoding("utf-8")
9
JMAG Version 22.2 User's Manual
Scripts
10
Using the Scripts
Script Execution
A script can be executed using VBScript or JScript in one of the following ways:
• Execute from Script Editor
• Execute from a script file
• Execute JMAG-Designer using a script file as an argument
A script can also be executed by selecting a script file from [Scripts]. The script file needs to be saved
in the following folder before starting JMAG-Designer to add it to the menu displayed by right-
clicking in the [Scripts].
C:\Users\JMAG-Designer\(Login user name folder)\Scripts
MEMO The context menu that reflects the folder structure is displayed under the [Scripts] menu of
JMAG-Designer if a subfolder is created in the [Scripts] folder mentioned above.
11
JMAG Version 22.2 User's Manual
Scripts
Examples of Executing
• Examples of executing a script in Windows:
>designer.exe filename.vbs
Windows example:
>designer.exe –g filename.vbs
12
Using the Scripts
Linux example:
>./designer –w filename.py
Note the following:
• There are some functions that cannot be performed
using scripts in non-Window mode. Some of these are as
follows:
• JPG export
• Case report
-l --log Path of the Records the execution history to a log file.
log file (.log) This option is effective when scripts that carry out geome-
outputted try editing and JCF file changes are executed in non-GUI
or non-Window mode. When an error occurs during script
execution, the log file can be used to investigate the cause
of the failure.
The log records the following major events necessary for
debugging under remote operation:
• License authentication status
• Start/end of JMAG-Designer
• Start of Geometry Editor, link status between JMAG-
Designer and Geometry Editor, model updates
• Analysis execution and results export
• File import
• JCF file output
• Script errors
Linux example:
>designer --log=logfile.log
>designer -l logfile.log
13
JMAG Version 22.2 User's Manual
Scripts
Linux example:
>designer -w --multi --project-key=123456
filename.py
>designer -w --multi --project-key-
file=filename.jproj filename.py
- --project-key None Specifies the project to be executed when multiple cases are
or to be executed using a power simulation license (PSL).
--project- This option is used with the --multi option.
key-file • When using the --project-key option, specify the project
key with an option value. The project key can be con-
firmed by opening the project file in JMAG-Designer
and right-clicking [Project] in the [Project Manager] tree
and selecting [Properties].
• When using the --project-key-file option, specify the
project file (full path) with an option value. Note the fol-
lowing:
• File paths need to be enclosed in double quotation
marks (").
See the description of the --multi option for execution
examples.
- --reservation Reservation Uses reserved licenses prior to executing JMAG-Designer.
key value • This option is only available when using LM-X license
servers.
• License reservations are made with the JMAG License
Center.
14
Using the Scripts
JMAG-Designer
Statement
JMAG-Designer's Application objects can be obtained by running this statement.
• When specifying the version:
JMAG-Designer 22.2 is started in this example.
Set designer = CreateObject("designer.Application.222")
• When not specifying the version:
Set designer = CreateObject("designer.Application")
MEMO When there are several versions of JMAG-Designer installed on a computer, the most recently
installed version of JMAG-Designer will start unless a version has been specified.
Notes
• When using this statement, JMAG-Designer terminates when 1 script process finishes. Use
designstarter (see below) in the following circumstances.
• When running multiple scripts consecutively and skipping JMAG-Designer start-ups and ter-
minations.
• Without terminating JMAG-Designer after scripts have finished, and continuing to run post-
processing scripts that use Microsoft Excel, etc.
JMAG-Scheduler
Statement
JMAG-Scheduler’s JobApplication objects can be obtained by running this statement.
• When specifying the version:
JMAG-Scheduler, included with JMAG-Designer 22.2, is started in this example.
Set scheduler = CreateObject("scheduler.JobApplication.222")
• When not specifying the version:
Set scheduler = CreateObject("scheduler.JobApplication")
MEMO When there are several versions of JMAG-Designer installed on a computer, the most recently
installed version of JMAG-Scheduler included with JMAG-Designer will start unless a version has been
specified.
15
JMAG Version 22.2 User's Manual
Scripts
designerstarter
designerstarter is a program to manage starting and shutting down JMAG-Designer using
script.Using designerstarter enables the following:
• Parallel operation of several JMAG-Designer windows within a single script.
• JMAG-Designer can be maintained in start-up status even after the script has been shut down.
Normally, when running several scripts sequentially and shutting down one script, JMAG-
Designer needs to be shut down and re-booted before another script can start.
Using designerstarter, when an instance is created by running the first script, enables the follow-
ing script to be re-used. This lets JMAG-Designer continue running and permits other scripts
from being executed sequentially. This cuts work times by eliminating time used starting and
closing JMAG-Designer.
Statement
designerstarter's InstantMananger objects can be obtained by running this statement.
• When specifying the version:
designerstarter, included with JMAG-Designer 22.2, is started in this example.
Set designerstarter = CreateObject("designerstarter.InstanceManager.22.2")
• When not specifying the version:
Set designerstarter = CreateObject("designerstarter.InstanceManager")
MEMO When there are several versions of JMAG-Designer installed on a computer, the most recently
installed version of designerstarter included with JMAG-Designer will start unless a version has been
specified.
Notes
• Running multiple scripts at the same time using designerstarter may cause a rapid increase in
load on the machine, causing JMAG-Designer to launch slowly. In such situations, use the envi-
ronment variable JMAG_DESIGNER_STARTER_FORCE_NOWINDOW to reduce the load
on the machine.
For the procedure for setting environment variables, see “Overview Edition”.
Environment variable Value Description
JMAG_DESIGN- 0 or 1 When the value is 1, JMAG-Designer is launched in non-
ER_STARTER_- Window mode.
FORCE_NOWINDOW In non-Window mode, no JMAG windows are created or
displayed.
Note the following:
• There are some functions that cannot be performed
using scripts in non-Window mode. Some of these are
as follows:
• JPG export
• Case report
16
Using the Scripts
17
JMAG Version 22.2 User's Manual
Scripts
MEMO For object type arguments and return values, the object class name is included in the syntax for
each method which can be found in the JMAG-Designer Help. For example, the underlined sections of
the above examples indicate that “MaterialObject class objects” and “DataSet class objects” are specified
as arguments. Note that there are many types of object classes.
18
Using the Scripts
Reference Types
Specific symbols (&, *) may appear before arguments and return value types in each method syntax
of the JMAG-Designer Help. These symbols show the reference types for arguments and return val-
ues.
The meaning of each symbol is described below.
• Blank:
The value to be entered as the argument color is directly passed to a method.
• &:
The address of the value to be entered as the argument color is passed to the method.
• *:
The pointer of the value to be entered as the argument color is passed to the method.
Example
• Blank example:
SetPhase (double value)
• Example with “&”:
SetName (String &name)
• Example with “*”:
DeleteCustomMaterialByObject (MaterialObject *object)
Reference types are for categorizing the processes inside methods, so it is not necessary to pay atten-
tion to argument input.
ID specifying methods
ID refers to the identification number. 1 or greater natural numbers are assigned.
Example:
SelectPart()
SetId(index, id)
Methods specifying the following targets apply.
• Part • Element
• Face • Element Face
• Edge • Element Edge
• Vertex • Node
19
JMAG Version 22.2 User's Manual
Scripts
• Model • Condition
• Study • Coordinate system
• Material
Also, note the following when specifying an index:
• The index is assigned in the order of the [Project Manager] tree. For example, the index is
assigned in the order of “0, 1, 2” in the FEM Coil condition shown in the [Project Manager] tree
shown below.
0
1
2
Examples of use
The following are examples.
SetValue("my_property", "360/7")
SetXYZPoint("propName", "10/7", "11/7", "12/7")
SetProperty("Angle", "360/11")
Notes
The following should be noted when using this function.
• Mathematical formulas cannot be specified in parameters for integer type (Int type).
20
Using the Scripts
• Mathematical formulas cannot also be used on parameters that are real type (Double type) for
methods that is not using property name. For example, this feature cannot be used for the “Set-
Radius” method of the “ConstraintRadius” class.
SetRadius(300)
Parameters that have a specific relationship need to maintain their relational sequence when they are
included in the script.
Correct example:
The upper parameters are set on the 8th line, and the lower parameters are set on the 9th.
app = designer.GetApplication()
sectiongraph1 = app.GetModel(0).GetStudy(0).CreateSectionGraph("untitled")
sectiongraph1.SetResultType("ReferenceMagneticFluxDensity")
sectiongraph1.SetAbscissa("angle")
sectiongraph1.SetArc(app.CreatePoint(13.35, 13.35, 0), app.CreatePoint(0, 0, 1),
app.CreatePoint(22.695001, 13.35, 0), 360)
sectiongraph1.SetArcOffset(0)
sectiongraph1.SetResultCoordinate("Use Coordinate System of Target Point")
sectiongraph1.SetComponent("Radial")
sectiongraph1.Build()
app.SetCurrentStudy(0)
Incorrect example:
The lower parameters are set on the 8th line, and the upper parameters are set on the 9th.
app = designer.GetApplication()
sectiongraph1 = app.GetModel(0).GetStudy(0).CreateSectionGraph("untitled")
sectiongraph1.SetResultType("ReferenceMagneticFluxDensity")
sectiongraph1.SetAbscissa("angle")
sectiongraph1.SetArc(app.CreatePoint(13.35, 13.35, 0), app.CreatePoint(0, 0, 1),
app.CreatePoint(22.695001, 13.35, 0), 360)
sectiongraph1.SetArcOffset(0)
sectiongraph1.SetComponent("Radial")
sectiongraph1.SetResultCoordinate("Use Coordinate System of Target Point")
sectiongraph1.Build()
app.SetCurrentStudy(0)
21
JMAG Version 22.2 User's Manual
Scripts
Notes
• To customize the GUI, the SimpleDialogBox Class method is used. For more details on the Sim-
pleDialogBox Class method, check the Help.
• The following controls can be added to the dialogs created using scripts.
• Text box (integer type, real number type, string type)
• Spin box (integer type)
• Check box (boolean type)
• Radio button
• Label
• Separator line in the dialog
• Directory and file path
• Each control will be displayed in the dialog in the order in which it was added.
• Specifying the following settings will cause an error.
• When the same name is set for more than one control (excluding the radio button)
• When the name of the control has not been set
22
Using the Scripts
MEMO If the value of the radio button is obtained with the GetValue method, in the above example,
numbers such as “1” are acquired.
When they are used, label, input space of the string, and the [Browse] button will be displayed in the
dialog. When [Browse] is clicked, the standard file dialog will open.
MEMO The dialog is displayed in the language specified in the optional settings in JMAG-Designer.
label_en = "aaa"
label_jp = "bbb"
23
JMAG Version 22.2 User's Manual
Scripts
• The method to add each parameter specifies a name, label (parameter name displayed in the dia-
log), and the initial value as an argument.
MEMO In this example, by using variables such as V1 and V2 as integer types, the GetValue method
can be used to return values of integer type, real number type, and string type depending on the parame-
ter type.
24
Using the Scripts
In the following example, a two-column dialog box, as shown in the figure below, was created using
method A.
25
JMAG Version 22.2 User's Manual
Scripts
26
Using Python in Your Environment to Execute Scripts
Scripts in JMAG can be run using Python in the user environment. The main uses of this function are:
• Edit, run and debug JMAG-Designer scripts using a third-party script editor.
• Control JMAG-Designer by running scripts using Python commands installed in the user environment.
• Control JMAG-Designer by running scripts from applications that support Python.
27
JMAG Version 22.2 User's Manual
Scripts
Notes
• JMAG-Designer modules can be called using Python in the user environment instead of the
Python included in JMAG.
• Use the Python version supported by JMAG when using Python in the user environment or a
third-party script editor. The Python versions supported by JMAG-Designer depends on the
environment being used. Please check the JMAG website for the latest information. (https://
www.jmag-international.com/)
28
Using Python in Your Environment to Execute Scripts
Using Spyder
To use Spyder, set PYTHONPATH in PYTHONPATH Manager.
1. Start Spyder.
2. From the menu bar, select [Tool] > [PYTHONPATH Manager] and open the [PYTHONPATH
manager] dialog.
3. Click [+Add path], open the [Select directory] dialog and specify the folder where JMAG-
Designer is installed.
4. Click [Select Folder] and go back to the [PYTHONPATH manager] dialog.
5. Click [OK].
1. Before automatic recording is started, change the argument types (index or name)
recorded in the script code in the [Script] setting panel of the [Preferences] dialog, as
needed.
The [Preferences] dialog can be opened by selecting [Tools] > [Preferences] from the JMAG-
Designer menu bar.
2. From the JMAG-Designer menu bar, select [Scripts] > [Start Recording].
3. Operate JMAG-Designer.
4. From the JMAG-Designer menu bar, select [Scripts] > [Stop Recording].
The JMAG Script Editor opens and displays the recorded code. Copy and paste the codes to a
third-party script editor.
29
JMAG Version 22.2 User's Manual
Scripts
Add code for importing the JMAG module to the script code
To use JMAG from a third-party script editor, the JMAG module must be imported. Add the fol-
lowing code to the beginning of the script.
from jmag.designer import *
Example (Line 2)
30
Using Python in Your Environment to Execute Scripts
31
JMAG Version 22.2 User's Manual
Scripts
32
Using Python in Your Environment to Execute Scripts
Application class
Function Description
designer.GetApplication() Obtains the Application object which is the entry point when script
commands are called.
When GetApplication() is called, the following behavior occurs:
• When JMAG-Designer does not start in the version specified by
PYTHONPATH:
A new JMAG-Designer process is created when GetApplication()
is called.
• When a JMAG-Designer version specified by PYTHONPATH is
already started:
The [Select JMAG-Designer] dialog is displayed when GetAppli-
cation() is called. “Select Available JMAG-Designer to Attach” or
“Create New JMAG-Designer” can be selected in this dialog.
33
JMAG Version 22.2 User's Manual
Scripts
Function Description
designer.CreateApplica- Starts a new JMAG-Designer process.
tion(option=[]) Argument
• Option:
Adds to command line in JMAG-Designer. Pass an optional string
in the list. This argument can be omitted.
Example:
['-l', 'D:/log.txt']
Option
For details, see “CreateApplication() command-line options” on
page 34.
Return value
Application object
designer.AttachApplication(pid) Attaches to JMAG-Designer with a specified process ID.
Argument
• pid:
Process ID of Application object
Return value
Attached Application object
designer.GetApplicationPid(app) Obtains process ID of specified Application object.
Argument
• app:
Application object
Return value
Process ID of Application object
34
Using Python in Your Environment to Execute Scripts
35
JMAG Version 22.2 User's Manual
Scripts
36