I have a ton of existing direct OPC tags that need to be converted to UDT's to match standards of current programming. In the end, I just need the original OPC tag path to end up as a parameter of the updated UDT.
Is there any quick way to do this? Originally, I was thinking possible with Find/Replace in a json export, but where the parameters of both span multiple lines and have different properties, I'm not sure that is possible. Would some sort of script work to browse tags and change the type?
You can say that again! While it's pretty cool when you finally get the statement right, I could have written something in python, welcomed the next new year, and celebrated the following Christmas in the time it takes to work it out
If you're familiar with batch or powershell though it might be more logical. I struggle with these as well as I just havebt had the chance or desire to learn them properly
Yeah. I'm struggling at the moment just figuring how to direct the program to the file I need to work on etc. I have stuff installed. Can't even get to where I need to come up with the syntax of replacement I need. Just trying to do a sample still.
@PGriffith I've been trying with the sample json string from your other linked forum note. Here's some snips of my setup. I'm missing like a quote or how I'm supposed to reference the file directory or something dumb I'm sure.
Looks like some funky quotes snuck into what you're trying. Try recopying, or put it into a text editor and ensuring those are true " characters and there's no other funky stuff.
If it's any help, this is my end goal with a sample piece of json export.
I've highlighted the piece of addressing that would need to be retained. If anyone wants to put together the "magic sauce" for Command Shell to make this happen, it would make my weekend. I just don't have as much time to learn a 15th programming language/software lol.
That would be awesome. I'm hoping to have some working solution by mid next week if possible. It's not the end of the world if you can't get to it. I know it's all out of the kindness of our hearts to help each other out and for that I'm grateful.
When I'm back I'll post it. I needed it whenever I created udts from a selection of standard tags because when you just do a find replace kn the json to replace the elements with parameters it makes them static not bindings. My script goes through and converts them to bindings
I'm sorry, I never did get to trying out your script. I had the bug to learn this jq stuff as I figured it could be useful for a lot of things and be quite elegant in it's purpose. That being said, I thought I'd share what finally worked for me. Ultimately, I learned that you can install Ubuntu on windows and seems to be a cleaner interface to use jq from than windows powershell.
jq 'walk(if type == "object" and .valueSource == "opc" and .name == "Service" then {"name": "Service","typeId": "Logix/ControlBit","parameters":{"ParentPath":{"dataType": "String","value": (.opcItemPath)},"BaseScanClass": {"dataType": "String","value": (.tagGroup)}},"tagType": "UdtInstance","tags": [{"name": "Output","tagType": "AtomicTag"},{"name": "AccessLevel","tagType": "AtomicTag"},{"name": "_rev","tagType": "AtomicTag"},{"name": "LogRequired","tagType": "AtomicTag"}]} else . end)' serviceExport.json > serviceImport.json
Here's a snapshot of my original test tags. I wanted to change the Service Tag (OPC) for Pump 1 to be a UDT like is show under Pump 2.
I exported these 2 folders to a file called serviceExport.json. Then in Ubuntu, I simply just read the file to view it's contents. Mostly for comparison before and after.
Oh wow, I think I completely misread your OP and question... I thought you wanted to convert OPC tags that were changed to memory tags for testing, back to OPC tags.
The equivalent of giving you a lamb yiros when you ordered a pizza