Rbxlx - A .rbxlx file parser for NodeJS

Parsing .rbxlx files can be difficult to do using NodeJS since there are no libraries currently available for that, until now.

So what is it?

Simply put, it parses .rbxlx files (not .rbxl) in an organised manner. This can be useful in many ways and I personally use it to convert the files to objects where I then can for example find all the scripts with a specific name.

There are of course many others ways you can use this and one is for example importing a place file, changing the Color3 of all frames to something that you retrieved from an api and then importing it back to Roblox.

What does parsing mean?

It simply means that we break down the file into a more user friendly structure that is easier to work with than traditional xml files.

How do I use it?

This is a basic example on how to use it, in this case we parse a .rbxlx file and then output every Part in that file.

const rbxlx = require("../index.js");
const util = require("util");
const path = require("path");
const fs = require("fs");

rbxlx.parse(fs.readFileSync(path.join(__dirname, "test.rbxlx")))
.then(tree => {
    console.log("Parsed file!");

    var descendants = tree.getDescendants();
    for (var object of descendants) {
        if (object.class == "Part") {
            console.log("We found a Part named", object.getProperty("Name"));
        }
    }

    // You can also output the entire tree structure
    //console.log(util.inspect(tree, {depth: Infinity, colors: true}));
})
.catch(err => {
    console.log(`Could not parse file because: ${err.message}`);
})

It is available as a zip file:
rbxlx-master.zip (3.8 KB)

How do I import those instances?

You can use this module, if you want a demo on how to use it then check out this place.

Feedback

The parser isn’t perfect so if you have any general feedback on it or the module then feel free to contact me!

23 Likes

Wow, this is great! I’m going to try it out later.

Nice to see that we have an parser now but is there also a way to output a modified version of the tree into an rbxlx file again?

If I were you, I would’ve written that parser in Python. Node was built to run on the backend of the web stack - whereas I’ve personally seen more instances of Python scripts being executed on the shell. However, there’s always that case of an end user of your parser may have the former installed but may not wish to install the latter.

There’s a use case for both JS and Python. At the same time both can do command line and both be used for web stacks. I’d love to see both.

1 Like

This isn’t an option at the moment although it’s something that might be added.

The reason I went with NodeJS is because it’s a language that is quite widely used when it comes to api’s and that is what I had in mind when I made this. I do however agree that a Python port would be cool but it’s not really top priority, you could always have a go at doing it yourself though.

1 Like