How access other file by Figma API

I created a small plugin for creating Tables. I hope to create and access a small data Figma file in the community space to save the Table’s data styles that the table needs to use, and then how can I read the file?

In fact, this is a problem with reading files across files in Figma API. I wish any expert can enlight us, or give some clues and hints.

for example, can access it and clone it, but how to clone it?:joy: Which function I can use?


Here is the Screenshot, it is ugly because this plugin only can work but bounding one static Figma file, I hope it can work in any Figma file without any limitation

Plugins can only work within the limits of one file. The most you can do is import components from other files (libraries), and even then you have to know the component keys first, which you can’t get without opening the plugin in the library file first.

1 Like

Hi, Master Gleb, Thank you for coming,

Could I know which function should I use to get the component keys? I have already hung up a Figma file with full edit permissions in a URL, and already put all resource frames into it.

Could you let me know where is the introduction of this function?

Thanks :blush::pray:

Edit permissions and URLs have nothing to do with plugins. Open the file, open the plugin in that file, scan the file for the component you need (using something like root.findAll for example) and then get the key via component.key property.

1 Like

Hi, Dear Master Bleb, follow the advice your enlighted me, I create them correctly this Sunday! Like the GIF below here:
getComKey

Thank you for your comments!

Nic

Next step: I prefer to import the component by the key, but can you give me a tip: on how to import the component by JS,
I am failed when I import it,


figma.importComponentByKeyAsync(key)

1 Like

Hi, Tank, Thank you for reminding me of the “figma.” mistake I made, I fixed it, and it worked, but … there is some 404
So could you tell me some clue about the console error report?

For ComponentSetNode you need to use figma.importComponentSetByKeyAsync(key).

Tank, Thank you reply me so fast​:blush::+1:


I switch to:
importComponentSetByKeyAsync(“key’s string”);
But still display 404, something I did wrong?
importError01

Is the component with this key published in the library file?

I use a button event to get the component.key similar to what Gleb told me.

Here is how I copy the key below​:blush::sob::
importErrorCopyKey

I asked about something else.

The component whose key you got is in the library file? Is this file published as a library?

The above API methods only allow you to import components from libraries.

Oh, yes yes😊, the resource library file has been published,

and the test file already imports library in as green framed:

I will check my publish status, maybe somewhere is wrong, Thank you! Tank!:blush:

Very helpful, I chose another component, it is working, and I get a [promise]

so how do I copy the component into the current page?

Wait for the Promise to succeed and then create an instance of the imported component.

For example:

let importComponent = await figma.importComponentByKeyAsync(key);
importComponent.createInstance()
2 Likes

Hi, Tank,
I continue with your suggestion as below here: but it is doesn’t work, help please😂

Note that you are receiving a syntax error, not the plugin API error, which means your code is written incorrectly. Most likely you are trying to use await outside of an async function (or outside of any function for that matter). Make sure you are using async/await correctly.

Hi, Gleb, It is the first time using await, the situation is:
I can get promise as the image below here:

but I copy code(Tank66’s), and it logged error,

Could you help me with more complete/Entire code, sorry I’m a noob designer and I’m really stupid at coding😂
I feel like I’m at the gate, but I just “can’t get in”: I just can’t import this component from the library.