How to scrape views for all matching components

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.

Is this for designer only or runtime/perspective session?

1 Like

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

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

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.

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
2 Likes

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.

1 Like

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

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.

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

cough git with a separate branch for your experiment cough

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

1 Like

Honestly, @PGriffith 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:

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'

setVisiblity(self,False,'Label_1')

Show all components whose name contains 'Label_1'

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.

1 Like

:face_with_open_eyes_and_hand_over_mouth: :dotted_line_face:
aren't i just the oblivious idiot... thanks @lrose and @PGriffith .