How to use custom method to get tag tree browser selected field value?

- script used in list component (custom method i have written this script)

In line 18 in my script i don’t know how to call tag tree browser selected tag path to the line

- getting this error

please help me out get solution

i tested by giving line 18 like this

my output is

- getting output like this

i am trying to drag and drop tags from tag tree browser to list component

if any correction in my script please let me know

The selected paths should come over as part of the Transferable.

line 19 in your code is looking for the paths variable to be a list of lists.

In your test if you did:

paths = [['test']]

you would see the result you were expecting.

However, you should be able to get the paths from the Transferable that comes with the event object e

like this

paths = [[path] for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR)]

This list comprehension constructs a list of lists from the selected paths. It is functionally equivalent to the following:

newList = []
for path in e.getTransferable().getTransferData(ListOfQualifiedPath.FLAVOR):
    newList.append([path])

i am getting this error when i use this 3 lines this is the issue i am facing past one week . please give any alternative solution

my script

test_20210315225736.zip (7.3 KB)

my project file can you check anything needs to be change?

Okay, so I had some free time today, and this will be a nice to have for my application so I dug in a little bit more.

Turns out that if you have the Tag Browse Tree mode configured as a Readtime Tag Tree then you get a different Transferable type.

If your mode is set to ‘Realtime Tag Tree’ then the transferable that is used is a ListOfNodeBrowseInfo
If your mode is set to ‘Historical Tag Tree’ the the transferable that is used is a ListOfQualifiedPath

I am sure there are reasons for that in the background.

That means your code needs to change slightly to use the correct Transferable Flavor

NOTE: If you have added the listener in the InternalFramActivated event you will need to close the window in the designer and re-open it once the change has been made.

from java.awt.dnd import DropTargetAdapter, DropTarget
from com.inductiveautomation.ignition.client.tags.dnd import ListOfNodeBrowseInfo
		
class customDragDropListener(DropTargetAdapter):
	_comp = None
	def __init__(self,comp):
		DropTargetAdapter.__init__(self)
		self._comp = comp
				
	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = [[node.getFullPath()] for node in e.getTransferable().getTransferData(ListOfNodeBrowseInfo.FLAVOR) if not node.hasChildren() and node.getObjectType().toString() != 'Provider']
		self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)
				
ddl = customDragDropListener(self)
DropTarget(self,ddl)

Note that his will not accept a Folder or Provider, I didn’t take the time to handle that.

To properly handle these you will need to write a function which utilizes a recursive browse to gather the paths on a thread other than the GUI thread, should you want to handle a folder or provider in any way other than doing nothing. I have chosen to ‘ignore’ those items with this code.

1 Like

its working fine. thank you so much for your time. I have learned many things from you.

I would not call it a small change.

You’ll need to implement a recursive browse.

To do it properly you will need to use

system.tag.browse
system.util.invokeAsynchronous
system.util.invokeLater

If you look through the forum there are several examples and posts detailing the proper use of those functions.

2 Likes

@lrose

i just want to drga and drop only the tag path -"[MQTT Engine]Edge Nodes/Montreal/Energy/EPI/Total_Consumption_kWhTON"

i dont want to drag and drop [MQTT Engine]Edge Nodes/Montreal/Energy/EPI/Total_Consumption_kWhTON.EngUnit" not the path contains after the dot

is there any way to avoid and i need to show popup like if the drag and drop with .eng unit or some other thing

i want to indicate them please drag and drop the proper tag path

is there any way to add this feature in script?

put .split('.')[0] after the string will split it up around the dots and take the first one if thats the one you want

1 Like

thanks i will try to implement it according to my issue

i am getting output like this

[[[MQTT Engine]Edge Nodes/Vidalengo/Energy/EPI/Total_Consumption_kWhTON.EngHigh]]

i want to use if condition it .dot is there in ouput i want to show popup
other wise i want to pass

any idea for use if condition for my output?

i dont fully understand the question…
But i think this should do it
if '.' in string:

1 Like

exactly this is what i want
if ‘.’ in string:

simple when i drag and drop tag i dont want the string after the dot
image
i only want tag upto consumption_KWTON… if any person try to drag and drop with engunit or some other think i want to show popup
hope now you understood
thanks

1 Like

You can handle this in a couple of different ways.

  1. You can just split the path and ignore the property specification in the transferable.
  2. You can break apart the comprehension and show a message box, or pop up if you prefer.

In the second case you will need to determine if that means not excepting the entire drop or not.

Case 1

	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = [[node.getFullPath().split('.')[0]] for node in e.getTransferable().getTransferData(ListOfNodeBrowseInfo.FLAVOR) if not node.hasChildren() and node.getObjectType().toString() != 'Provider']
		self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)	

Case 2

	def drop(self,e):
		e.acceptDrop(e.getDropAction())
		paths = []
        addPaths = True
        for node in e.getTransferable(e.getTransferData(ListOfNodeBrowseInfo.FLAVOR):
            if not node.hasChildren() and node.getObjectType().toString() != 'Provider']:
                path = node.getFullPath().split('.')
                if len(path) == 1:
                    paths.append(path)
                else:
                    addPaths = False #set flag to not add paths
                    break #if were not accepting the drop, no reason to continue the loop
        if addPaths:
		    self._comp.data = system.dataset.addRows(self._comp.data,paths) if self._comp.data.columnCount > 0 else system.dataset.toDataSet(['Selected Tags'],paths)
        else:
            system.gui.messageBox('Your message here for invalid drops')
1 Like

thank you so much

getting error for case 2 script

Not sure how the 0 got in there, but it should be an e

for node in e.getTransferable(e.getTransferData(ListOfNodeBrowseInfo.FLAVOR):

I’ve edited the code to correct the bug.

1 Like

@lrose

Hi ,
I have tired same script in power table dragging and drop tags from tag tree browser to power table

its not working

any change we need to implement this feature in power table?

This code works just fine for me when the drop target is a power table. What doesn’t work? What error are you seeing?

may be again i will check and let you know