Skip to main content
Inspiring
November 16, 2014
Answered

Optimize objects stacking order for vinyl cutting

  • November 16, 2014
  • 1 reply
  • 5167 views

Hello,

i am looking for a script for optimizing vinyl cutting speed.

The script should be similar to following , but needs to sort the selected objects by the relative position to page origin and not the height from page origin as it does now

script from Arranging stacking order from top to bottm

//David Entwistle

 

var thisDoc = activeDocument;

 

// get selected objects

var selObj = thisDoc.selection;

 

// count the selected objects

var selObjCount = selObj.length;

 

// sort selected objects by their height from the page origin

var byProperty = function(prop) {

    return function(a,b) {

        if (typeof a[prop] == "number") {

            return (a[prop] - b[prop]);

        } else {

            return ((a[prop] < b[prop]) ? -1 : ((a[prop] > b[prop]) ? 1 : 0));

        }

    };

};

 

var symbolsSorted = selObj.sort(byProperty("top"));

 

// for each object in turn in the ordered selection, BringToFront

for(i = selObjCount; i >0; i--){

          var currObj = symbolsSorted[i-1];

          currObj.zOrder(ZOrderMethod.BRINGTOFRONT);

}

 

redraw();

alert("Selected Objects Sorted = " + selObjCount);

 

 

Any help is welcome

Panagiotis

This topic has been closed for replies.
Correct answer Qwertyfly___

Ok its late and its not exactly what you want.

There are also probably better ways to achieve this.

It measures the distance from top right of page to top right of pathitems

then sorts them accordingly.

 

var doc = app.activeDocument;

var item = doc.pathItems;

var newLayer = doc.layers.add();

newLayer.name = "New Layer";

 

var newL = doc.layers['New Layer'];

var oldL = doc.layers['Layer 1'];

 

var list = new Array();

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

{

    list.push(dist(item[i].geometricBounds[0]/2.834645,item[i].geometricBounds[1]/2.834645).toFixed(3));

    item[i].name = list[i];

}

list.sort(sort);

list.reverse();

for(var j = 0 ; j <  list.length; j++)

{

    for(var k = 0; k < oldL.pathItems.length; k++)

    {

        if(oldL.pathItems[k].name == list[j])

        {

            oldL.pathItems[k].move(newL, ElementPlacement.INSIDE);

        }

    }

}

function sort(A,B){return (A - B);}

function dist(A,B){return (Math.sqrt(A*A+B*B));}

 

 

1 reply

Qwertyfly___
Legend
November 16, 2014

When cutting you want to make sure you cut holes (ie. Center of "O") before cutting the outside.

I cut more with a CNC router so this is probably not as important when cutting vinyl.

But I run all my designs through cam software for cut paths and optimizing of.

not sure how you could decide on start and end position of each cut with illustrator.

Can you clarify what you mean by "relative position to page origin".

Do you mean:

Top left object, followed by next closest object, and so on?

siomospAuthor
Inspiring
November 17, 2014

Hello , thanks for the reply

I am printing and cutting directly from the same illustrator file, with versaworks rip( using a roland printer-cutter), so the cutting order is very important.

Clarifying about relative position.

The goal is to have the shorter possible cutting head movement

So, with relative position , i mean,

Cut first  the top left object, then the 2nd closest to top left , then the 3d closest to top left , and so on.

Hope that the following image is helpfull

siomospAuthor
Inspiring
November 19, 2014

Sorry,

item.geometricBounds[0] = left

item.geometricBounds[1] = top

item.geometricBounds[2] = right

item.geometricBounds[3] = bottom

So it uses top left, I made a mistake in my description.

to measure to Right would take more code as you need to measure page width etc...


Great , thanks a lot!!