dateExtract not defined?

Morning,

Attempting to use the dateExtract function in the Script playground,
receiving the below error. I am not a Java expert…

Suggestions?

Thanks,

Andy

Traceback (most recent call last):
File “”, line 6, in
NameError: name ‘dateExtract’ is not defined

at org.python.core.Py.NameError(Py.java:260)
at org.python.core.PyFrame.getname(PyFrame.java:257)
at org.python.pycode._pyx21.f$0(<script playground>:6)
at org.python.pycode._pyx21.call_function(<script playground>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:568)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:557)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:551)
at com.inductiveautomation.ignition.designer.gui.tools.ScriptPlayground.runScript(ScriptPlayground.java:210)
at com.inductiveautomation.ignition.designer.gui.tools.ScriptPlayground$2.actionPerformed(ScriptPlayground.java:226)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Ignition v7.7.1 (b2014092209)
Java: Oracle Corporation 1.8.0_25

dateExtract is an expression function not a scripting function so it can not be used in the script playground.

Expression and scripting functions are not a part of the Java language.

If you provide some more details about what you are trying to do I’m sure someone here can get help get you started.

Thanks for the explanation.

Looking to sync time of multiple Opto22 SNAP-PAC controllers with gateway pc.

I’d like to write current time broken out to year, month, day, etc. to a data type including a trigger bit,
then update Opto controllers time.

I thought I’d do this with a script on a button press.

Thanks

If you want to do it from a button you could use a Python script like this -

[code]#get time from database
dbTime = system.db.runQuery("SELECT HOUR(NOW()) as hours, " +
"MINUTE(NOW()) as minutes, " +
“SECOND(NOW()) as seconds”)

tags = [“MasterClock/SCADA/Hours”, “MasterClock/SCADA/Minutes”,
“MasterClock/SCADA/Seconds”, “MasterClock/SCADA/SyncClocks”]
values = [dbTime[0][“hours”], dbTime[0][“minutes”],
dbTime[0][“seconds”]+1, 1]

#write time to Master Clock PLC and set SyncClocks bit
system.tag.writeAll(tags, values)[/code]

I use a gateway script that updates the clock every morning -

[code]from time import localtime, strftime
curTime = strftime("%H:%M:%S", localtime())

if curTime == “00:00:01”:
#sync PLC clocks to server’s time
system.tag.write(“MasterClock/SCADA/Hours”, 0)
system.tag.write(“MasterClock/SCADA/Minutes”, 0)
system.tag.write(“MasterClock/SCADA/Seconds”, 1)
system.tag.write(“MasterClock/SCADA/SyncClocks”, 1)[/code]

Thanks, that looks promising.

Andy

You can use this stand alone application from Opto 22 to time sync all of your controllers. I have this running on my Ignition server to do just that. Nothing fancy but it works great.

Uio Time R1.3 Distribution.zip (105 KB)