[IGN-18211]system.config.getResources and collectionName=local

@paul-griffith Can we read resources in a specific collection ?

Exemple for devices:

moduleId="com.inductiveautomation.opcua"
typeId="device"
result = system.config.getResources(moduleId = moduleId, typeId = typeId)

for elm in result:
    system.perspective.print(elm)
16:51:56.657 [Browser Thread: 09e0169b-e7ee-4556-bfbd-a6b3dfd9959b] INFO Perspective.Designer.Workspace -- <PyResource: ResourceId{resourcePath=com.inductiveautomation.opcua/device/AB_SIG_GRAND_HAMEAU, collectionName=local}>
16:51:56.658 [Browser Thread: 09e0169b-e7ee-4556-bfbd-a6b3dfd9959b] INFO Perspective.Designer.Workspace -- <PyResource: ResourceId{resourcePath=com.inductiveautomation.opcua/device/AB_SIG_JENNER_SUD, collectionName=local}>

In the result, collectionName=local seems to mention that the listed devices are the result of the gateway devices available according overrides and the gateway mode active.
That's fine and it seems ok according the filesystem:

My gateway mode active is "DEV_DB_POSTGRES".
mode can have 3 value:

  • DEV_DB_POSTGRES
  • DEV_DB_MYSQL
  • DEV_DB_SQLSERVER

Filesystem:

C:\Program Files\Inductive Automation\Ignition\data\config\resources\DEV_DB_POSTGRES\com.inductiveautomation.opcua\device\
AB_SIG_JENNER_SUD
C:\Program Files\Inductive Automation\Ignition\data\config\resources\core\com.inductiveautomation.opcua\device
AB_SIG_GRAND_HAMEAU
C:\Program Files\Inductive Automation\Ignition\data\config\resources\DEV_DB_MYSQL\com.inductiveautomation.opcua\device
AB_ES_SV1
AB_SIG_GRAND_HAMEAU
AB_SIG_LA_PLAGE

But how can I browse for exemple the "DEV_DB_MYSQL" collection (gateway mode that is inactive) without a walk of the filesystem directory ?

I would like to list for exemple all the devices of a collection and then to remove them with system.config.delete.

Every PyResource has a getDefiningCollection() method as well as getCollection(). So you could get the "effective" list (all the devices) and then check it for ones defined specifically in the collection you're interested in.

moduleId="com.inductiveautomation.opcua"
typeId="device"
result = system.config.getResources(moduleId = moduleId, typeId = typeId)
targetCollection = "DEV_DB_MYSQL"

for elm in filter(result, lambda r: r.definingCollection == targetCollection):
    system.perspective.print(elm)

Thanks a lot again,
definingCollection is perfect to obtain the "source" collection of the resource :+1:

I think getResources could be enought for my use case, because I'm mainly interested in the devices resulting from the gateway mode active collection and core collection.

But, it would be awesome if we could have a script function to obtain only the resource of a targeted collection ?
In my example : devices of the collection "DEV_DB_MYSQL" that is not the gateway mode active...
I understand it could be a corner case...

No, I think it's a reasonable request, especially given all the other functions accept a collection name as an argument. I'll file a ticket.