Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Start a new Document with Millimeters

$
0
0

Hi there,
I am new to Illustratror Scripting.

I changed a Script from William Ngan, http://www.metaphorical.net and http://forums.adobe.com/message/3813716?tstart=1

It saves EPS-files instead of AI-Files. But the Units are still in PT. I want them to be in Millimeters and the artboard isn't focused on the viewport.
I suppose it's RulerUnits.Millimeters but somehow it doesn't work and when I pick a line it shows pt. I don't know how to write it. Perhaps you find the solution.

I deleted the Comments of William so it's not as long as the original. I tried at the line:

var newdoc = app.documents.add ( doc.documentColorSpace, doc.width, doc.height );

 

I thought this would help:

newdoc.RulerUnits = doc.RulerUnits;

But it doesn't work. Hope it shows the idea.

 

/* Here the Script starts */

 

var doc = app.activeDocument;

var docname = (doc.name.split('.'))[0]; // name

var doc_artboard = doc.artboards[0].artboardRect;

 

if (app.documents.length > 1) {

        alert( "Nur ein Dokument darf geöffnet sein. Schließen Sie andere Dokumente und führen Sie das Script erneut aus.");

} else {

 

    var ok = confirm( "Bitte speichern Sie zuerst Ihr Original.\nDie Ebenen werden im gleichen Ordner wie Ihre Datei gespeichert.\nWeiter?" );

 

    if (ok) {

 

        // prepare layers

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

            doc.layers[i].visible = false;

        }

 

 

        // go through each layers

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

            app.activeDocument = doc;

 

 

            if (i>0) doc.layers[i-1].visible = false;

            doc.layers[i].visible = true;

            doc.activeLayer = doc.layers[i];

 

            saveAI( doc.path, doc.activeLayer.name, i );

        }

 

 

        // close original file without saving

        doc.close( SaveOptions.DONOTSAVECHANGES );

 

    }

 

}

 

 

function saveAI( path, name, id ) {

 

    var currlayer = doc.layers[id];   

    var g = currlayer.groupItems.add();

    group( g, currlayer.pageItems );   

 

    var t = g.top;

    var l = g.left;

 

    /*

    var myPreset = app.getPresetSettings("Druck");

    app.documents.addDocument("Druck", myPreset );

    */

 

    var newdoc = app.documents.add ( doc.documentColorSpace, doc.width, doc.height );

    newdoc.artboards[0].artboardRect = doc_artboard;

    /* app.preferences.rulerUnits = Units.Millimeters; */

    /* app.activeDocument.rulerUnits = RulerUnits.Millimeters; */

    /* newdoc.Units = RulerUnits.Millimeters; */ 

    var newlayer = newdoc.layers[0];

 

    g.duplicate( newlayer, ElementPlacement.PLACEATBEGINNING );

    newlayer.pageItems[0].top = t;

    newlayer.pageItems[0].left = l;

 

    path.changePath( name+".eps" );

 

    var saveOpts = new EPSSaveOptions();

    /* saveOpts.compatibility = ILLUSTRATOR16; */

    saveOpts.embedLinkedFiles = true;

    saveOpts.includeDocumentThumbnails = true;

    saveOpts.embedAllFonts = true;

    saveOpts.saveMultipleArtboards = false;

    saveOpts.cmykPostScript = true;

    saveOpts.preview = EPSPreview.TRANSPARENTCOLORTIFF;

 

 

 

    newdoc.saveAs( path, saveOpts );

    newdoc.close( SaveOptions.DONOTSAVECHANGES );

 

 

    // wait for the new file to save and close before continue.

    // A callback function (if possible) will be better than a while loop for sure.

    while (app.documents.length > 1) {

        continue;

    }

}

 

 

function group( gg, items ) {

 

    var newItem;

    for(var i=items.length-1; i>=0; i--) {

 

 

        if (items[i]!=gg) {

            newItem = items[i].move (gg, ElementPlacement.PLACEATBEGINNING);

        }

    }

    return newItem;

}


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>