Script to import OPC tags like dragging with OPC Browser

It is easy to create new tags with the OPC Browser: select, drag, drop, done!
https://docs.inductiveautomation.com/display/DOC80/Creating+Tags#CreatingTags-BrowsingforOPCTags

How can we do the same in a script by giving the OPC path to import into my project. I would imagine something like this: import_opc_tags(“nsu=urn:BeckhoffAutomation:Ua:PLC1;s=GVL”, “[default]GVL”)

I am certainly not the first who wants to do that.

Yeah, but don’t. You really don’t want to create Ignition tags for PLC data that you aren’t using. Any such scripting that is structured enough to end up with efficient driver communications is structured enough to make a UDT, where a parameter holds your OPC root item path.

It is also rare for a single PLC data structure to map to a tag folder in a SCADA UI optimizable way. Use UDTs. That is what they are for. And you can edit them and all the instances will fix themselves to conform. Good luck scripting that.

1 Like

Normally yes.
However we already created in the PLC the many data structures for the purpose of exchanging data with the SCADA. We would only import OPC tags useful for the SCADA. Using UDT in Ignition imply having to create and support data structures in two systems at the same time without much gain. It is hard to be simpler and quicker than drag&dropping the tags already structured we created in the PLC.

Thus, a script allowing the importation of tags from OPC would help automatically recreate/regenerate our tags in Ignition. We already have scripts to set tags properties like alarms and history for specific tags after reimporting them.

This should be possible using a combination of system.opc.browseServer (or system.opc.browse if you want a dangerous recursive version) and system.tag.configure to create new OPC tags.

Agree that the gain is completely subjective, but you might find that the host of advantages of using UDT’s on the SCADA side does provide a gain (not the least of which is having similar, if not identical data structures in both places).

I’m with Phil on this one, IMHO there is enough gain that it is worth the effort.

I am always impressed how quick doing the “drag&drop” from OPC Browser is. In less than 10 secondes we can delete and recreate more +10k tags.

Using your idea, would it knows the data type? And would it recreate the data structures with folders like it does with a Drag&Drop?

It would probably take A LONG TIME for a script like that to create +10k tags. It does take one minute for our reconfiguration script to set alarms and history to specific tags. However, we would probably be able to make the script “smart” enough to only replicate changes and ignore what already exists.

You’d have to create the folders yourself when you encounter an ObjectNode in the browse results and also look at the datatype indicated in each browse result to know what Ignition datatype to use when creating the tag.

Thanks Kevin, that is what I was expecting from using system.tag.configure.

It would be nice if Inductive would consider creating a function system.tag.importOPC(“OPCpath”) or similar.