Copy link to clipboard
Copied
Hello All,
I wanted to trim/divide the object by using the top right and bottom left corners as shown in the below screenshot. I have done this by manually using Scissors tool.
How to do a script for this conversion?
Thanks.
Unfortunatly you script cannot work.
Here is a working variant with remove the pathPoint[3] of the created rectangle
// Set color values for the CMYK object
var cmykCol = new CMYKColor();
cmykCol.black = 100.0;
cmykCol.cyan = 0.0;
cmykCol.magenta = 0.0;
cmykCol.yellow = 0;
var myDocument = app.activeDocument;
var artLayer = myDocument.layers.add()
var rect1 = artLayer.pathItems.rectangle( -449.855743408203,815.611206054688, 14.173, 8.504 );
rect1.fillColor = cmykCol;
rect1.p
...
Copy link to clipboard
Copied
Can you be more specific? Are they always squares (not rectangles with different width/height), will they ever be rotated, are you using the Rectangle tool every time, are you running this on every square in the document or just the selection, etc?
Copy link to clipboard
Copied
Actually, this is a rectangle but I draw it like a square shape.
I need to delete the bottom right Anchor point for the selected rectangle object.
How can we remove the anchor point through script?
Copy link to clipboard
Copied
It depends. Will it ever be rotated? Are you running this on just the selection or every square?
Copy link to clipboard
Copied
My steps in script like below.
This is my script:
var artLayer = myDocument.layers.add()
var rect1 = artLayer.pathItems.rectangle( 449.855743408203,815.611206054688, 14.173, 8.504 );
// Set color values for the CMYK object
var cmykCol = new CMYKColor();
cmykCol.black = 100.0;
cmykCol.cyan = 0.0;
cmykCol.magenta = 0.0;
cmykCol.yellow = 0;
The above code, it is applying the black color for the object. Here I need to remove the bottom right anchorpoint.
Copy link to clipboard
Copied
Lol. I guess that kind of answers my questions, but without you explicitly saying it I have to guess here. I'm asking because if the shape is not rotated, you can assume the bottom right will always be the same pathPoint in the pathItem.pathPoints array. You can directly call pathPoint.remove() to remove that anchor point:
var rect1 = artLayer.pathItems.rectangle(449.855743408203, 815.611206054688, 14.173, 8.504);
rect1.pathPoints[3].remove();
If it might be rotated this will not work, you'd have to compare the points to one another in order to determine the orientation to get the one at the bottom right, which is why I've asked you twice.
I don't actually understand why you're using rectangles. This is one of the reasons you should try to explain further or show your script sooner, because it's not clear what you're actually trying to accomplish and this is a prime example of an XY Problem, where you're asking how to accomplish what you think is a solution to a problem instead of asking about that original problem to begin with.
The original problem is that you're trying to make a triangle, right? You're only asking about rectangles because you assume that you'd need to make one and then remove a point to create it as a triangle?
var artLayer = app.activeDocument.layers.add();
// If you know only 3 points are needed, why create the rectangle at all?
var points = [
[815.611206054688, 449.855743408203],
[829.748206054688, 449.855743408203],
[815.611206054688, 441.351743408203]
];
var triangle = artLayer.pathItems.add();
// https://ai-scripting.docsforadobe.dev/jsobjref/PathItem/#pathitem-setentirepath
triangle.setEntirePath(points);
triangle.closed = true;
Copy link to clipboard
Copied
Unfortunatly you script cannot work.
Here is a working variant with remove the pathPoint[3] of the created rectangle
// Set color values for the CMYK object
var cmykCol = new CMYKColor();
cmykCol.black = 100.0;
cmykCol.cyan = 0.0;
cmykCol.magenta = 0.0;
cmykCol.yellow = 0;
var myDocument = app.activeDocument;
var artLayer = myDocument.layers.add()
var rect1 = artLayer.pathItems.rectangle( -449.855743408203,815.611206054688, 14.173, 8.504 );
rect1.fillColor = cmykCol;
rect1.pathPoints[3].remove();
Copy link to clipboard
Copied
Thanks a lot, Now it is working fine.