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.
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.
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.
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.
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...
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.