# How to scrape views for all matching components

**URL:** <https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [January 30, 2024, 9:26pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981 "2024-01-30T21:26:00Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [January 30, 2024, 9:26pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/1 "2024-01-30T21:26:00Z")

</div>

i'd like to build a script to scrape a view for all it's components whose name matches a filter, then set a prop value for all of the resultant views. is there something like this already built in? basically something equivalent to the JS `getDocumentById` kind of thing.

why? because i want to have a button that will toggle the visibility for EVERY DAMN THING in the view.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [January 30, 2024, 10:26pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/2 "2024-01-30T22:26:04Z")

</div>

Is this for designer only or runtime/perspective session?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 30, 2024, 10:28pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/3 "2024-01-30T22:28:28Z")

</div>

> [@Iterate through all components programatically in Perspective?](https://forum.inductiveautomation.com/t/iterate-through-all-components-programatically-in-perspective/32938/21):
>
> We went with this one so our util library looks like def getComponents(element): def walkComponents(component): for child in component.children: yield child walkComponents(child) return walkComponents(element) def parseContainer(container): return { c.name: c.custom["outValue"] for c in getComponents(container) if "outValue" in c.custom } and call parseContainer on a container works as we expect it too. Decided on this one because it's the most readable to me and without need…

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [January 31, 2024, 2:09pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/4 "2024-01-31T14:09:04Z")

</div>

> [@ryan.white](#):
>
> designer only or runtime/perspective session?

designer-only session, preferably. but if not, i'm happy to hide a button with the script on it. nobody will find it.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 31, 2024, 2:11pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/5 "2024-01-31T14:11:17Z")

</div>

> [@ian.sebryk](#):
>
> why? because i want to have a button that will toggle the visibility for EVERY DAMN THING in the view.

All at once, or separately ?  
Does that include the button itself ? 😃

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [January 31, 2024, 2:14pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/6 "2024-01-31T14:14:36Z")

</div>

> [@pascal.fragnoud](#):
>
> All at once

all at once. by way of explanation, there's a ton of UI elements that activate based on which type of asset is being managed because they all have different feature cards for the base unit. because of the spaghetti, things like CSS and scripts are per component. and they aren't labeled. like. at all. so i just want to turn their visibility ALL on so i can just click the UI, find the component in the list of `'label\_1', 'label\_2', etc. and start fixing the nightmare. so the button would just toggle visibility while i'm working.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 31, 2024, 2:18pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/7 "2024-01-31T14:18:13Z")

</div>

Frankly, for this use case, I'd go the quick and dirty way.

1. make a backup of the view, because things break and we don't like broken things
2. copy the view's json (shift + right click on the view in the project browser)
3. paste it in an editor
4. find and replace `visible: false`, `display: none`, etc
5. paste the json back

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [January 31, 2024, 2:22pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/8 "2024-01-31T14:22:42Z")

</div>

Honestly any other way of messing with the **designer** is gonna be a pain, because the designer is a mix of java/swing and html/react...

The origin perspective view file is quite easy to edit (its just a json). but edits on the file dont really register instantly. So you would ahve to close and open the view again.

Scripting ways would require you to put in a button which is also messy...

so yh copy json and edit in an advance text editor. Take a backup because if you replace something wrong the view gets broken and you'll be unable to open it again.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [January 31, 2024, 2:27pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/9 "2024-01-31T14:27:14Z")

</div>

> [@pascal.fragnoud](#):
>
> find and replace `visible: false`, `display: none`, etc

this won't disturb the bindings, i'm assuming? have to ask to be sure. and, yeah, backup backup backup.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [January 31, 2024, 2:29pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/10 "2024-01-31T14:29:12Z")

</div>

> [@ian.sebryk](#):
>
> this won't disturb the bindings, i'm assuming?

It will. Good thing you had a backup !

Find/replace won't work where there's a binding, so I guess a recursive script to parse the json, change the value, then output the modified json is in order.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [January 31, 2024, 2:30pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/11 "2024-01-31T14:30:46Z")

</div>

dang it. then we'll have to go the JS route. can you guys point me to the correct resource?

---

<div class="post-metadata">

**Author:** ![Tim\_Carlton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim_carlton/32/52835_2.png) [@Tim\_Carlton](https://forum.inductiveautomation.com/u/Tim_Carlton)\
**Post date:** [January 31, 2024, 5:03pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/12 "2024-01-31T17:03:32Z")

</div>

_cough_ git with a separate branch for your experiment _cough_

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [January 31, 2024, 5:12pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/13 "2024-01-31T17:12:36Z")

</div>

bruh. BRUH! believe me. i come from a Git-centric world. these guys here are like: 'oh, too much work; too confusing'. 🤬 it was literally the first thing i proposed when i got here...

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [January 31, 2024, 6:28pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/14 "2024-01-31T18:28:31Z")

</div>

Honestly, @paul-griffith posted the answer earlier. You just need to modify it for your needs.

I would recommend putting these functions in a utility script library, but then you can call them directly from a button on the view. Tested and works:

```auto
def getComponents(element):
	def walkComponents(component):
		for child in component.children:
			yield child
			walkComponents(child)
	return walkComponents(element)
	
def setVisibility(self, makeVisible, flt):
		
	isMatch = lambda element: flt.upper() in element.name.upper()
		
	for comp in filter(isMatch, getComponents(self.view.rootContainer)):
		comp.meta.visible = makeVisible

```

Hide all components whose name contains 'Label\_1'

```auto
setVisiblity(self,False,'Label_1')

```

Show all components whose name contains 'Label\_1'

```auto
setVisiblity(self,True,'Label_1')

```

Should be simple enough to modify the code to show or hide all components as needed. No need for editing the JSON at all.

---

<div class="post-metadata">

**Author:** ![ian.sebryk](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ian.sebryk/32/49319_2.png) [@ian.sebryk](https://forum.inductiveautomation.com/u/ian.sebryk)\
**Post date:** [January 31, 2024, 6:40pm UTC](https://forum.inductiveautomation.com/t/how-to-scrape-views-for-all-matching-components/84981/15 "2024-01-31T18:40:21Z")

</div>

> [@lrose](#):
>
> Honestly, @paul-griffith posted the answer earlier

🫢 🫥  
aren't i just the oblivious idiot... thanks @lrose and @paul-griffith .
