JS - selection of the center of the artboard / New Document with some dimensions of the artboard

TL; DR:

How do I Center my current selection to the artboard?

as well as hitting the "align horizontal center" and the «align vertical center» buttons

Hello

I searched for the last two hours and before my head hit the keyboard I wanted to ask for help.

What I am struggling with:

in my init function, I create a new document and then copy all the layers of the previous document step by step to the new document and then save it as SVG.

Init

(function() {}

Destination = Folder.selectDialog ("selecting a folder for files SVG.', 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 original document where the layers are copied from.

so, I want the same artboard size as in my original document.

I am fine with the fact that fixed values or directly take the values of the initial RFSO.

I tried this on the segment where I create the new document:

Init

(function() {}

Destination = Folder.selectDialog ("selecting a folder for files SVG.', docPath");

If (! destination) {return ;}

holderDoc = app.documents.add ();

holderDoc.artboards [0] .artboardRect = [0,0,128,128];

stepThroughAndExportLayers (docRef.layers);

}());

and receive this error message:

"Error 1200: Illustrator error: 1346458189 ("PARM").

Online: 83

-> holderDoc.artboards [0] .artboardRect = [0,0,128,128]; »

what I read on the web means that illustrator does not know what to choose document. but I called him directly. so, what could be the problem?

to clearify: I don't want to adapt to the artboard for the images/layer. the work plan must always be a certain size. (for me 128px by 128px)

Thank you for helping me to each fixing of my approach highly or offer a completely new.

Thank you very much in advance.

Edit: workaround solution


(function() {}

Destination = Folder.selectDialog ("selecting a folder for files SVG.', 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);

}());

now, I added a new work plan to the new document with the same size as the work plan on the original document.

I have remove the work plan predefined on the new doc and the new work plan as active.

BUT!

now, the work plan is not centered in the window. Illustrator that allows to place my image with ctrl + c-> ctrl + v somewhere outside the artboard.

Now I need to align my selection in the center of the artboard. but I can't find any reference on how to Center a selection to the artboard.

I don't know if I understand you right.

If you want to create a new document with a fixed width and height, you can do this:

var doc = app.documents.add(DocumentColorSpace.RGB, new UnitValue ("128", "px"), new UnitValue ("128", "px"));

If you want to only align your objects selected on the artboard, you can try this:

Note that the result may be different, if the clipping masks are exist in the document.

Please test it first on copies of your documents. Use it at your own risk.

// ArtboardCenterAroundSelectedPaths.jsx
// works with CS5
// http://forums.adobe.com/thread/1336506?tstart=0
// (title: script to align selected objects to artboard)
// quick & dirty, all selected items will be centered at the active artboard
// (include clipping paths  !visible result can be different)

// regards pixxxelschubser  19.Nov. 2013

var aDoc = app.activeDocument;
var Sel = aDoc.selection;

if (Sel.length >0 ) {
    var abIdx = aDoc.artboards.getActiveArtboardIndex();
    var actAbBds = aDoc.artboards[abIdx].artboardRect;

    var vBounds = Sel[0].visibleBounds;
    vBounds_Li = vBounds[0];
    vBounds_Ob = vBounds[1];
    vBounds_Re = vBounds[2];
    vBounds_Un = vBounds[3];

if (Sel.length >1 ) {
    for (i=1; i vBdsI[0] ) {vBounds_Li = vBdsI[0]};
        if( vBounds_Ob < vBdsI[1] ) {vBounds_Ob = vBdsI[1]};
        if( vBounds_Re < vBdsI[2] ) {vBounds_Re = vBdsI[2]};
        if( vBounds_Un > vBdsI[3] ) {vBounds_Un = vBdsI[3]};
        }

    aDoc.artboards[abIdx].artboardRect = [vBounds_Li +((vBounds_Re - vBounds_Li)/2-(actAbBds[2]-actAbBds[0])/2), vBounds_Ob -((vBounds_Ob - vBounds_Un)/2+(actAbBds[3]-actAbBds[1])/2), vBounds_Li +((vBounds_Re - vBounds_Li)/2-(actAbBds[2]-actAbBds[0])/2)+(actAbBds[2]-actAbBds[0]), vBounds_Ob -((vBounds_Ob - vBounds_Un)/2+(actAbBds[3]-actAbBds[1])/2)+(actAbBds[3]-actAbBds[1])];
    }
    } else {
        alert ("No selection");
        }

Hope this is useful for you.

Have fun

Tags: Illustrator

Similar Questions

  • I use the color picker to select a background color, then try to create a new document using this background color. The appearance of the color changing at this time. It is a new problem. I have successfully used the procedure several times in the p

    My background color changes when I try to apply it. I put the color using the color picker. Then I try to create a new document with the same background color. But that change of a very different color. What I am doing wrong? I've used the previous procedure, several times, without this problem.

    The new document has a different color profile. Make sure that they are the same.

    The same result of RGB numbers in different colors in different color spaces. Or in other words, the color space defines the specific color produced by a certain set of numbers.

  • Having a color changing the question when you copy and paste things into a new document

    Hello, I had a question about copying and pasting in photoshop (something I thought I'd be able to handle).  See the screenshots below:

    First with the move selected tool, I went to command + click on the dark blue model below to highlight and select its layer.  Then, in the following screenshot with the marquee tool, I was trying to copy a square piece of 100 x 100 px of the model.

    Screen Shot 2014-12-03 at 4.31.04 PM.png

    After hitting the command + c to copy, and then I opened a new document with the following and click settings on ok:

    Screen Shot 2014-12-03 at 4.36.11 PM.png

    I knocked and then command + v to paste what I had copied the new document that I created.  However, the part gets confused me is that the color of the background pattern that I copied and pasted is now a different color, as shown below:

    Screen Shot 2014-12-03 at 4.27.38 PM.png

    The glued color is obviously much darker than the original.  Anyone know what is happening here?  Very confused.

    Some how you have copied a composite instead of the layer + styles.

    Try this instead, select the layer as you did

    Create a new document as you did

    Use the move tool and drag the document on the tab of the new document with the mouse still down, drag your document down to the new document.

    Because your new document is set to 100 x 100 is what adapts the layer, so you should be good to go.

    If you still have a question of color or something has not transferred correctly let us know.

  • Name the new document

    As part of an AppleScript I develop, I create a new document, I want to give a specific name. So I tried:

    say application "Adobe Illustrator".

    do new document with Properties ¬

    {color space: RGB, name: myString}

    end of say

    However, the document still appears with the name "without title-1. Is it possible to give the document a name when you create? Or can only do you when recording?

    I need the same thing and found the answer using the DocumentPreset object.

    In JavaScript, I put the name of the new document in the options DocumentPreset and applied when I created the document. getPoints is simply a conversion from inches to points, btw.

    var docPreset = new DocumentPreset;
    docPreset.units = RulerUnits.Inches;
    docPreset.width = getPoints(13.0);
    docPreset.height = getPoints(18.0);
    docPreset.title = 'test document';
    docPreset.colorMode = DocumentColorSpace.CMYK;
    
    var doc = app.documents.addDocument(DocumentColorSpace.CMYK,docPreset);
    
  • Photosmart C4780: Cannot load the solution Center since a cΘdΘrom with Windows 10 to scan

    Things worked fine with my old computer running Windows 7. However this computer failed last week, well that was 10 years old, and I bought a new computer with Windows 10.

    He had no problem with the wireless print job immediately. However, I need to have the program loaded in to scan documents. I think that the program is called Center of HP solutions? Despite the CD, I am unable to install the program.

    It presents a panorama of a Mediterranean home fron a gateway with Brown and the message "select install to begin the installation of your new HP device ' however Instrall is not presented as an option only"Exit".".

    I tried the Support Web site without success, everything I can find drivers.

    Help is greatly appreciated.

    Robert

    @RobertinHerts

    You will not find a download link for the HP Solution Center software as part of the full software solution features of your printer.

    Install HP Solution Center with the full Windows software feature of the HP Web site, or use the Printer Wizard.

    HP Photosmart C4700 all-in - One Printer series Full Feature Software and Driver

    http://ftp.HP.com/pub/softlib/software13/COL28119/MP-109702-3/PS_AIO_06_C4700_140_408-5.exe

    HP printer install wizard for Windows

    http://ftp.HP.com/pub/softlib/software13/COL50403/MP-150580-2/hppiw.exe

    You can see this also.

    Your HP printer static IP address assignment

    http://WWW8.HP.com/h20621/video-gallery/us/en/customer-care/1972074076001/assigning-your-HP-printer-a-static-IP-address/video/

    REO

  • PCL Code for the selection of the status bar

    We have a Unix-based program that relies on EZ for the selection of the printer spooler. Printing was allowed until we replaced the old printer with a HP 3005dn. We must make letterhead in tray 3. EZ print spooler requires to print PCL codes. I ran the code numbers range to print from the 3rd drawer.

    My problem is when it receives the print job, you have to hit the OK button twice so he can shoot from the 3rd drawer.

    By changing the PCL code, I can get him out tray 2 automatically, or stops for tray 3.

    I have modifed the installation of manual feeding system and or use requested tray do not help both.

    Here's the line of code in order

    PCLx_lowreceipt_ac_begin_ ^ [& l0o66f4H ^ [& s1C ^ [(s4099t0p12H_]]

    4 H is supposed to designate the selection of the status bar. I spent several hours from 1: 00 until 8: 00 successfully and to have the work automatically pull from tray 3.

    any ideas?

    Solution

    You need to access from the UI and not the control panel

    -IP in the laserprinter

    -Tab settings select

    -Set the camera (left side)

    -Develop "Configure Device" in the center of the page

    -Develop "Impression".

    -Develop 'PCL '.

    -at the bottom, "Mapping of media sources"... assign the Standard classic.

    Worked!

  • Windows is not able to load the selected for the following reason of backup set

    Hello;
     
    I did run a daily backup to a computer in a network with windows backup and Restore Center. the hard drive crashed on this computer and we had to install another. When I try and use advanced restore / backup made on a different computer, I can navigate to the backup on the network computer folder but when I select the folder and click Next it gives me an error:
     
    I get: Windows is not able to load the backup game selected for the following reason:

    There is a problem with the backup catalog... 0x810000E5... restore from a different place...

    Just to add additional information; The computer with the replaced hard drive running Vista family premium, the path to the backup file is \\HPDESKTOP\Public\Backup\Bobruncer-pc\.

    There is another folder under Bobruncer-pc called Bobruncer-pc and all the backup files. I restore from the correct location? Also, the backup folder is 226 concerts but the backups were made from a hard drive of 80 GB... should I worry about this too?

    Thank you

    Dave

    Hi Colt4t5,

    Just to clarify, perform you a complete PC Backup or backup and restore?

    When you do return, and restore, it can be saved as a .zip file in the backup folder. You can decompress the file and retrieve the required files.

    Restore files from a backup
    http://Windows.Microsoft.com/en-us/Windows-Vista/restore-files-from-a-backup

    Back up and restore: frequently asked questions
    http://Windows.Microsoft.com/en-us/Windows-Vista/back-up-and-restore-frequently-asked-questions

    I hope this helps.

    Bindu S - Microsoft Support

    [If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message.] [Marking a post as answer, or relatively useful, you help others find the answer more quickly.]

  • Copy the selection into a new document

    Here's a breakdown of what I am wanting to do... any guidance would be appreciated!

    1. the user will select the elements (blocks of text, items, transparent path)

    2. the user will execute a script that will do the following...

    1. open a new document (8.5 "x 11") with RGB color

    2. anything with a color fill should get gray 100% fill applied

    3. anything with an outline of color should get 100% of applied gray race

    4. then save a .ai file and a PDF in the following format...

    #target illustrator
    
    
    var doc = app.activeDocument;
    var fileName = doc.name;
    var jobName = (fileName).substr(0, 11);
    aiFile = "D:\\Jobs\\"+jobName+"\\AI\\Cover Page.ai"  
    pdfFile = "D:\\Jobs\\"+jobName+"\\PDF\\Cover Page.pdf"  
    
    
    var newaiFile = new File(aiFile);  
    doc.saveAs (newaiFile);  
      
    var pdfOpts = new PDFSaveOptions();      
    pdfOpts.pDFXStandard=PDFXStandard.PDFXNONE;  
    pdfOpts.compatibility = PDFCompatibility.ACROBAT5;      
    pdfOpts.preserveEditability = false;  
    var newpdfFile = new File(pdfFile);      
    doc.saveAs(newpdfFile, pdfOpts);
    
    
    
    
    
    
    

    OK, so I got it away square to where the art jury moves selected items. Someone else wrote the code to move the jury art to the selected items, and I modified to fit my needs. So that being said, a big thank you to pixxxel schubser to get the code for the part (found here... ( https://forums.adobe.com/thread/1336506 )

    Here is the code for anyone to see/modify/use!

    #target illustrator
    
    var newDocSet = new DocumentPreset;
    newDocSet.title = "Cover"
    newDocSet.width = (8.5 * 72);
    newDocSet.height = (11 * 72);
    newDocSet.units = RulerUnits.Inches;
    newDocSet.colorMode = DocumentColorSpace.RGB;
    
    var doc = app.activeDocument;
    var selectedItems = doc.selection;
    
    if (selectedItems.length > 0) {
        var newDoc = app.documents.addDocument(DocumentColorSpace.RGB, newDocSet);
        for (var i = 0; i < selectedItems.length; i++) {
            var newArt = selectedItems[i].duplicate(newDoc, ElementPlacement.INSIDE);
        }
    } else {
        alert("nothing selected");
    }
    
    // to move the new document artboard over to the selected items
    var doc = app.activeDocument;
    var selectedItems = doc.selection;
    
        var abIdx = doc.artboards.getActiveArtboardIndex();
        var actAbBds = doc.artboards[abIdx].artboardRect;  
    
        var vBounds = selectedItems[0].visibleBounds;
        vBounds_Li = vBounds[0];
        vBounds_Ob = vBounds[1];
        vBounds_Re = vBounds[2];
        vBounds_Un = vBounds[3];  
    
    if (selectedItems.length >1 ) {
        for (i=1; i vBdsI[0] ) {vBounds_Li = vBdsI[0]};
            if( vBounds_Ob < vBdsI[1] ) {vBounds_Ob = vBdsI[1]};
            if( vBounds_Re < vBdsI[2] ) {vBounds_Re = vBdsI[2]};
            if( vBounds_Un > vBdsI[3] ) {vBounds_Un = vBdsI[3]};
            }  
    
        doc.artboards[abIdx].artboardRect = [vBounds_Li +((vBounds_Re - vBounds_Li)/2-(actAbBds[2]-actAbBds[0])/2), vBounds_Ob -((vBounds_Ob - vBounds_Un)/2+(actAbBds[3]-actAbBds[1])/2), vBounds_Li +((vBounds_Re - vBounds_Li)/2-(actAbBds[2]-actAbBds[0])/2)+(actAbBds[2]-actAbBds[0]), vBounds_Ob -((vBounds_Ob - vBounds_Un)/2+(actAbBds[3]-actAbBds[1])/2)+(actAbBds[3]-actAbBds[1])];
        } 
    
    // save .ai and .pdf file to correct locations, then close the file
    var allDocs = app.documents;
    
    for(var i = 0; i < allDocs.length; i++){
    var fileName = allDocs[1].name;
    var jobName = (fileName).substr(0, 11);
    aiFile = "D:\\Job Number\\"+jobName+"\\AI\\Cover.ai"
    pdfFile = "D:\\Job Number\\"+jobName+"\\PDF\\Cover.pdf"  
    
    var newaiFile = new File(aiFile);
    var doc = app.activeDocument;
    doc.saveAs (newaiFile);
    saveAI();
    
    var pdfOpts = new PDFSaveOptions();
    pdfOpts.pDFXStandard=PDFXStandard.PDFXNONE;
    pdfOpts.compatibility = PDFCompatibility.ACROBAT5;
    pdfOpts.preserveEditability = false;
    var newpdfFile = new File(pdfFile);
    doc.saveAs(newpdfFile, pdfOpts);
    }
    
    function saveAI( path, name, id ) {
      var saveOpts = new PDFSaveOptions();
      saveOpts.compatibility = PDFCompatibility.ACROBAT6;
    }
    doc.close(SaveOptions.SAVECHANGES);
    
  • Align the selection to the layer (CS4)

    I know that there is this option to align a layer to selection... But what I often do is I want to make a selection and Center it on the layer - IE, the rectangle selection tool. How are you?

    I guess there should be a very simple way to do it.

    I want to do is darken/lighten the edges (a bit like making a thumbnail) around a few images, and I make a selection, invert the selection, feather and to make an exposure mask and go to little matter I think is very pretty. This is often where I want it to be centered on the layer.

    Thank you!

    Set the Distance 0, as in the example above.

    -Christmas

  • cfselect preserve the value selected on the back

    We are on CF9.  I have a form with several fields bound cfselect.  If I submit the form, and then go back using the back button of the browser, all the bound cfselect fields are set back to their original state.  I tried used preserveData = "yes" to the eth and selected set the domain name cfform tag but it doesn't seem to work.

    Is there a way to do this?  Thank you.

    Example code:

    < cfform id = "form1" name = "form1" action = "" majormarketAction.cfm? action = AddRecord "preserveData ="Yes"method ="post">"
    < table border = "0" cellpadding = "4" cellspacing = "0" width = "480" align = "center" class = "FormTable" >
    < b >
    < style td = "" padding-left: 8px; "width ="25% "valign ="top"> < market strong > < / strong > < br / >"
    < name cfselect = "thisMarketID."
    ID = "thisMarketID".
    bind = "SWC:/com/majormarket.getMarketsRemote()"
    display = "MarketLabel."
    value = "MarketID".
    bindOnLoad = 'true '.
    selected = "thisMarketID."
    Class = "formText" / >
    < table >
    < td valign = "top" colspan = "2" > < strong customer > < / strong > < br / >
    < name cfselect = "CustomerID".
    ID = "CustomerID".
    bind = "SWC:/com/majormarket.getCustByMarketRemote({thisMarketID})"
    display = "CustName".
    value = "CustomerID".
    Class = "formText".

    selected = "CustomerID".
    style = "width: 320px;" / >
    < table >
    < /tr >

    Hi Jeff,

    I found as a plant of great forms of SESSION variable that potentially need to use the back button or even refresh.  If you submit the form and action page can set a variable to the SESSION for you.  Then, the user presses back, you can test for the existence of a SESSION variable, if it exists, it is populated if it comes in white.  You can even set the initial variable as a SESSION variable and forget the test piece.

    After playing with html and 'hidden' values, a SESSION variable is a handy piece of code.

    Good luck!

  • How to select only the URLS in the same page

    I'm used to be able to select only the URL with right click of the entire page. After reinstalling Firefox, I can't use this feature more. Please let me know what kind of add-on, I need to have. Thank you

    I looked in the Wayback Machine for an older version of this page. He said:

    Multi links allows you to open, copy or favorite of several links at the same time rather than having to do them all individually.

    To open, links copy or bookmark, you simply right-click and do to drag a rectangle around the links to the desire to act. When you release the right mouse button, you will open/copy/bookmark these links.

    Note: The Wayback Machine does not cache downloads real extension due to the limitations of robots.txt on the site of modules.

    One of these current extensions could be partial replacement:

    I have not tried any of them myself.

  • The download window - behavior on the selection of the Excel window open excel files

    Imagine that you are working on an Excel file. You have completed and saved. You leave open and want to download it via Firefox - whether for a portal, or to send an email or anything else.
    As soon as any Excel file is selected in the window of the Explorer/upload (be it by single click or highlighting by the arrows), Excel window is set up to forward - as if I had clicked on the icon in the taskbar.

    I can't make pile or face of this - it seems to be only Excel.
    It's pretty frustrating in itself and especially when needing to download several Excel files.

    Any ideas?

    Guigs2, you understand.

    COR - el, Yes, it happens only when Excel is already running. He does not Excel if Excel is not running.

    Update: now it no longer. I have no idea what has changed. I have probably quit Firefox, I killed all the process of Excel running, or just rebooted.

    I uninstalled the Flash plugins and installed the latest version.
    If the problem occurs again, I will try it in safe mode.

    Thanks for your help so far!

  • I do not understand this statement "It is a good idea to keep track that uses a bunch of Audio channels selected in the arrange window, unless you actively play or record on a software Instrument."

    It's a good idea to keep track that uses a bunch of Audio channels selected in the arrange window, unless you actively play or record on a software Instrument.

    Which no longer applies in Logic Pro X 10.2.3. In old versions of logic, selecting a range with a software instrument automatically would make this instrument in "Live" mode, which means that the instrument has begun to transform any MIDI in sound with a minimum of delay. This direct mode becomes an instrument need CPU power (on a single processor) and peut overload the audio engine. It is a waste of CPU if there is no direct game. Then select an audio track would ensure that No instrument is in direct mode. Now (LPX 10.2.2 or more) in direct mode can be turned on or off on a track, chosen or not - it is the R button on the track header.

  • Search by location bar goes to my internet service provider instead of search engine selected in the search bar; Why?

    Using Firefox 26.0 for openSUSE 12.3

    I disabled the keyword in the address bar search, because instead of results research of the source selected in the search bar (google), my string input sent to my internet provider, a kind of impasse, unproductive page 'web search' without any result.

    I had typed in "ezsniper' in the address bar. After you disable the keyword search in subject: config, my string entry took me to ezsniper.com, which is better than the impasse page Charter.com

    I put my addresses DNS 8.8.8.8 and 8.8.4.4 (Google Public DNS)

    The problem is not to breed, but is stopped before I did the DNS change. Charter Communications seemed to allow a way to disable the 'service' who had ignored my browser/preferences, so that he could... I appreciate the answers, doubt that Charter will get another chance to again divert the DNS.

  • Keyword.URL no longer works, default search uses it who is selected in the search box, how can I get this search keyword.url in the address bar works again?

    just changed after the last update of firefox. It's very embarrassing because the address bar and search bar are two different entities.

    CTRL + L moves the focus to the address bar

    Ctrl + A then selects all the content
    Ctrl + Del, or a plain Del, or Ctrl + X then deletes that content.
    

Maybe you are looking for

  • Jet Office HP 8600 pro: cannot turn on printer HP 8600 office pro jet

    The printer worked fine two days ago.  Don't ask me why I turned off the power, but I did.  Now I can't get it to power.  The plugs are all well sitting, I tried it in different outlets where I know I can exist.  I have tried holding down the power b

  • performance without clicking the button run

    Hello I am new in programming with Labview. I want to design a system which, since the input variables change, the output must change without click on run to start. Thank you

  • Vista - error message: configuration of updates "step 3 of 3-57% full. Do not turn off your computer. »

    Vista Basic As stated above I get this error message and can not do in SafeMode to rstore system dates back to an earlier era. I did the system of tapping F8 and tried all offered options of safe mode, but it does not open in any safe mode, just this

  • Error 0x8007045D when you try to install Windows Vista SP2

    Hello Currently I have Windows Vista SP1 and want to upgrade to service pack 2. When I try to do the update of Windows, I get "error (0x8007045d) Error_IO_DEVICE. I also tried to install it in safe mode, I get the same error message. After having tra

  • UCS failure test

    Hi all I've deployed a new DC using UCS 5108 with 4 blades (only 2 worked now) also 2-FI and connected to the upstream kernel SW 2 - links between IOM and FI (discovery of chassis by 1 link policy) 1 - uplink by base as the image1 SW FI also I have d