JS - Center Selection to Artboard / New Document with certain Artboard size

TL;DR:
how do I center my current selection to the artboard?
just like hitting the "horizontal align-center" and "vertical align-center" buttons.
Hi,
I've been searching for the last two hours and before my head hits the keyboard I wanted to ask you for help.
What I'm struggling with:
in my init function i create a new document and then copy all layers from the previous document step by step to the new document and then save it as SVG.
// Init
(function(){
          destination = Folder.selectDialog('Select folder for SVG files.', docPath);
          if (!destination){return;}
          holderDoc = app.documents.add();
          stepThroughAndExportLayers(docRef.layers);
my problem is that holderDoc = app.documents.add(); always creates a document that is not the same size as my initial document where the layers get copied from.
so I want the exact same artboard size as in my initial document.
I'm fine with either doing it as fixed values or taking directly the values of the inital doc.
i tried this in the segment where I create the new document:
// Init
(function(){
  destination = Folder.selectDialog('Select folder for SVG files.', docPath);
  if (!destination){return;}
  holderDoc = app.documents.add();
  holderDoc.artboards[0].artboardRect = [0,0,128,128];
  stepThroughAndExportLayers(docRef.layers);
and get this error message:
"Error 1200: an Illustrator error occured: 1346458189 ('PARM')
Line: 83
-> holderDoc.artboards[0].artboardRect = [0,0,128,128];"
which from what I've read on the web means that illustrator doesnt know what document to pick. but i have called it directly. so what could be the issue?
to clearify: I do not want to fit the artboard to the images/layer. the artboard should always have a certain size. (for me 128px by 128px)
I would highly appreciate you helping me with either fixing my approach or propose a completely new one.
Thanks so much in advance.
// edit: workaround
(function(){
          destination = Folder.selectDialog('Select folder for SVG files.', docPath);
          if (!destination){return;}
          var activeArtboard = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];
          var ABRect = activeArtboard.artboardRect;
          holderDoc = app.documents.add();
          holderDoc.artboards.add(ABRect);
          holderDoc.artboards.remove(0);
          holderDoc.artboards.setActiveArtboardIndex(0);
          //stepThroughAndExportLayers(docRef.layers);
i now added a new artboard to the new document with the same size as the artboard on the initial document.
i remove the predefined artboard on the new doc and set the new artboard as active.
BUT!
the artboard is now not centered into the window. which lets illustrator place my image with ctrl+c -> ctrl+v somewhere outside the artboard.
i now need to align my selection to the center of the artboard. but i cant find any reference on how to center a selection to the artboard.

yes of course. i never modify the author's comments in original scripts.
but I wont post the script anywhere when it doesnt work anyway haha.
this is what I've done now:
// Init
(function(){
          destination = Folder.selectDialog('Select folder for SVG files.', docPath);
          if (!destination){return;}
          var activeArtboard = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];
          var ABRect = activeArtboard.artboardRect;
          // create new document with same artboard as original
          holderDoc = app.documents.add(DocumentColorSpace.RGB, new UnitValue ((Math.abs(ABRect[0]-ABRect[2])), "px"), new UnitValue ((Math.abs(ABRect[0]-ABRect[2])), "px"));
          stepThroughAndExportLayers(docRef.layers);
in order to create the new document with the same dimensions as my orignal doc, I first read the artboardRect dimensions of the current artboard and then create the document with those values passed as parameters. the calculation is to get the real width since artboardRect gives you left,top,right,bottom values and not just height and width.
this only works for square formats though. to make it properly you'd have to change the second "new UnitValue" to use the top and bottom values of artboardRect but I currently dont need to do so.
* Layers to SVG - layers_export.jsx
* @version 0.1
* Improved PageItem selection, which fixed centering
* @author Anton Ball
* Exports all layers to SVG Files
* I didn't want every layer in the SVG file so it first creates a new document
* and one by one copies each layer to that new document while exporting it out
* as an SVG.
* TODO:
* 1. More of an interface wouldn't hurt. Prefix option and progress bar of some description.
// Variables
var docRef = app.activeDocument,
          docPath = docRef.path,
          ignoreHidden = true,
          svgExportOptions = (function(){
                    var options = new ExportOptionsSVG();
                    options.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
                    options.embedRasterImages = true;
                    options.fontType = SVGFontType.OUTLINEFONT;
                    return options;
          destination, holderDoc;
// Functions
var stepThroughAndExportLayers = function(layers){
          var layer,
                    numLayers = layers.length;
          for (var i = 0; i < numLayers; i += 1){
                    layer = layers[i];
                    if (ignoreHidden && !layer.visible){continue;}
                    copyLayerTo(layer, holderDoc);
                    // Resize the artboard to the object
                    selectAll(holderDoc);
                    exportAsSVG(validateLayerName(layer.name, '-'), holderDoc);
                    // Remove everything
                    holderDoc.activeLayer.pageItems.removeAll();
          holderDoc.close(SaveOptions.DONOTSAVECHANGES);
// Copies the layer to the doc
copyLayerTo = function(layer, doc){
          var pageItem,
                    numPageItems = layer.pageItems.length;
          for (var i = 0; i < numPageItems; i++){
                    pageItem = layer.pageItems[i];
                    pageItem.duplicate(holderDoc.activeLayer, ElementPlacement.PLACEATEND);
// Selects all PageItems in the doc
selectAll = function(doc){
          var pageItems = doc.pageItems,
                    numPageItems = doc.pageItems.length;
          for (var i = 0; i < numPageItems; i += 1){
                    pageItems[i].selected = true;
// Exports the doc to the destination saving it as name
exportAsSVG = function(name, doc){
          var file = new File(destination + '/' + name + '.svg');
          holderDoc.exportFile(file, ExportType.SVG, svgExportOptions);
// Makes sure the name is lowercase and no spaces
validateLayerName = function(value, separator){
          separator = separator || '_';
          //return value.toLowerCase().replace(/\s/, separator);
          return value.replace(/\s/, separator);
// Init
(function(){
          destination = Folder.selectDialog('Select folder for SVG files.', docPath);
          if (!destination){return;}
          var activeArtboard = app.activeDocument.artboards[app.activeDocument.artboards.getActiveArtboardIndex()];
          var ABRect = activeArtboard.artboardRect;
          // create new document with same artboard as original
          holderDoc = app.documents.add(DocumentColorSpace.RGB, new UnitValue ((Math.abs(ABRect[0]-ABRect[2])), "px"), new UnitValue ((Math.abs(ABRect[0]-ABRect[2])), "px"));
          stepThroughAndExportLayers(docRef.layers);

Similar Messages

  • How to create a new document with a given theme, instead of choosing it every time.

    Hi,
    for work I only use a custom made keynote theme.
    I've already deleted all the default themes, and the only one that is listed in the app is the one I actually use.
    However every time I create a new document I have to chose its theme (that's normal having plenty of themes, but in my case is just a waste of time).
    I was wondering if there's a way to tell keynote to start a new document with a given theme, in order to avoid to chose it every time.
    Thank you for reading and for the help you will give.
    Giacomo

    Keynote > Preferences > General tab
    select “Use theme,” and then click Choose to select a theme.

  • Create a new document with settings appropriate for SWF or XFL output.

    I'm studying up for the CS4 ACE exam, and I'm stumped on something. In the "Laying out a Document" section, it says: "Create a new document with settings appropriate for SWF or XFL output." There isn't really anything specific to creating a document for flash, except that you wouldn't add bleed. I can't find anything online that addresses this. Am I missing something here? Any document can be exported to SWF or XFL. This seems rather ambiguous. What is there to know about this?

    You're right that any document can be exported to SWF or XFL. I'm not sure what you're going to be asked on the ACE exam, but here are some resources:
    Help topic:
    http://help.adobe.com/en_US/InDesign/6.0/WS2DECDF40-B6DA-40b6-804F-2703D6C6A460.html
    Tim Cole's first of 3-part series:
    http://blogs.adobe.com/indesignchannel/2008/11/indesign_2_flash_part_i_1.html
    My blog entry:
    http://blogs.adobe.com/indesigndocs/2009/03/exporting_interactive_indesign.html

  • Hi guys n girls. How do you copy a whole table to create a new table with all cell sizes in tact? Thanks for your help. Jason.

    Hi guys n girls. How do you copy a whole table to create a new table with all cell sizes in tact? Thanks for your help. Jason.
    when you copy n paste into a new table, all the cell sizes are changed.
    is there a way to put in a new table from your templates into an existing file, different to the standard very basic ones in insert table.
    I look forward to your answers.  Your help is very much appreciated.
    Also how do you search for question answers already written in this support area please.

    Hi Jason,
    In Numbers 3, you can select a whole table by clicking once in the table to make it active, then click once on the "bull's eye" at the top left.
    Now copy and paste. All formatting (and any cell content) is pasted intact. In Numbers 2.3 (Numbers '09) it is a little different for selecting a whole table. But I won't go into that unless you are using Numbers '09. Please reply.
    I don't like the look of the tables in Insert Table. I keep custom tables in My Templates. I have set Numbers > Preferences > General > For New Documents > Use template: (name of my favourite custom template)
    That opens when I launch Numbers, or ask for a new document (command n). Note that if you follow this preference setting, then Menu > File > New From Template Chooser (for another template) requires you to hold down the option key in that menu.
    Regards,
    Ian.
    Message was edited by: Yellowbox. All formatting (and any cell content) is pasted intact.

  • Link to new window with a specific size

    I want to link to a new window with a specific size in
    dreamweaver.
    Thanks

    check this website, I found it useful....
    http://www.accessify.com/tools-and-wizards/accessibility-tools/pop-up-window-generator/

  • Creating a new document with columns and printing effects

    If you create a new document and set columns into it in the new document menu, and then subsequently create images, tables, text etc. in the document that are bigger than one column (that stretch for example across the entire page), will the part of the image that's in the gutter print and/or show up if it's saved as a PDF?
    Help!
    Thanks!

    Guides are only there as a reference for you to help in alignment.They don't restrict what or where objects can be placed or affect their visibility or printability.
    To see what your page will look like in print, switch to Preview Mode (fast way is to press W with nothing selected).

  • Creating a new document with separate images

    Can someone help me create a new document that has two separate images. I can create a new document but don't know how to place two separate photos in the document. For instance create a document that is 8.5 x11 with two images each 8.5 x 5.5.

    there is a number of ways to do this. also reading the manual to get a basic understanding of how Photoshop works will do wonders. Another method of learning is lynda.com
    here is one way.
    1 make a doc that is 8.5 x 11 at whatever resolution you need.
    2 use a guide as a center point.
    3 open the two pics you want to use.
    4 make sure they are the same res as your 8.5 x 11
    5 drag the layers from the open pics to the 8.5 x 11
    6 crop and size the pics in the file so they fit in each half

  • Setting english as the default language for a new document with arabic version of CC apps

    first off, appologies for the screen name, the name i'm sure i had registered before with account was suppose dot be looged in as was barred, so i used this in frustration.  Read the book, The Etymologicon to learn more.
    and another note.  why is the font size in the subject on this form gigantic? intentional of cockup?
    Now, to the point.
    Please please enlighten me, I'm sure it's simple but i can't find the answer and have been haphazardly ploughing the net for half the night.
    I have installed the Arabic langauge version of CC software becuase i need to do a lot of bilingual layouts.
    But
    I generally use, and start with english, but the defualt new document is always set to all the arabic settings, which is a nightmare.
    How do i make english the defualt type (and all the paragraph and language options) while retaining the functionaility of arabic version. 
    I've found instructions for CS2-6 but nothing remotely sensible about CC, and presume i'm missing something really really obvious.

    Hi,
    Here you have some interesting tutos about foreign languages in LV :
    Localizing Your LabVIEW Application to Different Languages
    Localize LabVIEW Applications in Multiple Languages
    Let me know what happens.
    Regards,
    Message Edité par Steve Mohamed le 02-27-2009 09:02 AM
    Steve M.
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Vidéo-t'chats de l'été : présentations techniques et ingénieurs pour répondre à vos questions

  • New Document with Layer Comp & Groups Link ?

    I'd like to create a script that creates a new photoshop document that automatically creates a set of layer comps with specific names that are linked with groups with identical names or the same name. I don't know whether to create this in Adobe Configurator but since I want to create a 'new' document that does this automatically I don't know if Adobe Configurator is the best route to go ?
    An added bonus it would be benifical to select the layer comp, and save only the selected layer comp or an option to save the entire composition or a layer comp.

    What good are Layer Comps that show Groups if one is to add Layers only
    later on or should Layers in the Groups be created right away?
    In Photoshop when you create a new document File -> New it would create the following layer comps and layer groups.
    The layer comps would be linked to the layer groups with the same name or identical name if allowed, for example if the Layer Group name is not Layer Comp A, rather CompyDesignA the script would know to still link it to Layer Comp A.
    I don't know how many layers I would add to the layer group so the script wouldn't create these layers, the script would then export the layer comp with the selected layer group.
    For example, I select Layer Comp A which is tied to the Layer Group, Layer Group A / or similiar name if I select the layer comp Layer Comp A it would know to save only the Layer Group 'Layer Group A / or similar name' automatically, with the option to save the entire composition with all layer comps and all layer groups, understand ?
    I suppose that upon creating the new composition/document each layer group would have a layer created called 'background' and the first layer created above that background layer would have a screen blend mode applied, automate the task.

  • Copy contents of 2 layers to new document with javascript

    Hi guys !
    Basically i have created a new cutfile generator for a Zund cutting machine we have here at work i have got it to the point where i can create a Registration mark layer and Cut layer now i would like to save this as a layered PDF as this is how the cutter software prefers it. What i would like to know is how with Javascript can I copy the contents of "Regmark" layer and "Cut" layer to a dynamically created new document ? Any thoughts on this will be greatly appreciated thanks so much !
    Regards,
    Bass

    Hi guys,
    Just something i forgot to add, the follow piece of code copies content of "Regmark" layer to new document but its going back and selecting contents of "Cut" layer i am unable to do thanks once again !
    var sourceDoc = app.activeDocument;
    sourceDoc.select(sourceDoc.layers.item("Regmark").pageItems)
    app.copy();
    var destinationDoc = app.documents.add();
    app.pasteInPlace();
    /* NEED SOMETHING HERE TO TAKE ME BACK TO sourceDoc */
    sourceDoc.select(sourceDoc.layers.item("Cut").pageItems)
    app.copy();
    /* ONCE AGAIN SOMETHING TO TAKE ME TO destinationDoc */
    app.pasteInPlace();
    I know im probably going about this all wrong but it's the only thing i can figure out from looking on forum and JS help thanks so much !
    Regards,
    Bass

  • Ilustrator freezes creating a new document with web profile.

    Hi,
    I have the illustrator instalation from creative cloud subscription and everytime i create a new document and on the profile combo choose "web", the illustrator freezes forever.
    Im using mac version in a macbook pro 13" corei7 with 8gigs ram.

    I'm having the same issue with i7 2500k, SSD, 16gb ram, 6870 2gb vram 10.7.4.
    Anyone have any idea if i can get a crash report to help you guys out with figuring this?
    Basically whenever i go -> new and change the document profile to web (or a few others) it just LOCKS and needs to be force quitted.
    I've also just ran with the default and it locks up anyway.    

  • Closing a new document with textvariable

    1. In Indesign CS4 version 6.0.2 ,
    if I create a new document and insert a textvariable, I can save the document and I can close it.
    2. In scripting Indesign CS4 version 6.0.2 with VB.net (Visual Studio 2008 + Framework 3.5),if I open a document manually created under Indesign CS4 version 6.0.2 with a textvariable, I can save the document and I can close it.
    3. In scripting Indesign CS4 version 6.0.2 with VB.net (Visual Studio 2008 + Framework 3.5),if I create a new document and insert a textvariable, I can save the document, but I can't close it. Indesign give a win32 error.
    MyPub = myIndesign.Documents.Add(False)
    MySpread = MyPub.Spreads.Item(1)
    myTextFrames = MySpread.TextFrames
    MyInfos = myTextFrames.Add
    Dim FileNameVariable As InDesign.TextVariable = Nothing
    For Each Item As TextVariable In MyPub.TextVariables
          If Item.VariableType = idVariableTypes.idFileNameType Then
                   FileNameVariable = Item
                   Exit For
         End If
    Next
    Dim FileNameVariableInstance As InDesign.TextVariableInstance = Nothing
    FileNameVariableInstance = MyInfos.TextVariableInstances.Add(idLocationOptions.idAtBeginning)
    FileNameVariableInstance.AssociatedTextVariable = FileNameVariable
    MyPub.Save(FullPath)   'OK
    MyPub.close               'Error Win32 in Indesign.exe
    I try to save the document before creating the FileNameVariableInstance but it's the same result.
    Do you know a way to do it ?
    Regards

    After searching a lot I have finally found the solution :
    MyPub = myIndesign.Documents.Add(False)
    MySpread = MyPub.Spreads.Item(1)
    myTextFrames = MySpread.TextFrames
    MyInfos = myTextFrames.Add
    Dim MyVars as Indesign.TextVariables = MyPub.TextVariables
    Dim FileNameVariableInstance As InDesign.TextVariableInstance = Nothing
    FileNameVariableInstance = MyInfos.TextVariableInstances.Add(idLocationOptions.idAtBeginning)
    FileNameVariableInstance.AssociatedTextVariable = MyVars.item(8) ''index of the textvariable equals to idFileNameType
    MyPub.Save(FullPath)   'OK
    MyPub.close               'OK

  • Can I create a new document with a locked PDF file, add new pages, and lock it all again?

    I published a PDF document ten years ago and now want to add Creative Commons licensing language to the copyright page.  But I forgot the password!  I gather from the Forum that there is no way to recover the password.  However, I wonder if I can take the locked PDF file, create a new document (adding a new page for the licensing information), then lock the whole thing up again.  Will this work?  Thanks for your help!                                                                               

    To create an unprotected file you would need the password.

  • Start new document with view at 100%?

    Every time I start Pages a new document is zoomed at 125%. I created a template that I use all the time & set the view zoomed at 100% before I saved it.
    But every time I create new blank document (or new document from my template) it's zoomed at 125%.
    Is it possible to set it so that a new blank document, or a new one from my template starts up at 100%?

    You can set the default zoom for new documents & those opened from templates in Pages > Preferences in Pages 2 & 3. Pages 1/iWork '05 does not have this setting.

  • Creating a document with different page sizes.

    I'm trying to produce a leaflet with different pages sizes. To try and explain what I mean I have included a picture of what I'd like the front cover to look like. When producing a booklet there doesn't seem to be a provision to individually alter each page size in the pages or document set up panel. Is there anyway around this or do I have to create each page seperately, export to pdf and then combine into the leaflet? Help gratefully received. tomas

    The build booklet feature is for very basic booklets, not something like this.
    Sorry, but you’ll need to make everything full size and then do the cutting.
    Bob

Maybe you are looking for