Welcome to the EMTP® Help Center
How to connect signals and pins using EMTP JavaScript
Required knowledge: * How to trigger a script in EMTP
* What are DWDevice, DWCircuit, DWSignal, DWPin, etc in EMTP JavaScript?
This script connects a device pin to different buses using virtual connection (signal naming) method or wire connection.
Applications:
· changing automatically fault location
· Apply lightning strike at different locations
· Automatic circuit building script
//* Description: This script connects the fault pin signal to BUS1 and then to BUS2. Several connection options are demonstrated.
//** 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_fault_array = cCt.devices('Name', 'fault'); //See Help & Support/4 - JavaScript based Scripting in EMTP/DWCircuit for more filtering options
//DWDevice_fault_array is an array with one element, because only one device is named fault in cCt.
//Check if fault was found
if(DWDevice_fault_array==null || DWDevice_fault_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 fault DWDevice out of DWDevice_DEV1_array
var DWDevice_fault= DWDevice_fault_array[0] //DWDevice_fault is the DWDevice of the first element (and only one) of DWDevice_fault_array
//** Get BUS1 signal */
var DWSignal_BUS1_array = cCt.signals('Name', 'BUS1'); //See Help & Support/4 - JavaScript based Scripting in EMTP/DWCircuit for more filtering options
//DWSignal_BUS1_array is an array with one element, because only one signal is named BUS1 in cCt.
//Check if BUS1 was found
if(DWSignal_BUS1_array==null || DWSignal_BUS1_array.length==0){
alert('The searched signal does not exist!');
halt(); //Stop the script. See Help & Support/4 - JavaScript based Scripting in EMTP/SPScript
}
//** Get BUS1 DWSignal out of DWSignal_BUS1_array
var DWSignal_BUS1= DWSignal_BUS1_array[0] //DWSignal_BUS1 is the DWSignal of the first element (and only one) of DWSignal_BUS1_array
//** Get the pin of fault DWDevice
var DWPin_faultPins_array = DWDevice_fault.pins() //See Help & Support/4 - JavaScript based Scripting in EMTP/DWDevice
//DWPin_faultPins_array is an array with all the pins of fault. In this case, there is only one.
//Check if the pin was found
if(DWPin_faultPins_array==null || DWPin_faultPins_array.length==0){
alert('Fault has no pins!');
halt(); //Stop the script. See Help & Support/4 - JavaScript based Scripting in EMTP/SPScript
}
var DWPin_faultPin = DWPin_faultPins_array[0] //DWDevice_faultPin is the DWPin of the fault device pin.
//** Connect the fault pin to BUS1 using name connection (Virtual connection)
DWSignal_BUS1.connectByName(DWPin_faultPin) //DWPin_faultPin will take the name of BUS1. See Help & Support/4 - JavaScript based Scripting in EMTP/DWSignal
alert('Take a look at the fault pin. Its name is BUS1, which means it is virtually connected to BUS1.')
//* OPTION: connection to BUS2
if(confirm('Do you want to connect the fault to BUS2?')){
//** Get BUS2 signal
var DWSignal_BUS2 = cCt.signals('Name', 'BUS2')[0]; //Quick way of grabing BUS2, assuming no possible error (not recommended)
//** Connect the fault pin to BUS2 using name connection (Virtual connection)
DWSignal_BUS2.connectByName(DWPin_faultPin)
alert('Take a look at the fault pin. Its name is BUS2, which means it is virtually connected to BUS2.')
}
//* OPTION: connection to BUS1 with visible connection
if(confirm('Do you want to connect faut2 to BUS1 using visible line connection?')){
//** Get fault2 pin
var DWPin_fault2Pin = cCt.devices('Name', 'fault2')[0].pins()[0].signal; //Quick way of grabing the pin of fault2, assuming no possible error (not recommended)
//** Get the BUS1 signal again. Must be done since connectByName has modified BUS1
DWSignal_BUS1 = cCt.signals('Name', 'BUS1')[0]; //Quick way of grabing BUS1, assuming no possible error (not recommended)
DWPin_fault2Pin.connectTo(DWSignal_BUS1, true)
alert('Take a look at the fault2 pin. It is connected to BUS1')
}
Example folder: Click here