-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathSelectOnlyPoints.jsx
114 lines (95 loc) · 3.3 KB
/
SelectOnlyPoints.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
SelectOnlyPoints.jsx for Adobe Illustrator
Description: After using the Lasso tool or Direct Selection Tool, both Points and Path segments are selected.
The script leaves only Points selected
Date: September, 2018
Author: Sergey Osokin, email: [email protected]
Installation: https://github.com/creold/illustrator-scripts#how-to-run-scripts
Release notes:
0.1 Initial version
0.2 Fixed when selected unnecessary anchor handles (thanks for Oleg Krasnov, www.github.com/krasnovpro)
0.3 Minor bug fixes and improvements
0.3.2 Minor bug fixes
Donate (optional):
If you find this script helpful, you can buy me a coffee
- via Buymeacoffee: https://www.buymeacoffee.com/aiscripts
- via Donatty https://donatty.com/sergosokin
- via DonatePay https://new.donatepay.ru/en/@osokin
- via YooMoney https://yoomoney.ru/to/410011149615582
NOTICE:
Tested with Adobe Illustrator CC 2019-2025 (Mac/Win).
This script is provided "as is" without warranty of any kind.
Free to use, not for sale
Released under the MIT license
http://opensource.org/licenses/mit-license.php
Check my other scripts: https://github.com/creold
*/
//@target illustrator
app.preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file
$.localize = true; // Enabling automatic localization
// Main function
function main() {
var LANG = {
errDoc: { en: 'Error\nOpen a document and try again',
ru: 'Ошибка\nОткройте документ и запустите скрипт' },
errSel: { en: 'Error\nUse Lasso tool or Direct Selection Tool to select an area with points',
ru: 'Ошибка\nИспользуйте инструмент "Лассо или "Прямое выделения" для выбора области с точками' }
};
if (!documents.length) {
alert(LANG.errDoc);
return;
}
var selPaths = [],
selPoints = [];
getPaths(selection, selPaths);
if (!(selPaths instanceof Array) || selPaths.length < 1) {
alert(LANG.errSel);
return;
}
getPoints(selPaths, selPoints);
selection = null;
for (var i = 0, pLen = selPoints.length; i < pLen; i++) {
selPoints[i].selected = PathPointSelection.ANCHORPOINT;
}
}
// Get single items from selection
function getPaths(items, arr) {
for (var i = 0, iLen = items.length; i < iLen; i++) {
var currItem = items[i];
try {
switch (currItem.typename) {
case 'GroupItem':
getPaths(currItem.pageItems, arr);
break;
case 'PathItem':
arr.push(currItem);
break;
case 'CompoundPathItem':
getPaths(currItem.pathItems, arr);
break;
default:
currItem.selected = false;
break;
}
} catch (e) {}
}
}
// Get selected points on paths
function getPoints(items, arr) {
for (var i = 0, iLen = items.length; i < iLen; i++) {
if (items[i].pathPoints.length > 1) {
var points = items[i].pathPoints;
for (var j = 0, pLen = points.length; j < pLen; j++) {
if ( isSelected(points[j]) ) arr.push(points[j]);
}
}
}
}
// Check current point is selected
function isSelected(point) {
return point.selected == PathPointSelection.ANCHORPOINT;
}
// Run script
try {
main();
} catch (e) {}