// Fireworks JavaScript Command // Fireworks/Configuration/Commands/ var dom = fw.getDocumentDOM(); // document object function CreatePatternFromSelection() { // require active document if (!dom) return false; // user input var input, filename, validFilename = new RegExp('^[^\\\./:\*\?\"<>\|]{1}[^\\/:\*\?\"<>\|]{0,254}$'); do{ input = prompt('Enter a name:',input||''); filename = fw.appPatternsDir+'/'+input; }while(!validate()); function validate(){ if(input == null) return true; if(!validFilename.exec(input)) return alert('Invalid name! Only use names that are valid filenames.'); if(Files.exists(filename+'.png')) return fw.yesNoDialog('A pattern with this name already exists. Overwrite existing?'); return true; } if(input == null) return false; // copy and paste to new document dom.clipCopy(); newDom = fw.createDocument(); fw.setActiveWindow(newDom); dom = fw.getDocumentDOM(); dom.clipPaste(); dom.setDocumentCanvasSizeToDocumentExtents(true); dom.setDocumentCanvasColor("#ffffff00"); // export pattern to default dir dom.exportTo(filename,{ exportFormat:'PNG', colorMode:'32 bit', paletteTransparencyType:'rgba' }); fw.closeDocument(dom,false); } CreatePatternFromSelection();