Welcome to the EMTP® Help Center
How to replace a device by another from a library using EMTP JavaScript
Required knowledge: * How to trigger a script in EMTP
* What are DWDevice, DWCircuit, DWSignal, DWPin, etc in EMTP JavaScript?
This script replaces a device by another device type defined in a EMTP library (.clf).
Applications:
· changing converter model from detailed to average value model
· changing control circuit based on operating model selected
· changing circuit according to study type, for example: a substation is modeled in detailed for lightning study and replaced automatically by a node device for load-flow analysis.
· Automatic upgrade of outdated devices with newer version.
//* Description: This script replaces the RLC: R devices by RLC: RL
//** Get the current DWCircuit object. See Help & Support/4 - JavaScript based Scripting in EMTP/DWCircuit for methods and attributes
var cCt = currentCircuit();
//** Get all resistances in the DWCircuit cCt into an array.
//The search is done using the LibType attribute (right click on a DWDevice/Attributes to see all attributes)
//LibType is a DWDevice attribute which corresponds to the name appearing in the library (see RLC Branches library).
//The libType of resistance is RLC: R
var resistanceDevs = cCt.devices('LibType', 'RLC: R'); //See Help & Support/4 - JavaScript based Scripting in EMTP/DWCircuit for more filtering options
//resistanceDevs is an array with one element, because only one device has a libType of 'RLC: R'.
//For research by name: cCt.devices('Name', 'R1');
var resistanceDev = resistanceDevs[0] //resistanceDev is the DWDevice of the first element (and only one) of resistanceDevs
parseScriptFile('ReplaceDevFromLib.dwj'); //Parse the definition of the ReplaceDevFromLib function which is used hereafter
var newDevicelib = 'Libs\\RLC branches.clf'; //Relative directory of the library in the installation folder where the replacement device is located
var newDeviceType = 'RLC: R-L' //Resistances are replaced by Resistance and inductance devices
var CloseLibrary = false //set to true if the library from which to retrieve must be closed after the replacement
//Replace resistanceDev by newDeviceType from the library newDevicelib
ReplaceDevFromLib(newDevicelib, newDeviceType, resistanceDev, CloseLibrary); //
//** The resistance has been replaced by an resistance and inductance.
Example folder: Click here