Disable overlay-opt-out option for all objects in a perspective view

Hello,
Is it possible to disable the “overlay-opt-out” option for all objects in a perspective view?
Like, put some python code in the view startup script.

No, it’s not an exposed property of the component - it’s a setting for the binding.

I presume you want to do this in runtime, Nader, not dev? In dev, you could just add this into the View’s json via a script (i copy json to clipboard and modify the clipboard then paste back over the top of the view)

1 Like

Very interesting trick, no I just want it in dev mode.
When I paste it back in over view, it create another root inside main root instead of overwrite it.
How exactly you do that?
And also in json where and what should write to disable overlay opt out ?

You need to Shift+Right click on the View and then you can Paste Json. That’s how you should copy it as well.
I’ve marked the overlay opt out in a very basic flex View with a single Label and binding, below:

{
	"custom": {},
	"params": {},
	"props": {},
	"root": {
		"children": [
			{
				"meta": {
					"name": "Label"
				},
				"position": {
					"basis": "32px"
				},
				"propConfig": {
					"position.grow": {
						"binding": {
							"config": {
								"fallbackDelay": 2.5,
								"mode": "direct",
								"tagPath": "[default]Tag/Path"
							},
							"overlayOptOut": true,   <==== OVERLAY OPT OUT
							"type": "tag"
						}
					}
				},
				"props": {
					"text": "Label"
				},
				"type": "ia.display.label"
			}
		],
		"meta": {
			"name": "root"
		},
		"props": {
			"direction": "column"
		},
		"type": "ia.container.flex"
	}
}
1 Like

The only problem is I have 50 object each has 5 binding and I want all overlay opt out to be true and it is also hard to edit it in view json.
I hope we have global option for each view.

It’s actually fairly easy to work with json, once you grasp the structure and how to work with it in Python. Essentially you’re just working with lists and dictionaries, and you just need to add a new key into the dictionary for example in this case if the dictionary has a “binding” key (maybe some other constraints as well if you need)

This is Python 3.9, but you can get something working in Ignition’s Jython as well using the java clipboard getter.
This is just a bastardised version of some of my script functions to do stuff with json objects. I work purely with json copied to clipboard, and I have a main function that does the common stuff like read the clipboard and convert into a json object, run it through a ‘parsing function’ and then convert back into text and into the clipboard.

import win32clipboard # part of library: pywin32 (has C dependencies)
import json # (pure Python library)

def setClipboard(text):
    # set clipboard data
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText(text)
    win32clipboard.CloseClipboard()


def getClipboard():
    # get clipboard data
    win32clipboard.OpenClipboard()
    data = win32clipboard.GetClipboardData()
    win32clipboard.CloseClipboard()

    return data

def main_parse_clipboard_json(parsing_function, **kwargs):
    # make sure you copy some tag json first to the clipboard!
    json_str = getClipboard()
    json_obj = json.loads(json_str)
    
    if isinstance(json_obj, list):
        for i in range(len(json_obj)):
            json_obj[i] = parsing_function(json_obj[i], **kwargs)
    elif isinstance(json_obj, dict):
        json_obj = parsing_function(json_obj, **kwargs)

    if json_obj != -1:
        json_str = json.dumps(json_obj)
        json_str = json_str.replace(":True", ":true").replace(":False", ":false")
        setClipboard(json_str)


# example parsing function to pass into main_parse_clipboard_json
def pf_json_do_something(obj):
    """
    Description:
    PARSING FUNCTION
    This function will set the execution mode of all expression tags to event driven
    """
    this_fn = pf_json_do_something

    if isinstance(obj, list):
        for i in range(len(obj)):
            obj[i] = this_fn(obj[i])

    if isinstance(obj, dict):
        if 'valueSource' in obj and obj.get('valueSource', None) == 'expr':
            obj['executionMode'] = 'EventDriven'

        if 'tags' in obj:
            obj['tags'] = this_fn(obj['tags'])

    return obj


# call the function
main_parse_clipboard_json(pf_json_do_something)
1 Like

I quickly tested this parsing function on the view json example I posted above, and this will add/set any binding to opt out of overlay. I haven’t tested it for anything else so perhaps some conditions i’ve missed. I’ve tested it with my cutdown code in my previous post too

def pf_view_json__add_overlayOptOut(obj):
    """
    Description:
    Adds overlayOptOut to all bindings within a View
    """

    this_fn = pf_view_json__add_overlayOptOut
    if isinstance(obj, list):
        for i in range(len(obj)):
            obj[i] = this_fn(obj[i])

    # if the obj is a dict, check if it is a tag that is opc and make sure its valueSource defines it as opc
    if isinstance(obj, dict):
        # add the overlayOptOut option if the object has a binding
        if "binding" in obj:
            obj['binding']['overlayOptOut'] = True

        # loop through each key in the dictionary and parse these as well
        for key in obj:
            if isinstance(obj[key], dict):
                obj[key] = this_fn(obj[key])
            elif isinstance(obj[key], list):
                for i in range(len(obj[key])):
                    obj[key][i] = this_fn(obj[key][i])

    return obj
2 Likes