{"id":997,"date":"2022-03-23T00:46:00","date_gmt":"2022-03-23T00:46:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=997"},"modified":"2022-03-23T00:46:00","modified_gmt":"2022-03-23T00:46:00","slug":"997","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2022\/03\/23\/997\/","title":{"rendered":"Adobe Illustrator \u62fc\u7248\u66ff\u6362\u5bf9\u9f50.jsx"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2022\/03\/2124898041.webp\" alt=\"ai_jsx.webp\" title=\"ai_jsx.webp\"><br \/>\u5f88\u65e9\u662f\u4ecegithub\u641c\u7d22\u5230\uff0c\u7528\u6765\u6279\u91cf\u66ff\u6362logo\u65f6\u6bd4\u8f83\u597d\u7528\uff0c\u6700\u8fd1\u5728\u62fc\u7248\u5de5\u4f5c\u4e2d\u6bd4\u8f83\u597d\u7528\uff0c\u6240\u4ee5\u590d\u5236\u4e00\u4efd\u6539\u540d <code>A \u62fc\u7248\u66ff\u6362\u5bf9\u9f50<\/code>\u3002<br \/>\u811a\u672c\u5728\u5904\u7406\u5f88\u591a\u7269\u4ef6\u7684\u65f6\u5019\u4f1a\u62a5\u9519BUG\uff0c\u54ea\u5929\u6709\u7a7a \u7cbe\u7b80\u4e00\u4e0b\uff0c\u770b\u770b\u80fd\u5426\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<h2>Adobe Illustrator \u62fc\u7248\u66ff\u6362\u5bf9\u9f50.jsx<\/h2>\n<pre><code>\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/Copy to Object(s) v7 -- CS,CS2,CS3\n\/\/ Hacked again by Nathaniel Vaughn KELSO\n\/\/ Last modified: 2008.March.30\n\/\/ Created: 2007.July.7\n\/\/ at Hyattsville, MD\n\/\/ Version 2\n\/\/ (c) nvkelso2008@gmail.com (but remove the 2008 bit)\n\/\/ \"Multiple-object-replacement\" hack by Iain Henderson\n\/\/ iain@addition.com.au\n\/\/\n\/\/&gt;=--------------------------------------\n\/\/ User selects two (or more) objects:\n\/\/ This script copies the top most object to the position and size of\n\/\/ all other selected objects.\n\/\/\n\/\/Version 2 update: now adjusts stroke based on difference in area.\n\/\/Version 3 update: now accepts multiple targets (Thanks Iain)\n\/\/Version 4 update: Deselects everything but source object\n\/\/  --this makes it easy to delete the source object if you wish,\n\/\/  -- also this makes the older \"Replace-Object\" script obsolete.\n\/\/Version 5 update: option to NOT transform to fit original shape\n\/\/  -- with additional option flag to register the replacing shape to\n\/\/     the being-replaced shape's center instead of upper-left corner\n\/\/TODO: add flag to delete \"master\" replacing symbol on completion\n\/\/&gt;=--------------------------------------\n\/\/ JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com\n\/\/copyright full text here:  http:\/\/www.wundes.com\/js4ai\/copyright.txt\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\n    \/\/initialize vars\n    \/\/\n    \/\/*******************************************************\n    \/\/ Toggles for scaling object, fitting to original, offset to center\n    \/\/toggle for scaling stroke: set to true to scale stroke.\n    var scaledStroke = false;                            \/\/ when fitting original dimensions, scale the stroke\n    var scaledObject = false;                            \/\/ fit to original dimensions\n    var scaleMethod = \"scaleToFit\";                    \/\/ if true, do NOT scale to fit original bounds but favor the smallest percentage of X or Y scaling for both X and Y\n    var scalingCentered = true;                            \/\/ register with center of being-replaced object\n    var groupFindAndReplaceResults = false;        \/\/ often not desired\n    var keepReplacedSelected = true;                \/\/ the result\n    var keepReplaceWithObjSelected = true;        \/\/ the model object that everything is replaced with\n    var deleteReplaceWithObj = true;                \/\/ the model object that everything is replaced with\n\nvar selObjs = \"Please select at least two objects on the page.\";\nvar docRef = activeDocument;\nif (documents.length&gt;0) {\n    if (docRef.selection.length &gt; 1) {\n        mySelection = docRef.selection;\n        var sourceObj = docRef.selection[0];\n        \/\/if object is a (collection of) object(s) not a text field.\n        if (mySelection instanceof Array) {\n            \/\/*******************************************************\n            \/\/create stroke Array\n            var strokeArray = new Array();\n            \/\/create bounding objects\n            \/\/********************************************************\n            var origBounds = mySelection[0].geometricBounds;\n\n            \/\/define paramaters of top object\n            var oul_x = origBounds[0];\n            var oul_y = origBounds[1];\n            var olr_x = origBounds[2];\n            var olr_y = origBounds[3];\n            var oSelWidth = (olr_x-oul_x);\n            var oSelHeight = (oul_y-olr_y);\n            var oSelPos = [oul_x, oul_y];\n            \/\/ *********************************************************\n            var initBounds;\n            var ul_x;\n            var ul_y;\n            var lr_x;\n            var lr_y;\n            var mySelWidth;\n            var mySelHeight;\n            var mySelPos;\n\n            var alterObjectArray = new Array();\n\n            for (var i=0; i &lt; mySelection.length; i++) {\n                eval('subArray' + i + '=' + 'new Array()');\n                eval('subArray' + i + '[\"object\"]' +  '=' + mySelection[i]);\n                initBounds = mySelection[i].geometricBounds;\n                ul_x = initBounds[0];\n                ul_y = initBounds[1];\n                lr_x = initBounds[2];\n                lr_y = initBounds[3];\n                mySelWidth = (lr_x-ul_x);\n                mySelHeight = (ul_y-lr_y);\n                mySelPos = [ul_x, ul_y];\n                mySelOffsetXpos = (ul_x + mySelWidth \/ 2 - oSelWidth \/ 2);\n                mySelOffsetYpos = (ul_y - mySelHeight \/ 2 + oSelHeight \/ 2);\n                eval('subArray' + i + '[\"width\"]=' + mySelWidth);\n                eval('subArray' + i + '[\"xpos\"]=' + ul_x);\n                eval('subArray' + i + '[\"ypos\"]=' + ul_y);\n                eval('subArray' + i + '[\"height\"]=' + mySelHeight);\n                eval('subArray' + i + '[\"offsetXpos\"]=' + mySelOffsetXpos);\n                eval('subArray' + i + '[\"offsetYpos\"]=' + mySelOffsetYpos);\n\n                eval('alterObjectArray.push(subArray' + i + ')');\n            }\n\n            for (var i=1; i &lt; alterObjectArray.length; i++) {\n                \/\/find proportional Difference\n                \/\/average height and width to find new stroke\n                if (scaledStroke == true ) {\n                    var wdiff = mySelWidth\/oSelWidth;\n                    var whght = mySelHeight\/oSelHeight;\n                    var propDiff = (wdiff+whght)\/2;\n                } else {\n                    var propDiff = 1;\n                }\n                \/\/mark stroked Items\n                \/\/apply transforms\n                var newGroup = mySelection[i].parent.groupItems.add();\n                \/\/modify move behavior for changes in JS for CS...\n                if (version == \"10.0\") {\n                    newGroup.moveToEnd(mySelection[i].parent);\n                    tempItem = mySelection[0].duplicate( mySelection[i], ElementPlacement.PLACEBEFORE);\n                    tempItem.moveToEnd(newGroup);\n                } else {\n                    newGroup.move(mySelection[i], ElementPlacement.PLACEBEFORE);\n                    mySelection[0].duplicate(newGroup, ElementPlacement.PLACEATEND);\n                }\n                markStroked(newGroup);\n\n                \/\/ Check to see if the replacing object should be scaled down\/up to fit the dimensions of the being-replaced object\n                if ( scaledObject == true) {\n                    eval('newGroup.position = [alterObjectArray['+i+'][\"xpos\"], alterObjectArray['+i+'][\"ypos\"]]');\n                    \/\/eval('newGroup.position = [alterObjectArray['+i+'][\"offsetXpos\"], alterObjectArray['+i+'][\"offsetYpos\"]]');\n                    newGroupWidth = newGroup.width;\n                    newGroupHeight = newGroup.height;\n\n                    tempObjCenterX = newGroup.position[0] + newGroup.width \/ 2;\n                    tempObjCenterY = newGroup.position[1] - newGroup.height \/2;\n\n                    replacingWidth  = eval('newGroup.width  = alterObjectArray[' + i +'][\"width\"]');\n                    replacingHeight = eval('newGroup.height = alterObjectArray['+ i +'][\"height\"]');\n\n                    switch( scaleMethod) {\n                        case \"proportionalX\":\n                            if( newGroupWidth &gt;= newGroupHeight ) {\n                                eval('newGroup.height = alterObjectArray['+ i +'][\"width\"]');\n                                eval('newGroup.width   = alterObjectArray['+ i +'][\"width\"]');\n                                \/\/ now offset X as needed\n                                if( newGroup.height &gt;= mySelection[0].height ) {\n                                    newGroup.top = newGroup.top + replacingHeight \/ 2;\n                                } else {\n                                    newGroup.top = newGroup.top - replacingHeight \/ 2;\n                                }\n                            } else {\n                                eval('newGroup.height = alterObjectArray['+ i +'][\"height\"]');\n                                eval('newGroup.width   = alterObjectArray['+ i +'][\"height\"]');\n                                \/\/ now offset X as needed\n                                newGroup.left = newGroup.left  + replacingWidth \/ 2;\n                            }\n                            break;\n                        case \"proportionalY\":\n                            if( newGroupWidth &gt;= newGroupHeight ) {\n                                eval('newGroup.height = alterObjectArray['+ i +'][\"height\"]');\n                                eval('newGroup.width   = alterObjectArray['+ i +'][\"height\"]');\n                                \/\/ now offset X as needed\n                                if( newGroup.width &gt;= mySelection[0].width ) {\n                                    newGroup.left = newGroup.left  - replacingWidth \/ 2;\n                                } else {\n                                    newGroup.left = newGroup.left + replacingWidth \/ 2;\n                                }\n                            } else {\n                                eval('newGroup.height = alterObjectArray['+ i +'][\"width\"]');\n                                eval('newGroup.width   = alterObjectArray['+ i +'][\"width\"]');\n                                \/\/ now offset X as needed\n                                newGroup.top = newGroup.top  + replacingHeight \/ 2;\n                            }\n                            break;\n                        case \"proportionalXY\":\n                            xy_Average = ( eval('alterObjectArray['+ i +'][\"height\"]') + eval('alterObjectArray[' + i +'][\"width\"]') ) \/2;\n                            newGroup.height = xy_Average;\n                            newGroup.width = xy_Average;\n                            if( newGroup.width &gt;= mySelection[0].width ) {\n                                newGroup.left = (newGroup.left  + newGroup.width  \/ 2 - replacingWidth \/ 2);\n                            } else {\n                                newGroup.left = (newGroup.left  + newGroup.height \/ 2 - replacingHeight \/ 2);\n                            }\n                            if( newGroup.height &gt;= mySelection[0].height ) {\n                                newGroup.top = (newGroup.top + newGroup.height \/ 2 - replacingHeight \/ 2);\n                            } else  {\n                                newGroup.top = (newGroup.top + newGroup.height \/ 2 + replacingHeight \/ 2);\n                            }\n                            break;\n                        case \"scaleToFit\":\n                        default:\n                            eval('newGroup.height = alterObjectArray['+ i +'][\"height\"]');\n                            eval('newGroup.width = alterObjectArray[' + i +'][\"width\"]');\n                            break;\n                    }\n                    tempGroupWidth  = newGroup.width;\n                    tempGroupHeight = newGroup.height;\n\n\n                    \/\/ now offset Y as needed\n                    \/\/newGroup.top = newGroup.top + newGroupHeight \/ 2 - tempGroupHeight \/ 2;\n                } else {\n                    \/\/ Check to see if the replacing object should be registered to the upper left corer of\n                    \/\/ the being-replaced objects or if it should be centered on the being-replaced object\n                    if( scalingCentered == true ) {\n                        eval('newGroup.position = [alterObjectArray['+i+'][\"offsetXpos\"], alterObjectArray['+i+'][\"offsetYpos\"]]');\n                    } else {\n                        eval('newGroup.position = [alterObjectArray['+i+'][\"xpos\"], alterObjectArray['+i+'][\"ypos\"]]');\n                    }\n                }\n\n                mySelection[i].remove();\n                \/\/restroke with new proportions\n                scaleStroke(strokeArray, propDiff);\n\n                howManyGroupItems = newGroup.pageItems.length - 1;\n\n                if( groupFindAndReplaceResults ) {\n                    \/\/ they are already grouped\n                    if( keepReplacedSelected ) {\n                        theMovedObject.selected = true;\n                    } else {\n                        theMovedObject.selected = false;\n                    }\n                } else {\n                    \/\/ but was the original a group?\n                    if( mySelection[0].typename == \"GroupItem\" ) {\n                        \/\/ do nothing\n                        if( keepReplacedSelected ) {\n                            newGroup.selected = true;\n                        } else {\n                            newGroup.selected = false;\n                        }\n                    } else {\n                        for( g=0; g&lt;=howManyGroupItems; g++ ) {\n                            theMovedObject = newGroup.pageItems[g].duplicate( newGroup, ElementPlacement.PLACEBEFORE );\n                            if( keepReplacedSelected ) {\n                                theMovedObject.selected = true;\n                            } else {\n                                theMovedObject.selected = false;\n                            }\n                        }\n                        \/\/ now that the group is empty of items, delete the group\n                        newGroup.remove();\n                    }\n                }\n            }\n            \/\/ Do we want to have the \"replacing\" object SELECTED after the result is processed and displayed (and may be selected)?\n            if( keepReplaceWithObjSelected ) {\n                sourceObj.selected = true;\n            } else {\n                sourceObj.selected = false;\n            }\n            \/\/ Do we want to have the \"replacing\" object DELETED after the result is processed and displayed (and may be selected)?\n            if( deleteReplaceWithObj ) {\n                sourceObj.remove();\n            }\n        } else {\n            alert(selObjs);\n        }\n    } else {\n        alert(selObjs);\n    }\n}\n\/\/Create the stroke Object that goes into the stroke Array.\n\/\/   contains the items colorObject, and it's initial stroke weight.\nfunction strokeObj(pName, strokeWt) {\n    this.pName = pName;\n    this.strokeWt = strokeWt;\n}\nfunction markStroked(Sel) {\n    var slen = Sel.length;\n    \/\/ if selected is a single object...\n    if (Sel.typename == \"GroupItem\") {\n        markStroked(Sel.pageItems);\n    } else if (Sel.typename == \"CompoundPathItem\") {\n        \/\/add object and stroke weight to the array...\n        myColor = Sel.pathItems[0];\n        myWt = myColor.strokeWidth;\n        bob = new strokeObj(myColor, myWt);\n        strokeArray.push(bob);\n    } else if (Sel.typename == \"TextFrame\") {\n        if (Sel.textRange.characterAttributes.strokeColor.typename != \"NoColor\") {\n            var clMax = Sel.textRange.characters.length;\n            for (var cl=0; cl&lt;clMax; cl++) {\n                myColor = Sel.textRange.characters[0].characterAttributes;\n                myWt = myColor.strokeWeight;\n                bob = new strokeObj(myColor, myWt);\n                strokeArray.push(bob);\n            }\n        }\n    }\n    \/\/ if selected contains more than one object...\n    for (var a=0; a&lt;slen; a++) {\n        if (Sel[a].typename == \"GroupItem\") {\n            \/\/alert(\"a group in markStroke\");\n            markStroked(Sel[a].pageItems);\n        } else if (Sel[a].typename == \"CompoundPathItem\") {\n            myColor = Sel[a].pathItems[0];\n            myWt = myColor.strokeWidth;\n            bob = new strokeObj(myColor, myWt);\n            strokeArray.push(bob);\n        } else if (Sel[a].typename == \"PathItem\") {\n            if (Sel[a].stroked == true) {\n                myColor = Sel[a];\n                myWt = myColor.strokeWidth;\n                bob = new strokeObj(myColor, myWt);\n                strokeArray.push(bob);\n            }\n        } else if (Sel[a].typename == \"TextFrame\") {\n            if (Sel[a].textRange.characterAttributes.strokeColor.typename != \"NoColor\") {\n                var clMax = Sel[a].textRange.characters.length;\n                for (var cl=0; cl&lt;clMax; cl++) {\n                    myColor = Sel[a].textRange.characters[cl].characterAttributes;\n                    myWt = myColor.strokeWeight;\n                    bob = new strokeObj(myColor, myWt);\n                    strokeArray.push(bob);\n                }\n            }\n        }\n    }\n}\nfunction scaleStroke(mySlx, strokeScale) {\n    var slen = mySlx.length;\n    for (var a=0; a&lt;slen; a++) {\n        \/\/set it's strokeweight or strokewidth, whatever... :)\n        mySlx[a].pName.strokeWidth = mySlx[a].strokeWt*strokeScale;\n        mySlx[a].pName.strokeWeight = mySlx[a].strokeWt*strokeScale;\n    }\n}\n<\/code><\/pre>\n<h2>\u529f\u80fd\u6f14\u793a<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2022\/03\/2827957994.gif\" alt=\"GIF.gif\" title=\"GIF.gif\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f88\u65e9\u662f\u4ecegithub\u641c\u7d22\u5230\uff0c\u7528\u6765\u6279\u91cf\u66ff\u6362logo\u65f6\u6bd4\u8f83\u597d\u7528\uff0c\u6700\u8fd1\u5728\u62fc\u7248\u5de5\u4f5c\u4e2d\u6bd4\u8f83\u597d\u7528\uff0c\u6240\u4ee5\u590d\u5236\u4e00\u4efd\u6539 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,12],"tags":[51],"class_list":["post-997","post","type-post","status-publish","format-standard","hentry","category-soft","category-learn","tag-adobe"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/997","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=997"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/997\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}