Copy link to clipboard
Copied
I have a script which creates rectangles, rounded rectangles, ellipses and polygons using pathItems. However, when I open the transform menu it says 'no shape properties'. Can I not, for example, change the number of sides of a polygon via the transform menu if I create a polygon in this manner?
The answer is yes, script do the jobs in old style, the objects script created are PathItems, not Shapes.
A solution can be record an action and call it in script. Here is a example:
...String.prototype.formatUnicorn = function () {
"use strict";
var str = this.toString();
if (arguments.length) {
var t = typeof arguments[0];
var key;
var args = ("string" === t || "number" === t) ?
Array.prototype.slice.call(arguments)
: arguments[0];
for (key
Copy link to clipboard
Copied
The answer is yes, script do the jobs in old style, the objects script created are PathItems, not Shapes.
A solution can be record an action and call it in script. Here is a example:
String.prototype.formatUnicorn = function () {
"use strict";
var str = this.toString();
if (arguments.length) {
var t = typeof arguments[0];
var key;
var args = ("string" === t || "number" === t) ?
Array.prototype.slice.call(arguments)
: arguments[0];
for (key in args) {
str = str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]);
}
}
return str;
};
function drawArc(p) {
var w = h = addZero(2 * p.r),
x = addZero(p.x),
y = addZero(p.y),
s = addZero(p.s),
e = addZero(p.e);
var actionStr = [
'/version 3',
'/name [ 3',
' 736574',
']',
'/actionCount 1',
'/action-1 {',
' /name [ 6',
' 616374696f6e',
' ]',
' /eventCount 3',
' /event-1 {',
' /internalName (ai_plugin_ovalTool)',
' /hasDialog 1',
' /showDialog 0',
' /parameterCount 7',
' /parameter-1 {',
' /key 1953460076',
' /type (integer)',
' /value 14',
' }',
' /parameter-2 {',
' /key 2003072104',
' /type (unit real)',
' /value {w}',
' /unit 592476268',
' }',
' /parameter-3 {',
' /key 1751607412',
' /type (unit real)',
' /value {h}',
' /unit 592476268',
' }',
' /parameter-4 {',
' /key 1668182644',
' /type (boolean)',
' /value 0',
' }',
' /parameter-5 {',
' /key 1668183128',
' /type (unit real)',
' /value {x}',
' /unit 592476268',
' }',
' /parameter-6 {',
' /key 1668183129',
' /type (unit real)',
' /value {y}',
' /unit 592476268',
' }',
' /parameter-7 {',
' /key 1667854947',
' /type (boolean)',
' /value 0',
' }',
' }',
' /event-2 {',
' /internalName (ai_liveshape_ellipse)',
' /parameterCount 3',
' /parameter-1 {',
' /key 1936220528',
' /type (enumerated)',
' /name [ 0',
' ]',
' /value 9',
' }',
' /parameter-2 {',
' /key 1954115685',
' /type (enumerated)',
' /name [ 0',
' ]',
' /value 10',
' }',
' /parameter-3 {',
' /key 1885950836',
' /type (unit real)',
' /value {s}',
' /unit 591490663',
' }',
' }',
' /event-3 {',
' /internalName (ai_liveshape_ellipse)',
' /parameterCount 3',
' /parameter-1 {',
' /key 1936220528',
' /type (enumerated)',
' /name [ 0',
' ]',
' /value 9',
' }',
' /parameter-2 {',
' /key 1954115685',
' /type (enumerated)',
' /name [ 0',
' ]',
' /value 11',
' }',
' /parameter-3 {',
' /key 1885947246',
' /type (unit real)',
' /value {e}',
' /unit 591490663',
' }',
' }',
'}'
].join('\n')
.formatUnicorn({w:w, h:h, x:x, y:y, s:s, e:e});
createAction(actionStr, 'set');
app.doScript('action', 'set');
app.unloadAction('set', '');
}
function addZero(n) {
return (n + '.0').replace(/(\.\d*)(\.?0?)$/, '$1')
}
function createAction(str, set) {
var f = File(set + '.aia');
f.open('w');
f.write(str);
f.close();
app.loadAction(f);
f.remove();
}
drawArc({
x:100,
y:100,
r:50,
s:60,
e:120
})
Copy link to clipboard
Copied
Great! Worked like a charm! I recorded all shape actions, exported the code and used yours as a template to recreate all! Much appreciated.