THE reference for power system transients

How to change a device name using EMTP JavaScript

Required knowledge: * How to trigger a script in EMTP

* What are DWDevice, DWCircuit, DWSignal, DWPin, etc in EMTP JavaScript?

* How to get devices in circuit with EMTP JavaScript

This script gets a DWDevice from an EMTP DWCircuit and change its attribute Name.

//* Description: This script gets DEV1 in the main circuit and change its name to fault

//** Get the current (active) DWCircuit object. See Help & Support/4 - JavaScript based Scripting in EMTP/DWCircuit for methods and attributes

var cCt = currentCircuit();

//** Get all devices of the DWCircuit cCt into an array whose names are DEV1.

var DWDevice_DEV1_array = cCt.devices('Name', 'DEV1'); //See Help & Support/4 - JavaScript based Scripting in EMTP/DWCircuit for more filtering options

//DWDevice_DEV1_array is an array with one element, because only one device is named DEV1 in cCt.

//Check if DEV1 was found

if(DWDevice_DEV1_array==null || DWDevice_DEV1_array.length==0){

alert('The searched device does not exist!');

halt(); //Stop the script. See Help & Support/4 - JavaScript based Scripting in EMTP/SPScript

}

//** Get DEV1 out of DWDevice_DEV1_array

var DWDevice_fault= DWDevice_DEV1_array[0] //DWDevice_fault is the DWDevice of the first element (and only one) of DWDevice_DEV1_array

 

//** Change DWDevice_fault name

DWDevice_fault.setAttribute('Name', 'fault')

alert('The new name of the device is '+ DWDevice_fault) //alert, just for the exercises

 

 

Example folder: Click here

If you can't find an answer, the support team is ready to help!
Follow us