{"id":1449,"date":"2023-08-23T13:33:25","date_gmt":"2023-08-23T05:33:25","guid":{"rendered":"https:\/\/lyvba.com\/?p=1449"},"modified":"2023-08-24T08:33:53","modified_gmt":"2023-08-24T00:33:53","slug":"adobe-illustrator-makesize","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2023\/08\/23\/adobe-illustrator-makesize\/","title":{"rendered":"Adobe Illustrator \u63d2\u4ef6 \u6279\u91cf\u6807\u6ce8\u5c3a\u5bf8"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/08\/AI_Size.webp\" alt=\"\" \/><\/p>\n<h2><a href=\"https:\/\/www.bilibili.com\/video\/BV1Zz4y1u7Ku\">Adobe Illustrator \u63d2\u4ef6 \u7269\u4ef6\u6279\u91cf\u6807\u6ce8\u5c3a\u5bf8<\/a> <a href=\"https:\/\/www.bilibili.com\/video\/BV1Zz4y1u7Ku\">\u4f7f\u7528\u89c6\u9891<\/a><\/h2>\n<p>\u5f53\u4f60\u60f3\u8981\u5728 Adobe Illustrator \u4e2d\u83b7\u53d6\u4e00\u4e2a\u7269\u4ef6\u7684\u5c3a\u5bf8\uff0c\u5e76\u663e\u793a\u51fa\u6765\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684 JSX \u811a\u672c\u793a\u4f8b\uff1a<\/p>\n<pre><code>var mySelection = activeDocument.selection;\nvar s = mySelection[0]\nvar bounds = s.geometricBounds;\nvar width = bounds[2] - bounds[0];\nvar height = bounds[1] - bounds[3];\nalert(&quot;\u5c3a\u5bf8:&quot; + width + &quot;x&quot; + height + &quot;mm&quot;);<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/08\/size1.png\" alt=\"\" \/><\/p>\n<h3>illustrator \u9ed8\u8ba4\u5185\u7f6e\u5355\u4f4d\u662f pt\uff0c\u6240\u4ee5\u8981\u505a\u5355\u4f4d\u8f6c\u6362\uff0c\u8fd8\u53ef\u4ee5\u6dfb\u52a0\u6570\u5b57\u53d6\u6574<\/h3>\n<ul>\n<li>\u5b9a\u4e49 <code>mm<\/code> \u53d8\u91cf\u7528\u6765\u8f6c\u6362\uff0c\u5b9a\u4e49 <code>formatSize<\/code>\u51fd\u6570\u5b8c\u6210 <code>pt-&gt;mm<\/code> \u540c\u65f6\u53d6\u6574<\/li>\n<\/ul>\n<pre><code>var mm = 25.4 \/ 72;  \/\/ pt \u548c mm \u8f6c\u6362\u7cfb\u6570\n\n\/\/ \u683c\u5f0f\u5316\u5c3a\u5bf8\u4e3a mm \u53d6\u6574\u6570\nfunction formatSize(size) {\n  return Math.round(size * mm).toFixed(0);\n}<\/code><\/pre>\n<h2>\u5b8c\u6210\u529f\u80fd\u7b2c\u4e00\u4e2a\u7248\u672c\uff0c\u80fd\u6279\u91cf\u6807\u6ce8\u4ee3\u7801 <code>001_\u6807\u6ce8\u5c3a\u5bf8.jsx<\/code><\/h2>\n<pre><code>\/\/ \u5b9a\u4e49\u5f53\u524d\u6fc0\u6d3b\u6587\u6863\nvar docRef = activeDocument;\nvar mm = 25.4 \/ 72;  \/\/ pt \u548c mm \u8f6c\u6362\u7cfb\u6570\nvar myFont = textFonts.getByName(&quot;MicrosoftYaHei&quot;);\nvar myFontSize = 24;\n\n\/\/ \u683c\u5f0f\u5316\u5c3a\u5bf8\u4e3a mm \u53d6\u6574\u6570\nfunction formatSize(size) {\n  return Math.round(size * mm).toFixed(0);\n}\nfunction writeText(text) {\n  var textRef = docRef.textFrames.add();    \/\/ \u5efa\u7acb\u6587\u672c\n  textRef.contents = text;\n  textRef.textRange.characterAttributes.size = myFontSize;   \/\/ \u8bbe\u7f6e\u5b57\u4f53\u5c3a\u5bf8\n  textRef.textRange.characterAttributes.textFont = myFont;   \/\/ \u8bbe\u7f6e\u5b57\u4f53\u540d\u79f0\n  textRef.textRange.characterAttributes.fillColor = docRef.swatches[4].color;   \/\/ \u8bbe\u7f6e\u989c\u8272\n  textRef.top = y + 15 \/ mm;\n  textRef.left = x + 10 \/ mm;\n}\n\n\/\/ \u904d\u5386\u9009\u62e9\u7684\u7269\u4ef6\u6807\u6ce8\u5c3a\u5bf8\nif (docRef.selection.length &gt; 0) {\n  \/\/ \u5b9a\u4e49\u9009\u62e9\u7269\u4ef6\n  var mySelection = docRef.selection;\n\n  for (var i = 0; i &lt; mySelection.length; i++) {\n    var s = mySelection[i]\n\n    \/\/ \u7269\u4ef6\u7684\u5de6\u4e0a\u70b9\u5750\u6807\n    var xy = s.position\n\n    \/\/ shape \u7684 \u53ef\u89c1\u8fb9\u754c\n    \/\/ var bounds = s.visibleBounds;\n    \/\/ shape \u7684 \u8def\u5f84\u8303\u56f4 Path Item Bounds\n    var bounds = s.geometricBounds;\n\n    \/\/ shape \u7269\u4ef6\u7684\u53ef\u89c1\u8fb9\u754c\u5de6\u4e0a\u70b9\u5750\u6807\uff0c\u4f1a\u548c s.position \u4e0d\u540c\n    var x = bounds[0];\n    var y = bounds[1];\n\n    \/\/ shape \u7269\u4ef6\u7684\u5927\u5c0f\n    var width = bounds[2] - bounds[0];\n    var height = bounds[1] - bounds[3];\n    \/\/ alert(&quot;\u5c3a\u5bf8:&quot; + width * mm + &quot;x&quot; + height * mm + &quot;mm&quot;);\n\n    var str = formatSize(width) + &quot;x&quot; + formatSize(height) + &quot;mm&quot;;\n    writeText(str)\n  }\n}<\/code><\/pre>\n<h3>\u67e5\u770b\u4e86\u4e00\u4e0bAI\u7269\u4ef6\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53d1\u73b0\u53ef\u4ee5\u76f4\u63a5\u53d6\u7269\u4ef6 <code>left top width height<\/code>\uff0c\u4ece\u989c\u8272\u7248\u53d6\u8272\u7b80\u5355\uff0c\u4f46\u662f\u7ed3\u679c\u4e0d\u786e\u5b9a<\/h3>\n<ul>\n<li>\u989c\u8272\u8bbe\u7f6e\u4ee3\u7801\u6539\u6210\u8fd9\u6837\n<pre><code>\/\/ \u8bbe\u7f6e\u586b\u5145\u989c\u8272\u4e3aCMYK\u7ea2\u8272 (0, 100, 100, 0)\nvar cmykRed = new CMYKColor();\ncmykRed.cyan = 0;\ncmykRed.magenta = 100;\ncmykRed.yellow = 100;\ncmykRed.black = 0;\ntextRef.textRange.characterAttributes.fillColor = cmykRed  \/\/ docRef.swatches[4].color;  \/\/ \u4ece\u989c\u8272\u7248\u53d6\u8272\u7b80\u5355\uff0c\u4f46\u662f\u7ed3\u679c\u4e0d\u786e\u5b9a<\/code><\/pre>\n<\/li>\n<\/ul>\n<h3>\u66f4\u65b0\u540e\u7684\u5b9e\u9645\u4f7f\u7528\u7248\u672c <code>\u6807\u6ce8\u5c3a\u5bf8.jsx<\/code><\/h3>\n<pre><code>\/\/ \u5b9a\u4e49\u5f53\u524d\u6fc0\u6d3b\u6587\u6863\nvar docRef = activeDocument;\nvar mm = 25.4 \/ 72;  \/\/ pt \u548c mm \u8f6c\u6362\u7cfb\u6570\nvar myFont = textFonts.getByName(&quot;MicrosoftYaHei&quot;);\nvar myFontSize = 24;\nvar x , y;\n\n\/\/ \u683c\u5f0f\u5316\u5c3a\u5bf8\u4e3a mm \u53d6\u6574\u6570\nfunction formatSize(size) {\n  return Math.round(size * mm).toFixed(0);\n}\n\n\/\/ \u8bbe\u7f6e\u586b\u5145\u989c\u8272\u4e3aCMYK\u7ea2\u8272 (0, 100, 100, 0)\nvar cmykRed = new CMYKColor();\ncmykRed.cyan = 0;\ncmykRed.magenta = 100;\ncmykRed.yellow = 100;\ncmykRed.black = 0;\n\nfunction writeText(text) {\n  var textRef = docRef.textFrames.add();    \/\/ \u5efa\u7acb\u6587\u672c\n  textRef.contents = text;\n  textRef.textRange.characterAttributes.size = myFontSize;   \/\/ \u8bbe\u7f6e\u5b57\u4f53\u5c3a\u5bf8\n  textRef.textRange.characterAttributes.textFont = myFont;   \/\/ \u8bbe\u7f6e\u5b57\u4f53\u540d\u79f0\n  textRef.textRange.characterAttributes.fillColor = cmykRed;   \/\/ \u8bbe\u7f6e\u989c\u8272\n  textRef.top = y + 15 \/ mm;\n  textRef.left = x + 10 \/ mm;\n}\n\n\/\/ \u904d\u5386\u9009\u62e9\u7684\u7269\u4ef6\u6807\u6ce8\u5c3a\u5bf8\nif (docRef.selection.length &gt; 0) {\n  var mySelection = docRef.selection;\n  for (var i = 0; i &lt; mySelection.length; i++) {\n    var s = mySelection[i]\n    x = s.left; y = s.top\n    var str = formatSize(s.width) + &quot;x&quot; + formatSize(s.height) + &quot;mm&quot;;\n    writeText(str)\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Adobe Illustrator \u63d2\u4ef6 \u7269\u4ef6\u6279\u91cf\u6807\u6ce8\u5c3a\u5bf8 \u4f7f\u7528\u89c6\u9891 \u5f53\u4f60\u60f3\u8981\u5728 Adobe Ill [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1450,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,12],"tags":[51,68],"class_list":["post-1449","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-soft","category-learn","tag-adobe","tag-jsx"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1449","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=1449"}],"version-history":[{"count":6,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1449\/revisions"}],"predecessor-version":[{"id":1457,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1449\/revisions\/1457"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media\/1450"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=1449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=1449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=1449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}