Passing current folder name into a Python script

Howdy,

I’ve written my own script that I’m calling via expression tag that returns how many medium-critical alarms are currently unacknowledged. The script works very well, but I’m trying to dynamically pass in the current folder name. I have hundreds of folders to put this expression tag into, so I’m looking for any sort of time saving features I can.

This is the expression that I am calling:

runScript("shared.alarmsMisc.alarmActiveInFolder('CRAH/CIDF_2')",3000)

As a workaround I am using a string memory tag that has the containing folder hard coded. If any of y’all can find me a better solution, I can switch the memory tag to an expression tag but this will work for now…

runScript("shared.alarmsMisc.alarmUnackedInFolder('"+{[.]_AlarmFolderName}+"')",3000)

What we do is create Integer expression tags in each tag area folder and then use
toInt(runScript(“len(system.alarm.queryStatus(state=[‘ActiveUnacked’],source=[‘PLAS/Board/’]))”,2000))

This counts the ActiveUnacked alarms in that folder and sets the tag value to the number.
You can then create one for ActiveAcked as well.

1 Like

So you’d like to automate the part where “CRAH/CIDF_2” gets typed in?

You could simply wrap that expression tag in a UDT (FolderAlarmCounter UDT).
Then in your existing expression tag which is now within a UDT instance, use:

split("{PathToParentFolder}",'/')[0]

To get the folder name.

1 Like

MMaynard,

Thanks for the reply. That’s more or less what I am trying to do, but I want the source parameter to be dynamic. My custom scripts are calling ‘system.alarm.queryStatus’ with some code wrapped around it. I wrote a custom script because I might need to modify the parameters to ‘system.alarm.queryStatus’ and I have hundreds of calls to it.

Thanks again.

bfuson,

That seems like a clever solution. I had thought about solving this with UDTs, but didn’t investigate much further. I think I might have to try this out later. I’m resorting to hard coding the path for now, but in a separate memory tag so I can modify it later.

If you really need to put your expression tag into hundreds of folders, I think this UDT ‘trick’ is the way to go.
It keeps you from needing to specify the folder path at all. You simply make a new UDT instance in the folder and you’re done.

1 Like

bfuson,

While you were writing up that post suggesting I use UDTs, I finally just say what the heck and went for it. I came back to post just that and I saw this post. You’re right that the best way to solve this is with UDTs. I’m literally just copying and pasting the one UDT instance into all of my folders now. Now while I marked your previous answer as the solution, I did have to make a small modification to your code because it was causing problems with subfolders. Here’s what I came up with for that string expression that returns the same string as when you right click on a device folder and select “Copy Tag Path”:

replace("{PathToParentFolder}","/"+"{InstanceName}","")
1 Like