Copy link to clipboard
Copied
When you select a point on a path (with the direct selection tool), app.selection[0] returns [object Polygon]. I was hoping it would return [object PathPoint], but it doesn't. Is it therefore not possible to select a pathPoint in InDesign and get a reference to it with app.selection[0]?
Thanks,
Peter
Thanks very much for putting me on the right track, Uwe and Trevor. The workaround, though ugly, is pretty straightforward. But first,
> By a menu action we could change the pointType of the path points selected
But we don't know which point is selected -- that's the whole point.
> app.undo() doesn't work on this function
app.documents[0].undo() does work
Here's the workaround I got to work thanks to your pointers. To try the script, draw a path with several points, then select a point with the direc
...Copy link to clipboard
Copied
Hi Peter,
I don't think there is a solution in ID
Sorry.
But e.g. in Illustrator you can do something like this:
var aDoc = app.activeDocument;
var thePp0 = aDoc.pathItems[0].pathPoints[0];
thePp0.selected = PathPointSelection.ANCHORPOINT;
$.writeln(thePp0.selected);
$.writeln(aDoc.pathItems[0].selectedPathPoints[0].anchor);
Perhaps this helps a little bit.
Copy link to clipboard
Copied
Thanks, pixxxel. Unfortunately there's no equivalent of that Illustrator code in InDesign.
Peter
Copy link to clipboard
Copied
@Peter – there is a method to check what path points are selected.
However it is an indirect method and involves the app.cut() method.
Store all pathPoints with their index and their anchor arrays.
Then do the app.cut() method.
Now inspect the path with the path points again.
Compare the anchor values with the ones stored.
The missing ones after the cut were initially selected.
Uwe
Copy link to clipboard
Copied
And would there be a way to reselect it after it's been cut (and redrawn)?
Copy link to clipboard
Copied
@Trevor – no. You'll have to do an app.undo() for the cut().
Uwe
Copy link to clipboard
Copied
@Peter and Trevor – there is a flaw in my idea. It could happen that two path points have the same position and only one of it is selected. So you could not tell by the anchor which is which.
But we could think of a different, more complex method to pin point the selected path points.
Also possibly with an app.undo() at the end.
By an menu action we could change the pointType of the path points selected and check before and after for the whole path to single out the changed ones. Possibly we have to do this more than one time, if more than one point type is present in the initial path.
Uwe
Copy link to clipboard
Copied
Uwe
There another problem, app.undo() doesn't work on this function. On Mac it produces an error "Unable to undo last comand" and on widows it just does nothing.
Oh well, back to the drawing board
Trevor
Copy link to clipboard
Copied
Using Undo menu action will do the trick
Copy link to clipboard
Copied
@Trevor – unfortunately you are right that app.undo() will not work in this scenario.
However there could be a (very) slim chance to do an equivalent menu action instead of app.undo() that will work. Did not test that yet…
Possibly we could wrap the app.cut() into a doScript() and try to get the undo with the appropriate menu action.
Uwe
Copy link to clipboard
Copied
@Trevor – cool! You already tested that idea!
Uwe
Copy link to clipboard
Copied
Thanks very much for putting me on the right track, Uwe and Trevor. The workaround, though ugly, is pretty straightforward. But first,
> By a menu action we could change the pointType of the path points selected
But we don't know which point is selected -- that's the whole point.
> app.undo() doesn't work on this function
app.documents[0].undo() does work
Here's the workaround I got to work thanks to your pointers. To try the script, draw a path with several points, then select a point with the direct selection tool (but not the first point; see below). This script moves the selected point up by 10 of whatever your units are:
app.cut();
index = app.selection[0].paths[0].pathPoints.length;
app.documents[0].undo();
movePoint (app.selection[0].paths[0].pathPoints[index])
function movePoint (point) {
var pos = [point.anchor[0], point.anchor[1]-10];
point.anchor = pos
}
The idea is this: if you cut a point you in fact cut the path in two and you end up with two paths. Both are selected: app.selection[0] contains the first part, app.selection[1], the second part. The length of the first part's path gives you the index of the deleted path point. Now undo and you can get a reference to the selected point.
But there's a problem: if you cut the first or the last point you end up with one path, not two. For the last point that's no problem, the above script still works. But if you delete the first point, index in the second line gives you the index of the last point. So we need to establish if we selected the first point. There are probably several ways of doing this; in the following script I take the anchor (a 2-element array with the point's x- and y-positions) of the first point, then cut the selected point, then check the anchor of what is now the first point. If these two anchors are the same, it was the last point that was cut; if the two anchors are not the same, the first anchor was cut.
// Get the coordinates of the first point as a string
first = String(app.selection[0].paths[0].pathPoints[0].anchor);
app.cut();
// If after cutting the point we end up with one selected object we cut either the first or the last point
// and if the first point of the new selection is not the same as the first point of the original selection,
// then we cut the first point.
if (app.selection.length == 1 && String(app.selection[0].paths[0].pathPoints[0].anchor) != first) {
index = 0;
} else {
index = app.selection[0].paths[0].pathPoints.length;
}
app.documents[0].undo();
movePoint (app.selection[0].paths[0].pathPoints[index])
function movePoint (point) {
var pos = [point.anchor[0], point.anchor[1]-10];
point.anchor = pos
}
Peter
Copy link to clipboard
Copied
Nice one Peter,
The natural and useful extension of this would be to work on multiple selection points and the one could apply alignments and distributions to those points.
I had planned some years ago to write a script like that along the lines of Marc's equalizer script but with reference to points as apposed to object, haven't made a start on it and wasn't aware of the difficulty of finding which point was selected until now but shouldn't be too tough to implement.
Trevor
P.s. I think you should mark your answer as correct, you won't get any brownie points for it but it's useful for searches
Copy link to clipboard
Copied
> The natural and useful extension of this would be to work on multiple selection points
That was one thing I was after. It's difficult in the interface to align two points because smart guides don't work well with points. Mousing hardly works, you need to get the coordinates of a point, then select another point and change its coordinates.
Haven't tried getting references to two points yet, that's not so straightforward. But a feature like Fontlab's, which warns you if two points are almost aligned ('vector is almost straight') and aligns them if necessary is not so hard to script.
I working on a tool to manipulate points. The way that InDesign implemented the point-conversion tool is crude, and the way it deals its curves and Bezier handles leaves much room for improvement. But at least it's scriptable.
By the way, whoever thought that leftDirection and rightDirection were better terms than incoming and outgoing wasn't thinking right. Totally misleading and inaccurate.
Peter
Copy link to clipboard
Copied
> P.s. I think you should mark your answer as correct, you won't get any brownie points for it
> but it's useful for searches
How do you do that?
Copy link to clipboard
Copied
After looking into things a bit more it does look like the natural and useful extension would be pretty tough to implement.
Any ideas?
Copy link to clipboard
Copied
Just click on the mark as correct on next to your answer
Copy link to clipboard
Copied
I see 'Was this helpful? Yes No', and a bit further to the right, 'Mark as:'. But there's nothing to choose from. Never mind.
Copy link to clipboard
Copied
You probably need to reset your site preferences on firefox this is easy , option, privacy, clear recent history, then tick site preferences. But as you put it "Never Mind"