Jump to content


Photo

Accessing the "selected" symbols in the document library


  • Please log in to reply
1 reply to this topic

#1 section6

section6

    Fireworks Sparkle

  • Members
  • Pip
  • 1 posts

Posted 09 March 2010 - 03:30 PM

A lot of the functions like deleteSymbol and updateSymbol depend on which items are "selected" in the library panel (when [null] is passed).

Is there a way to access these selections?
or
Loop through the library?
or
Set selections via code?


End Goal:
I'm working on an insert symbol script that finds some method of preventing symbol duplication. And if existing symbols are used on the canvas it does not delete them.

#2 jdunning

jdunning

    Fireworks Ninja

  • Members
  • PipPipPipPipPip
  • 173 posts

Posted 10 March 2010 - 09:05 AM

Is there a way to access these selections?
or
Loop through the library?
or
Set selections via code?

Unfortunately, I don't think so.

What I've done to try to avoid duplicating symbols is this:

	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) {
				// the symbol isn't in the document yet, so import it.  we use
				// importFile instead of importSymbol because the former seems
				// to preserve some magic that allows you to turn it back into a
				// rich symbol if you later drag the same symbol from the Common
				// Library into the doc and replace existing instances. 
			dom.importFile(inPath, {
				left: middleX,
				right: middleX,
				top: middleY,
				bottom: middleY
			}, true);
		}
	}

But that doesn't help you with the selection in the panels.