Programmatically Creating Blocks

Hello. I am attempting to add an API function (in api.js) to my custom Snap! instance that will allow me to programmatically generate blocks using JavaScript and a given Block name.

Currently, my API function looks like:

IDE_Morph.prototype.newBlock = function(options) {
    this.stage.world().add(this.stage.world().hand.children[0]);
};

Although this allows me to clone and place the block that is currently held, I could not seem to find a way to generate a new block by name (or clone a block that is loaded into the current Snap! project). How would I be able to accomplish this?

As a side question, how can I access the stack that is used for the undo/redo feature from within api.js? I was able to get the last-added block by adding console.log(this.dropRecord) to the ScriptsMorph.prototype.recordDrop function, but I get a constant value when running console.log(this.stage.scripts.dropRecord) in my API function (which does not change after I place a block).

Any suggestions that could help put me on the right track would be greatly appreciated. Thank you!

Check out this thread.