Skip to main content
visual_Dream5CAA
Known Participant
November 26, 2023
Answered

Help for script anchors point

  • November 26, 2023
  • 2 replies
  • 420 views

please who can help me to make this path created to come with position center of anchors point ?

main();

function main() {
    var doc = app.activeDocument;

    // Create a new group at the beginning of each script run
    var newGroup = doc.groupItems.add();
    newGroup.name = "Artwork Group " + (doc.groupItems.length); // Give a unique name to the group

    // Pass the new group to the handlePaths function
    handlePaths(doc.selection, newGroup);
}

// Modify handlePaths to accept the new group as a parameter
function handlePaths(sel, group) {
    for (var i = 0; i < sel.length; i++) {
        var item = sel[i];
        if (item.typename == "PathItem") {
            artworkOnPoints(item, group);
        } else if (item.typename == "GroupItem") {
            // Recursively handle items within the group
            handlePaths(item.pageItems, group);
        } else if (item.typename == "CompoundPathItem") {
            // Recursively handle items within the compound path
            handlePaths(item.pathItems, group);
        }
        // Continue to check for other types if needed
    }
}

// Modify artworkOnPoints to accept the new group as a parameter
function artworkOnPoints(path, group) {
    var pts = path.pathPoints;
    for (var i = 0; i < pts.length; i++) {
        var pos = pts[i].anchor;
        // Create a rectangle at the specified anchor point
        createRectangleAtPoint(pos, group);
    }
}

// Create a rectangle at the specified position and add it to the group
function createRectangleAtPoint(pos, group) {
    var rect = group.pathItems.rectangle(pos[1] - 5, pos[0] - 5, 10, 10); // Adjust the size and position as needed
    // Customize the rectangle's appearance here (e.g., fill color, stroke)
}
This topic has been closed for replies.
Correct answer CarlosCanto

change the top parameter from - to +

 

from this

var rect = group.pathItems.rectangle(pos[1] - 5, pos[0] - 5, 10, 10); // Adjust the size and position as needed

 

to this

var rect = group.pathItems.rectangle(pos[1] + 5, pos[0] - 5, 10, 10); // Adjust the size and position as needed

2 replies

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
November 26, 2023

change the top parameter from - to +

 

from this

var rect = group.pathItems.rectangle(pos[1] - 5, pos[0] - 5, 10, 10); // Adjust the size and position as needed

 

to this

var rect = group.pathItems.rectangle(pos[1] + 5, pos[0] - 5, 10, 10); // Adjust the size and position as needed

visual_Dream5CAA
Known Participant
November 26, 2023

Wow this is amazing thank you

femkeblanco
Legend
November 26, 2023

What do you want the script to do?