/* ------------------------------------ Make Guides From Selection v1.5 ------------------------------------ Created by Matt Stow 2007 http://www.mattstow.com With thanks to Aaron Beall ------------------------------------ */ (function() { if (fw.documents.length == 0) { return; } if (fw.selection != null && fw.selection.length > 0) { var dom = fw.getDocumentDOM(); var originalSelection = [].concat(fw.selection); var hasEffects = 0; for (var i in originalSelection) { if ((originalSelection[i].effectList) && (originalSelection[i].effectList.effects.length)) { hasEffects++; } } if (hasEffects > 0) { var incEffects = fw.yesNoDialog("Include effects boundaries when drawing guides?"); } var myGuides = prompt("(L)eft, (R)ight, (T)op, (B)ottom, (A)ll,\n(H)orizontal through centre, (V)ertical through centre, (C)omplete\nTo combine, separate values with a comma e.g: L,T,V","A"); if (myGuides == null) { return; } for (l in dom.layers) { if (dom.layers[l].name == "Web Layer") { var webLayer = l; break; } } var webLayerVis = dom.frames[0].layers[webLayer].visible; if ((fw.activeTool == "Scale") || (fw.activeTool == "Skew") || (fw.activeTool == "Distort")) { fw.activeTool = "Marquee"; } var bitmapTool = false; if ((fw.activeTool == "Marquee") || (fw.activeTool == "Oval Marquee") || (fw.activeTool == "Lasso") || (fw.activeTool == "Polygon Lasso") || (fw.activeTool == "Magic Wand")/* || (fw.activeTool == "Brush") || (fw.activeTool == "Pencil") || (fw.activeTool == "Eraser tool") || (fw.activeTool == "Blur tool") || (fw.activeTool == "Sharpen tool") || (fw.activeTool == "Dodge tool") || (fw.activeTool == "Burn tool") || (fw.activeTool == "Smudge tool") || (fw.activeTool == "Rubber Stamp") || (fw.activeTool == "Replace Color tool") || (fw.activeTool == "Red Eye Removal tool")*/) { bitmapTool = true; } if ((hasEffects > 0) && (incEffects == false)) { var effectsOld = new Array(); for (var i in originalSelection) { if (!originalSelection[i].effectList) { continue; } var effects = originalSelection[i].effectList.effects; for (f in effects) { var effect = {}; for(var p in effects[f]){ if (p != "javascriptString") { effect[p] = effects[f][p]; } if (p == "EffectIsVisible") { if (effects[f][p] == true) { effectsOld.push([i,f]); } } } effect.EffectIsVisible = false; if (originalSelection[i].toString() == "[object Text]") { $.sleep(170); // A sleep is needed on text objects for it to work correctly! } effects[f] = effect; } } } if ((originalSelection.length == 1) && (originalSelection[0].toString() == "[object SliceHotspot]")) { // Do nothing. A selected slice will always be at [0] being higher in the stack. } else if ((originalSelection.length == 1) && (originalSelection[0].toString() == "[object Hotspot]")) { // Again do nothing. A selected hotspot will always be at [0] being higher in the stack. } else { if (bitmapTool == false) { fw.getDocumentDOM().copyToHotspot("slice", "single", true); } } var selectBounds = dom.getSelectionBounds(); var selectLeft = selectBounds.left; var selectTop = selectBounds.top; var selectRight = selectBounds.right; var selectBottom = selectBounds.bottom; var middleVertical = selectLeft+parseInt((selectRight-selectLeft)/2); var middleHorizontal = selectTop+parseInt((selectBottom-selectTop)/2); if ((originalSelection.length == 1) && (originalSelection[0].toString() == "[object SliceHotspot]")) { // Do nothing. A selected slice will always be at [0] being higher in the stack. } else if ((originalSelection.length == 1) && (originalSelection[0].toString() == "[object Hotspot]")) { // Again do nothing. A selected hotspot will always be at [0] being higher in the stack. } else { if (bitmapTool == false) { fw.getDocumentDOM().deleteSelection(false); fw.selection = originalSelection; if (webLayerVis != dom.frames[0].layers[webLayer].visible) { dom.frames[0].layers[webLayer].visible = false; } } } if (hasEffects > 0) { if (incEffects == false) { for (var i in originalSelection) { if (!originalSelection[i].effectList) { continue; } var effects = originalSelection[i].effectList.effects; for (f in effects) { var effect = {}; for(var p in effects[f]){ if (p != "javascriptString") { effect[p] = effects[f][p]; } if (p == "EffectIsVisible") { for (a in effectsOld) { if ((effectsOld[a][0] == i) && (effectsOld[a][1] == f)) { effect.EffectIsVisible = true; } } } } effects[f] = effect; } } } } var guidesArray = myGuides.split(",",12); for ( i = 0; i < guidesArray.length; i++ ) { var makeGuide = guidesArray[i].toUpperCase(); makeGuide = makeGuide.replace (" ", ""); switch (makeGuide) { case "L": dom.addGuide(selectLeft, "vertical"); break; case "R": dom.addGuide(selectRight, "vertical"); break; case "T": dom.addGuide(selectTop, "horizontal"); break; case "B": dom.addGuide(selectBottom, "horizontal"); break; case "TL": dom.addGuide(selectTop, "horizontal"); dom.addGuide(selectLeft, "vertical"); break; case "TR": dom.addGuide(selectTop, "horizontal"); dom.addGuide(selectRight, "vertical"); break; case "BL": dom.addGuide(selectBottom, "horizontal"); dom.addGuide(selectLeft, "vertical"); break; case "BR": dom.addGuide(selectBottom, "horizontal"); dom.addGuide(selectRight, "vertical"); break; case "V": dom.addGuide(middleVertical, "vertical"); break; case "H": dom.addGuide(middleHorizontal, "horizontal"); break; case "A": dom.addGuide(selectLeft, "vertical"); dom.addGuide(selectRight, "vertical"); dom.addGuide(selectTop, "horizontal"); dom.addGuide(selectBottom, "horizontal"); break; case "C": dom.addGuide(selectLeft, "vertical"); dom.addGuide(selectRight, "vertical"); dom.addGuide(middleVertical, "vertical"); dom.addGuide(selectTop, "horizontal"); dom.addGuide(selectBottom, "horizontal"); dom.addGuide(middleHorizontal, "horizontal"); break; default: alert("Incorrect value entered.\n\nAcceptable values are (L)eft, (R)ight, (T)op, (B)ottom, (A)ll,\n(H)orizontal through centre, (V)ertical through centre, (C)omplete"); } dom.setShowGuides(true); } } else { alert("Please make a selection and try again."); } })()