0

enter image description herehttp://swsharings.blogspot.com.tr how do I do this for the described here FEFCO 0201 code box ?

I tried so hard but I couldn't

The .jsx script can be downloaded at the following link instances.

In addition these examples might need people. Are Sorry for my English.

3
  • 1
    I understand it may be a language barrier but I have no idea what your question is.
    – Cai
    Aug 9, 2016 at 17:21
  • Thanks Cai, swsharings.blogspot.com.tr is I downloaded a sample of the written language on-site scripting Indonesia I translate into English with Google Translator. An example I'm working on a more detailed example.
    – enisio
    Aug 10, 2016 at 12:18
  • Its like postscript in jsx. Not bad
    – joojaa
    Aug 10, 2016 at 15:59

1 Answer 1

2

try this (yeah i should refactor it but i cant be bothered, did it for fun):

#target illustrator

// Copyright joojaa 2016
// License: Buy somebody you do not know 
// a beer or other similar culturally 
// appropriate refreshment.

(function(){
var win = new Window('dialog');
var height = txtgroup(win, 'Height', '30 mm');
var width = txtgroup(win, 'Width', '10 mm');
var length = txtgroup(win, 'Length', '40 mm');

var grp = win.add('group');
var ok = grp.add('button {text: "OK"}');
grp.add('button {text: "Cancel"}');

var doDraw = function(){
    draw();
    win.close(0);
    }
ok.onClick = doDraw;

win.show();

function txtgroup(win, name ,txt) {
    var grp = win.add('group');
    grp.add('statictext {text: "'+name+': "}');
    var item = grp.add('edittext {characters: 12, active: true}');
    item.text = txt;
    return item;
}

// almost from scriptUI for dummies
function convert_units(n, to) {
  var unitConversions = {
    'pt': 1.0000000000,
    'p': 12.0000000000,
    'mm': 2.8346456692,
    'in': 72.00000000,
    'ag': 5.1428571428,
    'cm': 28.3464566929,
    'c': 12.7878751998,
    'tr': 3.0112500000
  }
  var obj = fix_measurement(n);
  var temp = (obj.amount * unitConversions[obj.unit]) / unitConversions[to];
  return temp
}

// almost from scriptUI for dummies
function fix_measurement(n) {
  n = n.replace(/ /g, ' '); // Delete all spaces
  n = n.replace(/^([pc])/, '0$1'); // Change p3 to 0p3
  // Infixed 'p' and 'c' to decimal suffixes: 3p6 > 3.5 p
  n = n.replace(/(\d+)([pc])([.\d]+)$/, function() {
    return Number(arguments[1]) + Number(arguments[3] / 12) + arguments[2]
  });
  // Split on unit
  var temp = n.split(/(ag|cm|mm|c|pt|p|in)$/);
  return {
    amount: Number(temp[0]),
    unit: temp.length === 1 ? doc_units() : temp[1]
  };
}








function draw(){

var myDoc = app.activeDocument;
grp = myDoc.groupItems.add();
grp.name = 'dieline';
function line(){

    var l = grp.pathItems.add();
    l.stroked = true;
    l.filled = false;
    return l;
}

var w = convert_units(width.text, 'pt');
var l = convert_units(length.text, 'pt');
var h = convert_units(height.text, 'pt');    

var mm =2.8346456692
var o = [10*mm, -10*mm];
var p = o;

//flap

line().setEntirePath([
                     p=[ p[0], p[1] -(w/2 + 3*mm) ], 
                     p=[p[0] - (w/8 + 4*mm), p[1] - (w/16 + 2*mm)],
                     p=[p[0], p[1] - (h + 6*mm) + 2*(w/16 +2*mm)],
                     [o[0], p[1] - (w/16 +2*mm)]
                     ]                     
                     );

// horizontal lines 
var p = o;
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(h + 6*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);

var p=[o[0] + (w + 4*mm), o[1]];
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(h + 6*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);

var p=[p[0] + (l + 5*mm), o[1]];
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(h + 6*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);

var p=[p[0] + (w + 4*mm), o[1]];
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(h + 6*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);

var p=[p[0] + (l + 5*mm), o[1]];
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(h + 6*mm) ]]);
line().setEntirePath([ p, p=[ p[0], p[1] -(w/2 + 3*mm) ]]);

// then vertical
var p = o;
line().setEntirePath([ p, p=[ p[0] + (w + 4*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (l + 5*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (w + 4*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (l + 5*mm), p[1] ]]);

var p=[o[0], p[1] -(w/2 + 3*mm)];
line().setEntirePath([ p, p=[ p[0] + (w + 4*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (l + 5*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (w + 4*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (l + 5*mm), p[1] ]]);

var p=[o[0], p[1] -(h + 6*mm)];
line().setEntirePath([ p, p=[ p[0] + (w + 4*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (l + 5*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (w + 4*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (l + 5*mm), p[1] ]]);

var p=[o[0], p[1] -(w/2 + 3*mm)];
line().setEntirePath([ p, p=[ p[0] + (w + 4*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (l + 5*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (w + 4*mm), p[1] ]]);
line().setEntirePath([ p, p=[ p[0] + (l + 5*mm), p[1] ]]);

return grp;
}

})();
4
  • The script works very well. How do I convert a rectangular shape in all fields. That's my only problem now.
    – enisio
    Aug 16, 2016 at 22:10
  • @ensio in the very beginning there is 3 line lf vars for height width and length there you see and set the default values.
    – joojaa
    Aug 20, 2016 at 6:05
  • @ensio delete the lives with var w = unitconvert(xxx) But wouldnt it be easier just leave that in and assume default units is mm and then let the user type whatever unit if it is not?
    – joojaa
    Aug 20, 2016 at 20:13
  • @ensio Look I did it for fun, if i must debug/change stuff for you its like work. For work you should hire me. I have a better unit input system that can accept defaults but its too many lines to share across this link but again its for fun. Dont make it feel like work. please.
    – joojaa
    Aug 20, 2016 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.