You are on page 1of 36

JMAG Version 22.

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: jmag-support@sci.jsol.co.jp 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

About This Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Using the Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7


Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Preparing an Operating Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
VBScript and JScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Script Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Executing from Script Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Executing from a Script File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Executing JMAG-Designer Using a Script File as an Argument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Executing from the Python Console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Start JMAG Using Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
JMAG-Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
JMAG-Scheduler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
designerstarter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Notes for Editing Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Argument and Return Value Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Reference Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Methods for Specifying ID and Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Using Mathematical Formulas for Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Specifying the Order of the Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Creating a GUI for Parameter Input Using Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Use of the Validation Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Adding a Ccheck Box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Adding a Radio Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Adding an Input Field for File Path or Directory Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Hiding the Cancel Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Translation Setting of Label Name. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Adding Help Button and Tool Tip. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Creating a Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Creating a Two-Column Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Using Python in Your Environment to Execute Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27


Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Executing Script Using a Third-party Script Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Set the Environment Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Create a Python Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Using Python Installed in User Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Set the Environment Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Using the Script from Applications that Support Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Enabling the License Waiting Function during Script Execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Script Commands That can be Used in Python in a User Environment . . . . . . . . . . . . . . . . . . . . . . . . . 33

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

 Topics in This Chapter


• Scripts (page 8)
• Preparing an Operating Environment (page 9)
• Script Execution (page 11)
• Start JMAG Using Script (page 15)
• Notes for Editing Script (page 17)
• Creating a GUI for Parameter Input Using Scripts (page 22)

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

Preparing an Operating Environment


JMAG-Designer supports the following scripting languages:
• VBScript
• JScript
• Python
This chapter contains notes for preparing each scripting language, information on how to install
scripting languages, and explanations on how to perform debugging.
MEMO The version information of VBScript, JScript and Python that are supported by JMAG-
Designer can be obtained from JMAG website (https://www.jmag-international.com/).

VBScript and JScript

 Notes
VBScript and JScript require no preparation because they are included with Windows.

 Debugging the script using VBScript and JScript


For debugging VBScript and Jscript (error detection), the following tools can be used.
• JMAG Script Editor:
When debugging with the Script Editor, the installation of Microsoft Visual Studio is needed.
• Visual Basic Editor:
The Visual Basic Editor can be run from Microsoft Word and Excel. For details on how to run,
see the website below.
https://msdn.microsoft.com/en-us/library/dn833103.aspx
Errors are automatically detected when the script file (.vbs, .js) is double-clicked on and run.

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

 Script debugging method when using Python


The following tools and others can be used for Python debugging (error detection).
• JMAG Script Editor
• Python Console:
To start the Python Console, from the JMAG-Designer menu bar, select [Script] > [Python Con-
sole].
Debugging can be performed by entering scripts in the [Python Console] dialog.

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 be executed using Python 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
• Execute from the Python console
MEMO Script errors can be converted to exceptions when using Python. For details, see the description
for the [Preferences] dialog [Script] setting panel under “Parameter Explanation Edition”.

Executing from Script Editor


A script can be executed from Script Editor.
Start JMAG-Designer, and select [Scripts] > [Script Editor] from the menu bar to display the Script
Editor window. Open or create a script file, and then execute the script from the menu or button.

Executing from a Script File


A script can be executed by dragging a script file (.vbs, .js, or *.py) to Script Editor or by double-
clicking a script file. A script file needs to be created in advance.
MEMO If multiple versions of JMAG-Designer, such as version 5.0 and 10.0, are installed on your
machine, the script files are executed from the last-installed version. To change the version of JMAG-
Designer to execute the script file, double-click the VBLink.bat file located in the installation folder of
the version to use.

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

Executing JMAG-Designer Using a Script File as an Argument


A script can be executed for the started JMAG-Designer from the Windows (or Linux) command
prompt by specifying the name or path of a script file (.vbs, .js, .py) as an argument of a JMAG-
Designer execution command.

 Examples of Executing
• Examples of executing a script in Windows:
>designer.exe filename.vbs

• Examples of executing a script in Linux


>./designer filename.py

 Designer command-line options


• There are two types of options: short options and long options. Some options also take a value
after the option name.
• Short options require a single hyphen (-). For short options that take a value, separate the
option name and value with a space.
• Long options require two hyphens (--). For long options that take a value, separate the option
name and value with a space or equal (=).
• If the value contains spaces, enclose the value in double quotes (").
Short option Long option Value Description
-g - None Runs a script file in non-GUI mode.
In non-GUI mode, JMAG windows are created but not
actually displayed. Running in non-GUI mode is useful
when you want to do other work on the same machine
during script execution or when you do not want to use
extra machine resources to launch any windows.
The -g option can be used in the following situations:
• When using Windows
• When using Linux and running scripts as a user logged
in to the desktop

Windows example:
>designer.exe –g filename.vbs

12
Using the Scripts

Short option Long option Value Description


-w - None Runs a script file in non-Window mode.
In non-Window mode, no JMAG windows are created or
displayed. Running in non-Window mode is useful when
you want to do other work on the same ma-chine during
script execution or when you do not want to use extra
machine resources to launch any windows.
The -w option can be used in the following situations:
• When using a Linux cluster without a window system
(such as X-Window System)

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

Short option Long option Value Description


- --multi None Executes multiple cases simultaneously using a power sim-
ulation license (PSL).
The LM-X power simulation license (PSL) is a license sys-
tem for multi-case execution (chargeable license). 100 jobs
can be run simultaneously with 1 license.
This option is used with the --project-key option or --proj-
ect-key-file option.

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.

Executing from the Python Console


A script can be executed from the Python console.
Start JMAG-Designer, and select [Python Console] from the [Scripts] menu to display the [Python
Console] dialog. Enter scripts in this dialog, and then execute the script.

14
Using the Scripts

Start JMAG Using Script


This chapter describes how to start the following JMAG programs using VBScript as the scripting
language.
• JMAG-Designer
• JMAG-Scheduler
• designerstarter
VBScript uses the CreateObject method to start a program. This method enables specifying the ver-
sion of start-up program to be used.

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

Notes for Editing Script


• Specification needs to be set so that a VBArray type can be specified when obtaining return val-
ues in array using Jscript.
• Script property name ignores the case.

Argument and Return Value Types


Arguments specified with JMAG methods and acquired return values are input or output using set
types.
The types of arguments and return values are described in each method syntax, which can be found
in the JMAG-Designer Help.
These are the main types used in JMAG.

 String: String Type


A string type variable can contain a collection of characters.
Example:
• Study class
SetName (String &name)

 String array: String Array Type


A string array type variable can contain a string array.
Example:
• Material class
SetTable (String &propName, String array &mat)
Example (Use VBScript):
Set app = designer
Set geomApp = _ app.CreateGeometryEditor()
Set document = geomApp.GetDocument()
Set sketch = geomApp.GetDocument().GetAssembly().GetItem("2DSketch")
‘Creates a region fillet in a sketch
Set fillet = _ sketch.CreateRegionFillet()
‘Obtains a line by selecting a name
set target1 = sketch.GetItem ("line")
set target2 = sketch.GetItem("line.4")
‘Creates an object for reference using a line object
Set ref1 = document.CreateReferenceFromItem(target1)
Set ref2 = document.CreateReferenceFromItem(target2)
‘Adds an object ID for reference to an array.
ReDim refarray(1)
refarray(0) = ref1.GetIdentifier()
refarray(1) = ref2.GetIdentifier()
‘Sets an array for ID as a fillet setting
Call fillet.SetProperty("Target", refarray)

17
JMAG Version 22.2 User's Manual
Scripts

 object: Object Type


An object type variable can contain any objects.
Example:
• MaterialLibrary class
DeleteCustomMaterialByObject (MaterialObject *object)
• GraphModel class
AddDataSet (DataSet *set, int pos=-1)

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.

 Int: Integer Type


An integer type variable can contain integers.
Example:
• Study class
SetCurrentCase (int caseIndex)

 double: Real Number Type


A real number type variable can contain real numbers.
Example:
• CalculationDefinition class
SetPhase (double value)

 bool (true/false): Boolean Type


A boolean type variable can contain either “true” or “false”. Boolean types can be used to express log-
ical operation results and “On/Off” displays.
Example:
• ViewController class
SetOnlyCutFacesView (bool flag)

 variant: Variant Type


A variant type variable can retain values for any type (strings or real numbers). The following exam-
ple can use both a string type part name and an integer type part ID as an argument.
Example:
• Model class
IsPartSuppressed (Variant &part)

 color: Color Type


A color type variable can contain a color type (keywords such as “red” or strings of “#RRGGBB” for-
mat).

 Void: Void Type


For methods that do not have return values, the return value type is shown as “void”.

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.

Methods for Specifying ID and Index


Some JMAG-Designer methods specify the properties by ID and others by index.

 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

 Index specifying methods


Index refers to the sequential number. Sequential numbers starting from 0 are assigned.
Example:
GetModel()
GetStudy()
GetCondition()
Items such as methods specifying the following targets apply.

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

Using Mathematical Formulas for Parameters


Mathematical formulas can be specified as values in the following parameters for variables of real
type (Double type).
• Parameters related to cut planes, sets, and coordinate systems in each model.
• Parameters that belong to conditions of each property
• Parameters that belong to properties of each study
• Parameters that belong to mesh properties of each study
• Parameters related to analysis results of each study
• Parameters related to dimensions or constraints for the Geometry Editor

 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)

Specifying the Order of the Script


Some parameters for JMAG-Designer have a dependence relationship with other parameters.
For example, the setting in the [Component] box for arc section graph vary by the setting in the
[Coordinate System] which establishes a dependent relationship (see the following image).

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

Creating a GUI for Parameter Input Using Scripts


GUI (Graphical User Interface) for parameter input can be created by using 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

Use of the Validation Function


Validation can be set to the text box added to dialogs. It is a function to prevent invalid input
parameters. For example, when a character string is entered into a real number type text box, the val-
idation function does not allow its input and results in an error.
For methods that create text boxes such as AddInteger, AddReal, and AddString; validation is set
automatically according to their input values (integer, real number, and character string).
Also, validation for checking the upper and lower limits of an input value can be manually set. The
following is an example.
dialog.AddInteger("int_name", "Integer Label", 1)
dialog.SetMinimum("int_name", 1)

Adding a Ccheck Box


To add a check box, set (0: OFF, 1: ON) as the initial value.
dialog.Addcheckbox("check_name", "Check Label", 0)

Adding a Radio Button


To add a radio button, use the same name for a parameter group.
dialog.AddRadio("radio_name", "Option One", 1)
dialog.AddRadio("radio_name", "Option Two", 2)
dialog.AddRadio("radio_name", "Option Three", 3)

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.

Adding an Input Field for File Path or Directory Path


The methods to create an input field for the path of a file or directory are as follows:
void AddOpenFilename(name, label, default_value, col = 0, col_span = 1)
void AddSaveFilename(name, label, default_value, col = 0, col_span = 1)
void AddDirectoryPath(name, label, default_value, col = 0, col_span = 1)

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.

Hiding the Cancel Button


The OK/Cancel button is displayed by default. To hide the Cancel button, assign the setting with
the following method.
dialog.SetCancelButtonVisible(false)

Translation Setting of Label Name


Displaying the label name for each control in Japanese can be specified with the SetTranslation
method. For example, to display a “label name” as “label name”, describe as follows:.
SetTranslation("label name", " ラベル名 ")

MEMO The dialog is displayed in the language specified in the optional settings in JMAG-Designer.

 Sample Scripts (VBScript)


Set app = designer
Set dialog = app.CreateDialogBox()

label_en = "aaa"
label_jp = "bbb"

Call dialog.SetTranslation(label_en, label_jp)


Call dialog.AddLabel(label_en)

Adding Help Button and Tool Tip


Setting the Help button can be specified using the following method. Clicking the Help button will
open the sub-window and displays the description. The explanation will be shown in the language
set in the language settings.
dialog.SetHelp("To use this dialog enter the values....")

The tool tip can be set for each parameter.


dialog.SetTooltip(name, "To show an on-screen tip for the parameter....")

23
JMAG Version 22.2 User's Manual
Scripts

Creating a Dialog Box


Running the following script will display the following dialog box.

• The method to add each parameter specifies a name, label (parameter name displayed in the dia-
log), and the initial value as an argument.

 Sample Scripts (VBScript)


'Creates the application object "app" and enables the execution of the script.
Set app = designer

'Creates a dialog object


Set dialog = app.CreateDialogBox()

'Adds a parameter to the dialog


Call dialog.SetTitle("Dialog Title")
Call dialog.AddLabel("a label")
Call dialog.AddInteger("int_name", "Integer Label:", 1)
Call dialog.AddReal("real_name", "Resistance:", 0.0)
Call dialog.AddInteger("another_real", "Inductance:", 0.0)
Call dialog.AddString("string_name", "Title:", "<untitled>")

'Displays a created dialog


Call dialog.Show()

'Retrieves variables for each parameter


v1 = dialog.GetValue("int_name")
v2 = dialog.GetValue("real_name")
v3 = dialog.GetValue("another_real")
v4 = dialog.GetValue("string_name")

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.

Creating a Two-Column Dialog Box


To create a dialog box in which parameters have been arranged in two columns, the following ways
can be used.
• A. Specifying the column number of the display start position and column width to be used for
display as an option using the method for adding parameters.
The following is the syntax of the AddInteger method. An optional argument to specify the col-
umn number and column width can be specified after the name, label, and the initial value. All
methods for adding parameters, like the AddInteger method, can specify column numbers and
column widths.
void AddInteger(name, title, default_value, column = 0, column_span = 1)

24
Using the Scripts

• B. Using the SetColumn method.

In the following example, a two-column dialog box, as shown in the figure below, was created using
method A.

 Sample Scripts (VBScript)


'Creates the application object "app" and enables the execution of the script.
Set app = designer
'Creates a dialog object
Set dialog = app.CreateDialogBox()
'Adds a parameter to the dialog
Call dialog.SetTitle("Dialog Title")
Call dialog.AddLabel("a long label that spans columns", 0, 2)
Call dialog.AddInteger("int_name", "Integer Label", 1, 0)
Call dialog.AddReal("real_name", "Resistance", 0.0, 0)
Call dialog.AddInteger("another_real", "Inductance", 0.0, 1)
Call dialog.AddString("string_name", "Title", "<untitled>", 0, 2)
'Displays a created dialog
Call dialog.Show()

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.

 Topics in This Chapter


• Notes (page 28)
• Executing Script Using a Third-party Script Editor (page 29)
• Using Python Installed in User Environment (page 31)
• Using the Script from Applications that Support Python (page 32)
• Enabling the License Waiting Function during Script Execution (page 32)
• Script Commands That can be Used in Python in a User Environment (page 33)

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

Executing Script Using a Third-party Script Editor


This section explains the procedure for using a third-party script editor, using Spyder as an example.
• (1) Add the search path for the JMAG-Designer module to the environment variable. (page 29)
• (2) Create a Python script. (page 29)
• (3) Execute the Python script.

Set the Environment Variable


Add the search path for the JMAG-Designer module to the environment variable PYTHONPATH
when running JMAG-Designer from a third-party script editor.

 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].

Create a Python Script

 Record the operations in JMAG-Designer to scripts


The following procedure is an example:

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)

 Script command to start/attach the JMAG-Designer process


Scripts that record operations in JMAG-Designer are prefixed with the script command GetApplica-
tion(). GetApplication() is used to obtain the Application object, which is the entry point for calling
the script command. When calling GetApplication() from a third-party script editor, 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 GetApplication() is called. “Select Avail-
able JMAG-Designer to Attach” or “Create New JMAG-Designer” can be selected in this dialog.
If you want a new process to be constantly created, replace GetApplication() with CreateApplica-
tion().
To specify the process that is to be attached with a process ID, use AttachApplication(). To obtain a
process ID within the script, use GetApplicationPid().
For details on each command, see “Script Commands That can be Used in Python in a User Envi-
ronment” on page 33.

30
Using Python in Your Environment to Execute Scripts

Using Python Installed in User Environment


When using Python in the user environment, follow the steps below:
• (1) Add the JMAG-Designer installation path to the environment variable (page 29).
• (2) Create a Python script.
• Procedures and settings are the same as for using a third-party script editor. See “Create a Python
Script” on page 29.
• (3) Run the Python script.

Set the Environment Variable


Add the JMAG-Designer installation path to the environment variable PYTHONPATH. Also
update the environment variable PYTHONPATH when changing the JMAG-Designer version you
are using.

 Windows: Setting the environment variable in command prompt


Use the set command. Variables and variable values must be connected by an equal sign. Variable
values set in command prompt using the set command are only valid within the command prompt
where the set command was executed.
• Example:
set PYTHONPATH=C:\Program Files\JMAG-Designer22.0

 Linux: Setting the environment variable to OS in C Shell


Use the setenv command. Enter a space between the variable and variable value. Note that Linux is
case-sensitive.
• Example:
setenv PYTHONPATH /home/app/jmag/mod

 Linux: Setting environment variable to OS in bash


Use the export command. Connect the variable and variable value with an equal sign.
• Example:
export PYTHONPATH=/home/app/jmag/mod

31
JMAG Version 22.2 User's Manual
Scripts

Using the Script from Applications that Support Python


Procedures and settings will depend on the application software you are using. Create the equivalent
of the following 2 settings according to the application you are using:
• Settings equivalent to environment variable PYTHONPATH.
Set the path to the JMAG-Designer installation folder. For PYTHONPATH, see the explanation
on “Set the Environment Variable” on page 31.
• Settings equivalent to script code “from jmag.designer import *”.
Create settings to import the JMAG-Designer module. For details on this script code, see the
explanation on “Create a Python Script” on page 29.

Enabling the License Waiting Function during Script Execution


The License Waiting function can also be enabled when Python in the user environment or third-
party script editor is used. When the License Waiting function is enabled and there are no licenses
available when the job starts, the job will wait until a license is available.
The License Waiting function is enabled when both of the following settings are created:
• Set the environment variable JMAG_LICENSE_CHECK_WAITING to 1
• Set -g or -2 to the argument of the CreateApplication() function (start JMAG-Designer in a
mode that does not display the window)
MEMO The License Waiting function will not work if the JMAG-Designer is started in a mode that dis-
plays the window.

32
Using Python in Your Environment to Execute Scripts

Script Commands That can be Used in Python in a User Environment


In Python in a user environment, the following script commands can be used in addition to JMAG-
Designer script commands:

 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.

[Select JMAG-Designer] dialog


• [Type]:
Select one of the following:
• [Select Available JMAG-Designer to Attach]:
Attaches to existing JMAG-Designer process and runs script.
Select the JMAG-Designer process to attach from the list dis-
played.
• [Create New JMAG-Designer]:
Starts a new JMAG-Designer process and runs script.
• [OK] button:
The GetApplication() returns the Application object related to the
attached or newly created JMAG-Designer process.
• [Cancel] button:
Stops GetApplication().
If you want to abort subsequent scripts upon cancellation, add
error handling.
Example:
app = designer.GetApplication()
if app.IsValid() != True:
sys.exit()

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

CreateApplication() command-line options


Short option Long option Value Description
-x - None Opens the [Driver Setup] dialog when JMAG-Designer is
run. The graphic driver to use can be specified in this dia-
log.
Use this option when JMAG cannot be run due to the
graphics driver.
-g - None Launches the JMAG-Designer process in non-GUI mode.
In non-GUI mode, JMAG windows are created but not
actually displayed.
The -g option can be used in the following situations:
• When using Windows
• When using Linux and running scripts as a user logged
in to the desktop

34
Using Python in Your Environment to Execute Scripts

Short option Long option Value Description


-w - None Launches the JMAG-Designer process in non-Window
mode.
In non-Window mode, no JMAG windows are created or
displayed.
The -w option can be used in the following situations:
• When using a Linux cluster without a window system
(such as X-Window System)

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
- --multi None Executes multiple cases simultaneously using a power sim-
ulation license (PSL).
The LM-X power simulation license (PSL) is a license sys-
tem for multi-case execution (chargeable license). 100 jobs
can be run simultaneously with 1 license.
This option is used with the --project-key option or --proj-
ect-key-file option.

35
JMAG Version 22.2 User's Manual
Scripts

Short option Long option Value Description


- --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 (").
- --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.

36

You might also like