0 Replies Latest reply on Nov 10, 2017 3:18 PM by badweasel

    Script now beachballs under AI CC 2018 (worked in 2017)


      As usually happens.  While I'm writing my "please help" post I end up figuring out the problem on my own.  Still, I will put my findings here to hopefully help someone else.


      A few months ago I hacked together a script to randomly distort path points.  It's not a perfect script but it worked fine for my use and saved me a ton of time.


      Now after upgrading to 2018 it just beachballs the mac and gets stuck in an endless loop.  When I detect a compound path I do this:


      newItem = newCompoundPath.pathItems.add();

      dupeAndWarp(comp[c], newItem, hVar, vVar);


      comp[c] is an pathitem of the compound path, which becomes "source" inside the dupeAndWarp method. Then inside dupeAndWarp, I transfer properties of the source item to the newpath (created by the caller), and then fill it with points using this loop:


      function dupeAndWarp(source, newpath, hVar, vVar) {


      for (i=0; i<source.pathPoints.length; i++) {

             var newPoint = idoc.pathItems[0].pathPoints.add();

             var anchor = source.pathPoints[i].anchor;

             var left = source.pathPoints[i].leftDirection;

             var right = source.pathPoints[i].rightDirection;


             var moveX = (Math.random() * hVar * 2) - hVar;

             var moveY = (Math.random() * vVar * 2) - vVar;


             newPoint.anchor = Array(anchor[0] + moveX, anchor[1] + moveY);

             newPoint.leftDirection = Array(left[0] + moveX, left[1] + moveY);

             newPoint.rightDirection = Array(right[0] + moveX, right[1] + moveY);

             newPoint.pointType = source.pathPoints[i].pointType;



      Which is where it's getting stuck. In CC 2017 this worked fine.  What I discovered is that in 2018 the source.pathPoints.lenth is growing by one each time I do:


      var newPoint = idoc.pathItems[0].pathPoints.add();


      In the past this created a new point to the newCompoundPath that I added.  But I suppose using pathItem[0] is sloppy and assumes that the item in [0] is the newest one that was added.  The reason I did this was that the demo I found did it.  I replaced that with "newpath and it works fine now.


      Conclusion.. in 2018 we can no longer assume what pathItem[0] is going to be.