Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

I am having trouble with text node in Google App script #21

Open
Blummer92 opened this issue Nov 13, 2019 · 0 comments
Open

I am having trouble with text node in Google App script #21

Blummer92 opened this issue Nov 13, 2019 · 0 comments

Comments

@Blummer92
Copy link

I am trying to route the text node to create text in Google App script. I basically have the code running through a loop to create the text at any instances that are created in Figma. I'm not sure why the API is not running. here is my code.

function myFunction() {
    var accessToken = "###-###-###"; // Please set your access token.
    var fileKey = "###-###-###"; // Please set the file key.

    var baseUrl = "https://api.figma.com/v1";
    var params = {
        method: "get",
        headers: {"X-Figma-Token": accessToken},
        muteHttpExceptions: true,
    };
    var fileInfo = JSON.parse(UrlFetchApp.fetch(baseUrl + "/files/" + fileKey, params))
    var children = JSON.parse(UrlFetchApp.fetch(baseUrl + "/textnode/" + fileKey + "?format=jpg&scale=3&ids=" + fileInfo.document.children.map(function(c) {return c.id}).join(","), params))
    if (!children.err) {

        var s = SlidesApp.create("sampleSlide");
        var shape = s.insertShape(SlidesApp.ShapeType.TEXT_BOX, 100, 200, 300, 60);
        var textRange = shape.getText();
        var selectionType = selection.getSelectionType();
        var keys = Object.keys(children.text);


        textRange.forEach(function(c, i) {
            textRange.setText(children.text[c]);
            textRange.insertText(chlidren.length);
            if (i != textRange.length - 1)s.insertSlide(i+1)
            });
    } else {
            throw new Error(children);
        }
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant