Yes, the method you mentioned does what you need.
Also, your code snippet is missing a function with this method.
Yeh, I know.
Instance import is working, but I need to change for frameNode after import.
Thanks for the video, but I know how the “Detach instance” function works.
In this video, I didn’t see where the detachInstance method is used in your code.
As I understand it, it should be here:
Note that your prototype constant stores an array of InstanceNode, not the InstanceNode itself.
Sorry, you’re completely right.
This is an example for all code:
1 const protoComponent = "id";
2 const importProtoComponent = await figma.importComponentByKeyAsync(
3 protoComponent
4 );
5
6 const instanceProto = importProtoComponent.createInstance();
7 block.appendChild(instanceProto);
8
9 const prototype = figma.currentPage.findAll(
10 (n) => n.type === "INSTANCE" && n.name === "Prototype"
11 );
12
13 const lastPrototype = prototype[prototype.length - 1];
14
15 lastPrototype.detachInstance();
16
Now the last instance from the array will be detached, otherwise you will get an error on the last line.
Yeah.
I managed to do what I wanted, but I don’t know if this is the best way.
1const protoComponent = "id";
2 const importProtoComponent = await figma.importComponentByKeyAsync(
3 protoComponent
4 );
5
6 const instanceProto = importProtoComponent.createInstance();
7 block.appendChild(instanceProto);
8
9 const prototype = figma.currentPage.findAll(
10 (n) => n.type === "INSTANCE" && n.name === "name"
11 );
12
13 const lastPrototype = prototype[prototype.length - 1];
14
15 if (lastPrototype && lastPrototype.type === "INSTANCE") {
16 const newFrame = figma.createFrame();
17
18 newFrame.x = lastPrototype.x;
19 newFrame.y = lastPrototype.y;
20 newFrame.resize(lastPrototype.width, lastPrototype.height);
21
22 for (const child of lastPrototype.children) {
23 newFrame.appendChild(child.clone());
24 }
25
26 block.appendChild(newFrame);
27
28 lastPrototype.remove();
29 }
30
I don’t know why you abandoned the detachInstance method, but I would use it, with the error handling in the previous example.
Because it was wrong… but I checked and it was just a typing error \o/.
1Property 'detachInstance' does not exist on type 'SceneNode'.
2 Property 'detachInstance' does not exist on type 'FrameNode'.
3
Thank you again!