-function consLog(e){configs.log&&$.writeln(e)}function listMatchNames(e){for(var o=1;o<=e.numProperties;o++){var r=e.property(o);consLog(r.matchName+"("+r.name+")")}}function explodeLayer(e){if(consLog("==============\n=============="),e.length>1)alert("Select a single shape layer");else{var o=e[0];if(void 0!=o&&"ADBE Vector Layer"===o.matchName){var r=o.containingComp,t=o.property("Contents"),p=[];if(!(t.numProperties>configs.itemAmountWarning)||confirm("You have more than "+configs.itemAmountWarning+" elements. Execution time might be long, are you sure you want to continue ?")){for(n=t.numProperties;n>0;n--){var c=t.property(n);if(c.enabled){var a=r.layers.addShape();a.name=c.name,a.enabled=!1,p.push(a),copyLayerTransform(o,a),insertPropertyToContents(c,a.property("Contents"),"")}}for(var n=0;n<p.length;n++)p[n].enabled=!0}}else alert("Select a shape layer")}}function insertPropertyToContents(e,o,r){if(!o.canAddProperty(e.matchName))return!1;for(var t=o.addProperty(e.matchName),p=1;p<=e.numProperties;p++){var c=e.property(p);if(c.enabled&&t.canAddProperty(c.matchName)){consLog(r+c.matchName);var a=t.property(c.matchName)?t.property(c.matchName):t.addProperty(c.matchName);switch(c.matchName){case"ADBE Vector Filter - Merge":copyProperty("mode",c,a);break;case"ADBE Vector Materials Group":consLog(r+"-- skipped");break;case"ADBE Vector Graphic - Stroke":copyPropertyStroke(c,a);break;case"ADBE Vector Graphic - Fill":copyPropertyFill(c,a);break;case"ADBE Vector Transform Group":copyPropertyTransform(c,a);break;case"ADBE Vector Shape - Rect":copyPropertyRect(c,a);break;case"ADBE Vector Shape - Ellipse":copyPropertyEllipse(c,a);break;case"ADBE Vector Shape - Star":copyPropertyStar(c,a);break;case"ADBE Root Vectors Group":case"ADBE Vectors Group":case"ADBE Vector Group":insertPropertyToContents(c,t,r+=" ");break;case"ADBE Vector Shape - Group":copyPropertyShape(c,a);break;default:a.setValue(c.value)}}}}function copyProperty(e,o,r){r[e].setValue(o[e].value)}function copyPropertyShape(e,o){o.property("ADBE Vector Shape").setValue(e.property("ADBE Vector Shape").value)}function copyPropertyStroke(e,o){copyProperty("composite",e,o),copyProperty("color",e,o),copyProperty("strokeWidth",e,o),copyProperty("lineCap",e,o),copyProperty("lineJoin",e,o),copyProperty("miterLimit",e,o)}function copyPropertyFill(e,o){copyProperty("composite",e,o),copyProperty("fillRule",e,o),copyProperty("color",e,o)}function copyPropertyTransform(e,o){copyProperty("anchorPoint",e,o),copyProperty("position",e,o),copyProperty("scale",e,o),copyProperty("skew",e,o),copyProperty("skewAxis",e,o),copyProperty("rotation",e,o),copyProperty("opacity",e,o)}function copyLayerTransform(e,o){copyProperty("anchorPoint",e,o),copyProperty("position",e,o),copyProperty("scale",e,o),copyProperty("rotation",e,o),copyProperty("opacity",e,o)}function copyPropertyRect(e,o){copyProperty("shapeDirection",e,o),copyProperty("size",e,o),copyProperty("position",e,o),copyProperty("roundness",e,o)}function copyPropertyEllipse(e,o){copyProperty("shapeDirection",e,o),copyProperty("size",e,o),copyProperty("position",e,o)}function copyPropertyStar(e,o){copyProperty("shapeDirection",e,o),copyProperty("type",e,o),copyProperty("points",e,o),copyProperty("position",e,o),copyProperty("rotation",e,o),copyProperty("innerRadius",e,o),copyProperty("outerRadius",e,o),copyProperty("innerRoundness",e,o),copyProperty("outerRoundness",e,o)}function createUI(e){if(e instanceof Panel)var o=e;else(o=new Window("palette",configs.title,void 0,{resizeable:!0})).show();var r=o.add("button",[10,10,100,30],"Explode layer");return o.text=configs.title,o.bounds.width=120,o.bounds.height=40,r.onClick=function(){var e=(new Date).getTime();explodeLayer(app.project.activeItem.selectedLayers),consLog("Execution time : "+((new Date).getTime()-e)+"ms")},o}var configs={title:"Explode layer tool",log:!0,itemAmountWarning:50},myToolsPanel=createUI(this);
0 commit comments