Skip to content

Instantly share code, notes, and snippets.

@fwextensions
Created August 26, 2011 22:53
Show Gist options
  • Save fwextensions/1174629 to your computer and use it in GitHub Desktop.
Save fwextensions/1174629 to your computer and use it in GitHub Desktop.
Importing a rich symbol
function insertSymbol(
inSymbolName,
inPath)
{
var dom = fw.getDocumentDOM();
var middleX = Math.round(dom.width / 2);
var middleY = Math.round(dom.height / 2);
try {
// first assume the symbol is already in the library and try to
// insert an instance. there doesn't seem to be an API to list
// the symbols in the document, so we just have to try it.
dom.insertSymbolAt(inSymbolName, {
x: middleX,
y: middleY
});
} catch (exception) {
// if we don't refresh the reference to the DOM, the call to
// importSymbol works, but it doesn't preserve the richness of
// the symbol for some reason. refreshing the dom var fixes
// that for most symbols, but some still don't work.
dom = fw.getDocumentDOM();
dom.importSymbol(inPath, true, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment