Search everywhere - even within components

Hi!

I have some Adobe XD plugin developers telling me that the XD plugin API makes it impossible for developers to search for elements throughout the complete project if there are components involved.

Meaning: If there are elements nested in components it is impossible for a plugin-script to search and find those nested elements.

Is that true? And did anyone ever created a workaround-script for this basic functionality?

Thanks!

Sascha

1 Like

Hi @SakoAdo,

There is indeed an “edit context,” a restriction of which layers a plugin can edit. This usually means that a plugin can only edit selected layers and layers “close” to it (within the layer hierarchy).

Unfortunately, there are some edge cases there when it comes to components (formerly symbols). This (as it is right now) can prohibit plugins to edit contents of component layers, unfortunately.

It kind of depends on what you mean by “search”. The editing context only restricts editing the layer, “finding” it should be possible for plugins.

Unfortunately, there are also some restrictions on how plugins can interact with components within a document. As far as I’m aware, there’s currently no way for plugins to determine or manipulate the different states a component can have, manipulate, or “view” the list of components available in the assets panel, and so on. The APIs still need to catch up in this regard.

All in all, there are indeed some restrictions in this regard. Still, it really depends on what you need to do (just “searching through and viewing” shouldn’t be a problem if you don’t need more detailed information about the component’s “inner workings”). Also, manipulating content within components can be a problem (without, as far as I’m aware, any workarounds).

All in all, the plugin developer community is very much looking forward to ways to get around these restrictions, but “by itself”, the “editing layers inside a component problem” is real, so to speak.

I hope this helps,
Best,
Pablo

My use case is “find and select when criteria is met”. But basicly every use case where items and their properties need to be changed and not only “viewed” (which I guess is 99% of all usecases) are blocked by this “restriction”.

Are there any known workarounds developed for selecting ALL elements with certain criterias?

1 Like

Plugins can search the entire scenegraph, including components. Plugin API support for components is limited to read-only. They are called “SymbolInstance” and generally behave like a Group. Plugins can query the children of any node, starting at the document root, and build a recursive hierarchy of nodes. Let me know if you would like source code for that.

Selecting nodes is restricted by the edit context. Global search-and-replace is a commonly requested feature that unfortunately the plugins APIs do not support at this time due to document security concerns. Basically XD only allows plugins to edit nodes that the user has explicitly selected prior to invoking the plugin. Search-and-replace and other edits within the user’s selection is supported. Here is one plugin that does that:

1 Like

Hi David,

yes I talked to the developer of that plugin and he said: “Search and replace within all components is not possible due to API restrictions.” Basicly that´s why I am asking here for a workaround. So if it is possible to select something by script within a component IF the user selected the component prior to activating the plugin the big question is: Is there any way for me as a user to select EVERYTHING in my project including all components and nested components. So that then I can activate the plugin and it is then able to search and select everything that matches a certain criteria?

1 Like

There is no workaround for the edit context restrictions. Plugins can modify any node that is within the edit context, even nodes that are part of a group or component. However, simply selecting a node with a single-click or select-all does not necessarily put it in the edit context. That works for some nodes, like a shape drawn directly on an artboard. But nodes within a group or component might need to be double-clicked or cmd/ctrl-clicked to be added to the edit context. And changing the selection with the plugin API does not change the edit context either (changing the selection is considered editing the document). There selection.editContext and selection.isInEditContext() APIs are available to provide information about what nodes are in the edit context. So if the goal is for a plugin to change what is selected, that can be done, but only within the set of nodes that the user has explicitly placed in the edit context.

1 Like

Hi David,

thanks for the clarification. So to put it into your words:

The user can NOT place ALL nodes in the EditContext (And by that enable plugins to create “sub-selections by certain criterias” of all nodes). Basicly because XD does not offer any kind of dialog which shows ALL nodes in a way that the user can select them. Neither in the layer panel, the canvas/artboards or anywhere else. Correct?

Probably not the right place to ask, but do you know if the Figma API has the same restriction?

Thanks!

Sascha