Highlighted

Optimize objects stacking order for vinyl cutting

Explorer ,
Nov 16, 2014

Copy link to clipboard

Copied

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

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.geometricBounds[0]/2.834645,item.geometricBounds[1]/2.834645).toFixed(3));

    item.name = list;

}

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.name == list)

        {

            oldL.pathItems.move(newL, ElementPlacement.INSIDE);

        }

    }

}

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

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

TOPICS
Scripting

Views

2.7K

Likes

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

Optimize objects stacking order for vinyl cutting

Explorer ,
Nov 16, 2014

Copy link to clipboard

Copied

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

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.geometricBounds[0]/2.834645,item.geometricBounds[1]/2.834645).toFixed(3));

    item.name = list;

}

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.name == list)

        {

            oldL.pathItems.move(newL, ElementPlacement.INSIDE);

        }

    }

}

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

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

TOPICS
Scripting

Views

2.7K

Likes

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
Nov 16, 2014 0
Guide ,
Nov 16, 2014

Copy link to clipboard

Copied

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?

Likes

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
Reply
Loading...
Nov 16, 2014 0
Explorer ,
Nov 17, 2014

Copy link to clipboard

Copied

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

optimized-path.jpg

Likes

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
Reply
Loading...
Nov 17, 2014 0
Guide ,
Nov 17, 2014

Copy link to clipboard

Copied

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.geometricBounds[0]/2.834645,item.geometricBounds[1]/2.834645).toFixed(3));

    item.name = list;

}

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.name == list)

        {

            oldL.pathItems.move(newL, ElementPlacement.INSIDE);

        }

    }

}

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

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

Likes

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
Reply
Loading...
Nov 17, 2014 1
Explorer ,
Nov 17, 2014

Copy link to clipboard

Copied

Thanks for the script ,

i will try it and post the results!

Likes

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
Reply
Loading...
Nov 17, 2014 0
Explorer ,
Nov 18, 2014

Copy link to clipboard

Copied

The script works perfectly

One question

How i can modify it to measure the distance from top LEFT of page to top LEFT of pathitems?

( instead of top right of page to top right of pathitems that measures now)

Thanks a lot!

Likes

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
Reply
Loading...
Nov 18, 2014 0
Guide ,
Nov 18, 2014

Copy link to clipboard

Copied

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...

Likes

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
Reply
Loading...
Nov 18, 2014 0
Explorer ,
Nov 19, 2014

Copy link to clipboard

Copied

Great , thanks a lot!!

Likes

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
Reply
Loading...
Nov 19, 2014 0
Guide ,
Nov 19, 2014

Copy link to clipboard

Copied

No problem. Glad I could help

Likes

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
Reply
Loading...
Nov 19, 2014 1
New Here ,
Jan 06, 2018

Copy link to clipboard

Copied

What is this part?
I took the script you copied above and it only makes a new layer. nothing else happens. I just copied the whole text. Opened another script in txt document. pasted your script and saved the file. renamed it but as i said it doesn't work. it just created a new layer.

Likes

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
Reply
Loading...
Jan 06, 2018 0
New Here ,
May 19, 2018

Copy link to clipboard

Copied

The original script only processes pathItems. It depends on what you are trying to re-order. Im my case everything is grouped so here is an example.

This worked for me.

var doc = app.activeDocument; 

var item = doc.groupItems; 

var newLayer = doc.layers.add(); 

newLayer.name = "New Layer"; 

 

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

var oldL = doc.layers['DISPLAY']; 

 

var list = new Array(); 

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

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

    item.name = list

list.sort(sort); 

list.reverse(); 

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

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

    { 

        if(oldL.groupItems.name == list

        { 

            oldL.groupItems.move(newL, ElementPlacement.INSIDE); 

        } 

    } 

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

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

Likes

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
Reply
Loading...
May 19, 2018 0
Community Beginner ,
Sep 11, 2020

Copy link to clipboard

Copied

Hi siomosp, nice script man. I manage to make your script work, however the script above created by  Qwertyfly gives me the following error: 

 

Error:1302: No such element

Line:30

→    list.push(dist(item.geometricBounds[0]/

2.834645,item.geometricBounds[1]/2.834645).toFixed(3));

 

What could I be doing wrong?

 

I will be cutting 7 meters of single letters with versaworks but I need the stack order to be as optimal as possible. 

 

The file looks like this:

 

2020-09-11_15h00_18.png

Thanks in advance

Likes

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
Reply
Loading...
Sep 11, 2020 0
Explorer ,
Oct 05, 2020

Copy link to clipboard

Copied

Hello!

Latest Versaworks ( Dual and V6 ) have its own algorithm for optimizing cutting sequence.

It is not the best, but it is better than nothing.

At your case i think it will do a good job

I hope they will make the cutting sequence smarter shortly!

 

 

Likes

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
Reply
Loading...
Oct 05, 2020 0
Adobe Community Professional ,
Oct 05, 2020

Copy link to clipboard

Copied

@janaleks oh wow. in my experience with versaworks and roland printers... you'd really be better off breaking that up in to several files. using one file to cut all of that is asking for disaster. the longer your sheet gets, the harder it is for the printer to move the material back and forth, and it doesn't slow down towards the end, so it's going to be trying to pull a ton of material back and forth really quickly which can cause the material to slip, slide, get crooked, etc. and if you wait 2 hours for things to cut, and then things get messed up, you probably have to start from scratch rather than just re-doing the small part that got messed up.

 

Likes

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
Reply
Loading...
Oct 05, 2020 0