• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Is it possible to convert RasterItem to placedItem?

Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Hi all , is it possible to convert RasterItem to placedItem in illustrator? Using script.

i have rasterise the placedItem manually but when I check it through the script It shows the typename as placedItem.

TOPICS
Scripting

Views

5.0K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 20, 2022 Jul 20, 2022

Hi @Abpujar, I have good news I think. I've been working on a script that will "unembed" raster items. Maybe this is what you need? Currently the script will "unembed" all raster items in document. It will save them into a "Links" folder in the same folder as the .ai document as .psd files and link them (so they will be linked placed items). I couldn't find any other scripts that solved this problem. Let me know if it helps.

- Mark

 

 

/**
 * Unembed Raster Items
 * for Adobe Illustrator 2022
 *
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

Hi @timothy5E42, I don't really understand that request. Can you give some more explanation?

- Mark

Votes

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
community guidelines
New Here ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

embedd an image > unembedd> save file> embedd again> release mask> delete mask

I dont know if you need photoshop installed.

the picture is for when it needs to be emedded again

 

Votes

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
community guidelines
Community Expert ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

I still don't understand. It seems like what you are describing is a strange thing to do. Can you explain what problem you are solving by doing those steps? In any case, as soon as you talk about "Convert Layers To Objects" you are largely outside the scope of this script and topic. Maybe start a new topic? But please describe problem very rigorously.

- Mark

Votes

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
community guidelines
New Here ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

Best way is to use code editor. Try Sublime Text, it's very simple, and you can just edit one file without creating any project like in IDE.

Votes

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
community guidelines
New Here ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

the best way to describe what I am trying to accomplish is to follow the instructions on illustrator. Take a .PNG file with a larger clear background than colored pixels. another explanation is a PNG file with a clear back ground that needs to be cropped. 

Votes

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
community guidelines
New Here ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

embedd an image - > unembedd-> save file-> embedd again-> release mask-> delete mask

Votes

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
community guidelines
New Here ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

When it needs to be emedded again

Votes

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
community guidelines
New Here ,
Sep 07, 2023 Sep 07, 2023

Copy link to clipboard

Copied

Thank you Thank you Thank you!!!!!! This did EXACTLY what we needed! Wow thank you!!! We have many old packaging PDF files that we need to pull the renders from to place into our new templates, and this just cut the labor down by A LOT!!! Thank you!

Votes

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
community guidelines
Community Expert ,
Sep 07, 2023 Sep 07, 2023

Copy link to clipboard

Copied

LATEST

Great to hear! 🙂

Votes

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
community guidelines
Community Expert ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Very good approach, Mark. Thank you for sharing.

 

I did some quick tests and basically the script is running well.

 

But as far as I can see, currently there will be some localisation issues if you use it with non-English international Illustrator versions.

 

For example, in line 253:

 

myDocPreset = app.getPresetSettings('Print');

 

The preset 'Print' (or its name) does not exist in e.g. the German version of Illustrator. Therefore the script will be interrupted.

 

You would have to replace it with the localised name 'Druck' or various completely different names in other non-English Illustrator versions.

 

Votes

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
community guidelines
Community Expert ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Thanks for testing it out, Kurt and great comment about language! Could I use the index of startup presets list? Could you please check these:

alert(app.startupPresetsList[0] + '\nDoes this mean "print"?');
alert(app.startupPresetsList[2] + '\nDoes this mean "web"?');

- Mark

Votes

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
community guidelines
Community Expert ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Not as you may think (or hope), Mark.

 

Line 1 [0] alerts the profile "Grafik und Illustration" (in English: "Art & Illustration")

 

Line 2 [2] alerts the profile "Film und Video" (in English: "Film and Video")

 

I think using the index may get even more confusing if you have (a lot of) custom profiles in the dropdown menu.

 

Votes

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
community guidelines
Community Expert ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Hi Kurt, I believe I have fixed that issue (I edited script above). Just a basic RGB or CMYK document is fine for this purpose, so I avoided accessing startupPresets. Thanks again for your help.

- Mark

Votes

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Hi @m1b  a big hug to you, thank you for taking your time to prepare this script.

While testing this script I got error in -

"// relink to the embedded image

            var newImage = oldImage.layer.placedItems.add();

            newImage.file = file;"

This line ,here the newImage is not getting file property so the next line will get error. 

 

Is it possible to convert the rasterItem to placedItem?? 

Votes

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
community guidelines
Community Expert ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Hi @Abpujar, I cannot reproduce that problem using your previous sample file (with the eagle). Does the script fail on every document? Can you post a screenshot of exact error you are seeing? And maybe send me a sample file that causes the script to fail?

- Mark

Votes

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
community guidelines
Explorer ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

Hi @m1b your script is working absolutely fine.

Thank you so much for helping.

 

I have another issue. in the above script is used to converting RasterImage to placedItem while doing unembedding.

Now how can we convert that converted placedItem to RasterItem, We can use embed() method but while using this method it will create clip group to a image. But I don’t want to create a clip group while embedding.

Votes

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
community guidelines
Community Expert ,
Jul 23, 2022 Jul 23, 2022

Copy link to clipboard

Copied

Hi @Abpujar, to go back the other way—so that a linked PlacedItem is converted to an embedded RasterItem, please try this script:

var doc = app.activeDocument,
    item = doc.selection[0],
    embeddedRasterItem = embedPlacedItem(item);




/**
 * Embeds a placed Item and ungroups it.
 * @author m1b
 * @date 2022-07-23
 * @param {PlacedItem} item - an Illustrator PlacedItem.
 * @return {RasterItem} - the embedded RasterItem.
 */
function embedPlacedItem(item) {

    if (
        item == undefined
        || typeof (item.embed) != 'function'
    ) {
        alert('Please select a Linked Item and try again.');
        return;
    };

    var previousInteractionLevel = app.userInteractionLevel;
    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

    var itemLayer = item.layer,
        embeddedItem = item.duplicate();

    embeddedItem.embed();

    var items = itemLayer.pageItems;
    for (var i = 0; i < items.length; i++) {
        if (
            items[i].uuid == item.uuid
            && i > 0
            && items[i - 1].constructor.name == 'GroupItem'
        ) {
            embeddedItem = ungroup(items[i - 1])[0];
            break;
        }
    }

    item.remove();

    // clean up
    app.userInteractionLevel = previousInteractionLevel;

    return embeddedItem;

}




/**
 * Ungroup a group.
 * @author m1b
 * @date 2022-07-23
 * @param {GroupItem} group - an Illustrator GroupItem.
 * @param {Document|Layer|GroupItem} whereToUngroup - the new container for the previously grouped items.
 * @returns {Array[PageItems]} - the ungrouped items.
 */
function ungroup(group, whereToUngroup) {

    if (!group.pageItems)
        return false;

    var placement,
        items = [];

    if (whereToUngroup == undefined) {
        // behave like manual ungroup
        whereToUngroup = group;
        placement = ElementPlacement.PLACEBEFORE;
    }

    else {
        // put the ungrouped items "into" the new location
        placement = ElementPlacement.PLACEATBEGINNING;
    }

    for (var i = group.pageItems.length - 1; i >= 0; i--) {
        items.push(group.pageItems[i]);
        group.pageItems[i].move(whereToUngroup, placement);
    }

    return items.reverse();
}

As you noticed earlier, the embed() method groups the rasterItem, so the script above ungroups it. As you can see there is a little bit of complication to the process. - Mark

Votes

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
community guidelines
Community Expert ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

Thanks, Mark. I think not using the localised presets/profiles is a good idea.

 

I hope you don't think that I'm going to be a nit-picky killjoy and don't mind that I did some more testing. As far as I can see, several other funny things may happen. For example:

 

- Scaled rotated images may change their original dimensions, positions, and sometimes their overall appearance.

 

- Images to which effects are applied (e.g. drop shadows, outer glow, feather or additional fills/strokes etc.) will be unembedded, but the results may be pretty "surprising" (e.g. "giant" sizes), the effects may get removed and sometimes even entire images disappear. Also, the original positions may shift considerably.

 

- If an embedded raster image contains at least one spot colour, unembedding will fail or produce undesired results.

 

You can download an Illustrator test file that contains some of the objects mentioned above.

 

Unembedder – Test file 1

 

Just open the document, run your script, wait until it's done and compare it to the initial file.

 

Votes

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
community guidelines
Community Expert ,
Jul 23, 2022 Jul 23, 2022

Copy link to clipboard

Copied

Hey @Kurt Gold, this is awesome analysis. Thanks very much! I've updated the script above including an important fix to do with rotated rasterItems (I just had the matrix operations backwards in one place). Unfortunately there isn't an easy fix for any of the other cases. I've left them in, with the option for the script to just ignore them if user prefers, but they will generate a warning message when the results are shown. See the screenshot below for notes on your sample file.

- Mark

Screen Shot 2022-07-23 at 9.36.27 pm.png

Votes

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
community guidelines
Community Expert ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

Thank you, Mark.

 

Right now I'm not going to make things more complicated than necessary. Your script is very good, just as is. Of course, there may be some other special cases that could disturb it, but for no-nonsense plain embedded raster images it works properly.

 

No doubt, it exemplarily shows that it may be always a bit chancy to use scripts (or actions) if there are files with unknown or unexpected occurrences.

 

Votes

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
community guidelines
Explorer ,
Aug 08, 2022 Aug 08, 2022

Copy link to clipboard

Copied

Hi @m1b , while unembeding RasterImage the progress bar is displaying automatically during the process of exporting file .that progress bar is not required , is it possible to remove this progress bar?

 

Thank you.

Votes

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
community guidelines
Community Expert ,
Mar 08, 2023 Mar 08, 2023

Copy link to clipboard

Copied

Hi @Abpujar, sorry for late reply—I didn't see until now. Unfortunately I can't stop Illustrator showing those progress bars. The script makes an attempt, by setting UserInteractionLevel.DONTDISPLAYALERTS, but it doesn't seem to stop those.

- Mark

Votes

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
community guidelines