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

Ajout d'image automatique dans tableau

Explorer ,
Feb 21, 2024 Feb 21, 2024

Bonjour à tous,

Je rencontre une problématique et je ne sais pas comment faire.

J'ai un tableau de 1000 lignes et dans chaque ligne je dois intégrer une ou plusieurs images (il s'agit de produits chimqiues et ce sont les images de pictogramme de sécuirté), les images varient en fonction du produit donc est différent par ligne. Existe t'il une possibilité pour que par exemple je mette des numéros associés à chaque image, que j'intègre les numéros dans mon tableau et que ca me charge automtiquement les images correspondantes ?

Merci d'avance pour vos retour.

TOPICS
Sync and storage
2.0K
Translate
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

Participant , Feb 22, 2024 Feb 22, 2024

The following script will replace each file name with an anchored image. Before running it, you will need to:

  1. Add the image names into your table cells. (Separate your file names with a space, or multiple spaces if you want to space out your images more.)
    danaken3_5-1708635860171.png

     

  2. Create a paragraph style called "Picto" and apply it to the text you want to replace. (Make sure the paragraph style has center alignment — other than that, it doesn't really matter what the style looks like, just as long as you have it applied
...
Translate
Participant ,
Feb 22, 2024 Feb 22, 2024

Would it be easy to add the file names of the images directly into the cell where you want the image(s) to go? Previously I've written a script that could then replace the text with images -- in that case it was in a frame rather than a table, but I think I can adjust my script to work with tables. Can you share a sample screenshot that shows what you want your table to look like?

Translate
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 ,
Feb 22, 2024 Feb 22, 2024

Thanks for your answer, please inf join a table. Today, I paste each pictogram on the line, but when I have to move or add a line, the pictograms doesn't move, so it's a long work and I have to re-do the list every 6 months.

 

That woul be awesome if you have a solution.

Translate
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
Participant ,
Feb 22, 2024 Feb 22, 2024

I think the best long-term solution may be to turn those icons into anchored objects. That way, they will adjust automatically when you insert, remove, or resize lines. 

  1.  In your column with the icons, make sure that the text alignment is centered (even though there will be no text, this will make the anchored objects centered).
  2. Create a cell style for these cells (or update the Table > Cell Options). Under Text, select the appropriate Vertical Justification (top, center, etc.) and adjust the cell insets as needed.
  3.  Create an object style for your icons, with the following options selected:
    Anchored Object Options > Position > Inline.  (Leave Y Offset at 0.) Optionally, you may also select "Prevent Manual Positioning," if you don't want to accidentally move your icons out of place.
    danaken3_0-1708594136450.png

     

    —(Optional) Size and Position Options > Size > Adjust: Height & Width (enter your desired dimensions). This may help if you want to make sure all your icons are the same size.
    —(Optional) Frame fitting options > Fitting > Fit Content Proportionally
  4.  Place your icon somewhere on the page (in a separate graphic frame, not in the table itself). Apply the object style you created earlier. When you select the frame, you will see a blue square at top right. To anchor this icon, drag that blue square into the desired cell.
    danaken3_2-1708594725874.png

    If you selected the options as outlined above, the icon should slide into the correct position (but let me know if it is not working for you). You should also be able to drag multiple icons into the same cell.

I will still try to figure out a script to help with your initial import of all the icons, but doing the above steps should make it easier to update your file later on. 

Translate
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
Participant ,
Feb 22, 2024 Feb 22, 2024

The following script will replace each file name with an anchored image. Before running it, you will need to:

  1. Add the image names into your table cells. (Separate your file names with a space, or multiple spaces if you want to space out your images more.)
    danaken3_5-1708635860171.png

     

  2. Create a paragraph style called "Picto" and apply it to the text you want to replace. (Make sure the paragraph style has center alignment — other than that, it doesn't really matter what the style looks like, just as long as you have it applied to the text so the script knows which text to target).
  3. Create an object style of the same name ("Picto") — use the information in my previous reply to configure that object style.

 

If you are not familiar with installing and running scripts, see this help article.

 

The script works as follows:

  1. It prompts you to select the folder where your images are saved (it will not search through subfolders).
    danaken3_4-1708635778878.png

     

  2. Then it searches for any text with the paragraph style "Picto" applied.
    danaken3_1-1708634682890.png

  3. Then it replaces the text with an anchored object, with the object style "Picto" applied. (Note there is a typed space between each image.)
    danaken3_2-1708634709835.png
  4. If a file cannot be found, an empty frame is inserted and the text will remain. 

 

Let me know if you encounter any issues or need additional guidance!

 

 

 

app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){
var myDoc = app.activeDocument;
var myFolder = Folder.selectDialog("Select folder to search");

app.findGrepPreferences= NothingEnum.nothing;  
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item("Picto");  
app.findGrepPreferences.findWhat ='\\<(\\w|-)+(\\.)(psd|png|jpg|jpeg|svg|tif|tiff)';  
//edited to add "psd"
var foundTexts = myDoc.findGrep();
var myObjStyle = app.activeDocument.objectStyles.item("Picto");

var i = foundTexts.length;
while (i--) {
    try {
        var ip = foundTexts[i].insertionPoints[0].index;
        var anchoredFrame = foundTexts[i].parent.insertionPoints[ip].rectangles.add();
        anchoredFrame.applyObjectStyle(myObjStyle, true);

        if(File(myFolder + "//" + foundTexts[i].contents).exists) {
            anchoredFrame.place(File(myFolder + "//" + foundTexts[i].contents));
            foundTexts[i].remove();
        }
    }
    catch(err) {
    }
}
app.findGrepPreferences= NothingEnum.nothing;
}

 

 

 

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Thank you very much, I've tried it but it doesn't work. II have the block that appears, but it's empty and the text still appears (see the sreenshot). I think i've missed something but can't found what 🙂

I have another question : Does the image has to be in .png only or does it works with .psd image if I add |psd?

Sorry it's the first time for me.

 

Please find the different step that i made and if you have time could you please tell me what i could have done wrong. Thank you

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

@daphné je ne suis pas du tout un scripteur, mais je crois comprendre le problème : d'après ce que je vois, le script qui t'a été fourni ne fait pas appel à un style de cellule alors que tu en utilises un dans ton tableau. Mais je suis peut-être complètement à côté de la plaque…

En ce qui concerne ta question sur les PSD, je pense que ça devrait fonctionner si tu ajoutes |psd

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Merci pour le retour, oui j'avoue que je ne suis pas dutout experte dans les script, je vais voir et merci pour le psd, je pensais bien aussi 🙂

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

J'ai testé le script de @danaken3 sur un tableau simple que je viens de créer et ça fonctionne parfaitement.

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Je ne comprends pas du coup, j'ai du loupé une étape.

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Je viens de le refaire avec un style de cellule, rangé dans un groupe, comme toi et ça fonctionne encore. Tu es certaine que le nom indiqué dans la cellule est rigoureusement celui du picto à placer ? Tu as bien suivi les instructions de @danaken3 ? (appliquer le style de paragraphe au texte de remplacement)

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Oui c'est bien pour ça que je ne comprends pas.

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

J'ai retesté, j'ai ce mesage d'erreur qui s'affiche à présent .. je suis perdue la.

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Et la première fois, tu n'avais pas ce message ? Tu as modifié quelque chose dans le script ?

Je vois aussi que tu as indiqué le chemin de ton dossier sur la ligne « var myFolder = Folder.selectDialog ». Ça ne sert à rien, ça sert juste à changer le message qui apparaît en haut de la fenêtre qui te permet de sélectionner le dossier dans lequel se trouvent les images. Ceci dit, je pense que ce n'est pas l'origine du problème.

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Non, je ne comprends plus rien 🙂

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Je vois sur ta capture d'écran que ton fichier est en lecture seule…

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Tu peux joindre le script, que je l'essaie ?

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

le voici

 

app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
function Main(){
var myDoc = app.activeDocument;
var myFolder = Folder.selectDialog("C:\Users\daphné\Desktop\PICTO");

app.findGrepPreferences= NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item("Picto");
app.findGrepPreferences.findWhat ='\\<(\\w|-)+(\\.)(png|jpg|jpeg|svg|tif|tiff)';
var foundTexts = myDoc.findGrep();
var myObjStyle = app.activeDocument.objectStyles.item("Picto");

var i = foundTexts.length;
while (i--) {
try {
var ip = foundTexts[i].insertionPoints[0].index;
var anchoredFrame = foundTexts[i].parent.insertionPoints[ip].rectangles.add();
anchoredFrame.applyObjectStyle(myObjStyle, true);

if(File(myFolder + "//" + foundTexts[i].contents).exists) {
anchoredFrame.place(File(myFolder + "//" + foundTexts[i].contents));
foundTexts[i].remove();
}
}
catch(err) {
}
}
app.findGrepPreferences= NothingEnum.nothing;
}

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Non, envoie-moi le fichier qui est stocké sur ton ordinateur, celui que tu as appelé « produits-chimiques.jsx »

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

il n'accepte pas les fichiers .jsx

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

J'ai copié collé le texte du script que tu as posté, ça marche sur mon Mac.

Ça veut donc dire que c'est le fichier InDesign qui coince : soit parce que le style d'objet ou le style de paragraphe « Picto » (ou les 2) n'est pas paramétré comme il faut.

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Bon ba la je ne sais pas ....

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Tu peux m'envoyer un extrait du fichier InDesign que tu utilises, avec le style d'objet et le style de paragraphe ?

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

comment faire ? 

Translate
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 ,
Feb 23, 2024 Feb 23, 2024

Quand tu réponds, tu dois voir ça en bas de la fenêtre de rédaction du message ? Sinon, tu m'envoies un lien wetransfer ou dropbox ou équivalent.

Capture d’écran 2024-02-23 à 16.38.09.png

Translate
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