• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Shifting a path starting point

Community Beginner ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

Hi,

I'm trying to automate moving a path's starting anchor point by a predeterminate step.

However, apparently I can't reference an array in the .setEntirePath() method.

Is this true ou did I blunder?

Thanks in advance.

var MSG_noobjects = "Please select some objects.";
var MSG_nodocs = "You have no open document."

var error=0;

if (documents.length<1) {

   error++;
   alert(MSG_nodocs);
}

if (error == 0) {

   var theObjects=selection;

   if (theObjects.length<1 && error == 0) {

  error++;
   alert(MSG_noobjects);
   }

}

if (error < 1) {

   changePathStarts(theObjects);
}

function changePathStarts(theItems) {

   for (var i = 0; i < theItems.length; i++) {


   if (theItems.typename == "PathItem" && !theItems.locked && !theItems.parent.locked && !theItems.layer.locked) {

   pathLen = theItems.pathPoints.length;

   var pointsarr = new Array();

   for (k = 0; k < pathLen; k++) {//fill array with path's points

       pointsarr.push(theItems.pathPoints[k]);
   }

  pointsarr.push(pointsarr.shift()); //array rotate/shift register right

  var newpath = app.activeDocument.pathItems.add();

           

  newpath.setEntirePath(Arraypointsarr);


  app.redraw();
   }

  }

}

TOPICS
Scripting

Views

484

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jan 19, 2018 Jan 19, 2018

I was trying to change a path starting point to another in the same path.

Something like this:
ttt.png
Finally I did it:

/**
* Created by Kaiserin on 19/01/2018.
*/
var MSG_noobjects = "Please select some objects.";
var MSG_nodocs = "You have no open document."

var error=0;

if (documents.length<1) {

  error++;
   alert(MSG_nodocs);
}

if (error == 0) {

   var theObjects=selection;
   if (theObjects.length<1 && error == 0) {

  error++;
   alert(MSG_noobjects);
   }

}

if (error < 1) {

   changePathStarts(theObjects);
}

functio

...

Votes

Translate

Translate
Adobe
Community Beginner ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

not sure what you are trying to do but I did notice this.

ln44:  newpath.setEntirePath(Arraypointsarr);

"Arraypointsarr" is undefined....should just be "pointsarr"

Also  line 36 should probably be...pointsarr.push(theItems.pathPoints.anchor);

the dot anchor is where you get the actual position of the point.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2018 Jan 19, 2018

Copy link to clipboard

Copied

LATEST

I was trying to change a path starting point to another in the same path.

Something like this:
ttt.png
Finally I did it:

/**
* Created by Kaiserin on 19/01/2018.
*/
var MSG_noobjects = "Please select some objects.";
var MSG_nodocs = "You have no open document."

var error=0;

if (documents.length<1) {

  error++;
   alert(MSG_nodocs);
}

if (error == 0) {

   var theObjects=selection;
   if (theObjects.length<1 && error == 0) {

  error++;
   alert(MSG_noobjects);
   }

}

if (error < 1) {

   changePathStarts(theObjects);
}

function changePathStarts(theItems) {

   for (var i = 0; i < theItems.length; i++) {

   if (theItems.typename == "GroupItem") {//ungroups before processing

   for (var ix = 0; ix < theItems.length; ix++) {

   var item = theItems[ix];
   var itemType = item.constructor.name;
   if (itemType != "Group") {

   continue;
   }

  item.ungroup();
   }

   changePathStarts(theItems.pathItems);
   }

   if (theItems.typename == "PathItem" && !theItems.locked && !theItems.parent.locked && !theItems.layer.locked) {

   pathLen = theItems.pathPoints.length;

   var pointsarr = new Array();

   for (k = 0; k < pathLen; k++) {//fill array with path's points
   pointsarr.push(theItems.pathPoints);
   }

  pointsarr.push(pointsarr.shift()); //array rotate/shift register right

   var newpath = app.activeDocument.pathItems.add()

   for (k = 0; k < pointsarr.length; k++) {

   var newPoint = newpath.pathPoints.add();
   newPoint.anchor = pointsarr.anchor;
   newPoint.leftDirection = pointsarr.leftDirection;
   newPoint.rightDirection = pointsarr.rightDirection;
   newPoint.pointType = pointsarr.pointType;
   }

  newpath.closed = true;

   }

  }

}

for (var k = 0; k < theObjects.length; k++) {

  theObjects.remove();
}

app.redraw();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines