Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
This repository was 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

Description

@Blummer92

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);
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions