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

Drag and Drop images/layers from HTML to AI documens (Illustrator)

Explorer ,
Feb 19, 2017 Feb 19, 2017

Copy link to clipboard

Copied

Hello every body!

I want to share my idea of images Drag and Drop realisation without C++ plugin.

Git:

GitHub - KupinFB/Adobe-HTML-Extension-Drag-and-Drop: Adobe HTML Extension - Drag and Drop example

How you can drag something (example):

In Illustrator we can drag only text from an HTML Panel to AI Documents.

For it we have to add attribute draggable="true" to our html tag.
And after it, we will be able to drag our html tag to active document.

Html:

<div class="color" style="background-color:#55AAFF" draggable="true"></div>

We can set the text for dragging.
For it we have to add an event listener - ondragstart="onColorDragStart(event)"ondragstart="onColorDragStart(event)"

Html:

<div class="color" style="background-color:#55AAFF" draggable="true" ondragstart="onColorDragStart(event)"></div>

JS:

function onColorDragStart(event) {

  event.dataTransfer.setData("text/plain", '{color:4000001}');

  return true;

  }

After that, i we drag our HTML tag to the active document we see TextFrame with text - {color:4000001}.

Also we can detect dragEnd.
For it we have to add an event listener - ondragend="onColorDragEnd(event)"on

This method allows us to call ExtendScript after Dropping.

Html:

<div class="color" style="background-color:#55AAFF" draggable="true" ondragstart="onColorDragStart(event)" ondragend="onColorDragEnd(event)"></div>

JS:

function onColorDragEnd(ev) {

  var script = 'replaceColorString("{color:4000001}", 70, 150, 255)'; // rgb(70, 150, 255)

  (new nCSInterface).evalScript(script, function(){

       //console.log("Done");

  });

  return true;

}

ExtendScript:

function replaceColorString(targetCode, r, g, b){

    var doc = app.activeDocument;

    if(!doc)

        return;

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

        var cLayer = doc.layers[lIndex];

        for(var i=0; i< cLayer.textFrames.length; i++){

            var tFr = cLayer.textFrames;

            if(tFr.contents == targetCode){

                var x = tFr.left+tFr.width; // drop X

                var y = tFr.top-tFr.height; // drop Y

                tFr.remove();

                 // DO SOMETHING

                return;

            }

        }

    }

}

The function replaceColorString() finds our TextFrame and remove it. But we are able to add sovething to our document insted of the TextFrame.

The Git Example shows how you can drag Colors, JPG, SVG, PNG, AI, EPS like layers.

All source is published to Git.

Best regards,

Sergey.

Views

1.7K

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 ,
Jul 23, 2018 Jul 23, 2018

Copy link to clipboard

Copied

Hi !!

This is not working for INDesign.

Could you please let me know what should i do to make it work for InDesign.

Thanks

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 ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

Bumped and moved to the exchange forum

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 ,
Jul 22, 2020 Jul 22, 2020

Copy link to clipboard

Copied

LATEST

I am implementing your example but in my extendedscript it can find the image that i am dragging

 

What means {color:4000001}? I a using {color:1} insteand but i am not sure why {color:4000001}

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