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

insert formated text from clipboard after a specific character

New Here ,
Mar 14, 2018 Mar 14, 2018

Good day,

Is it possible to insert content of clipboard after a specific character with a script?

For example, I have a piece of specifically formatted text, which I need to insert after every "-"-sign in every text block of a document.

I imagine, first the cursor should be moved to the position after hyphen-sign and then the script should fire the command Paste.

Can somebody help me with code?

TOPICS
Scripting
1.2K
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
Adobe
Valorous Hero ,
Mar 14, 2018 Mar 14, 2018

Can you elaborate on what you mean by 'specifically formatted' ?

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
New Here ,
Mar 15, 2018 Mar 15, 2018

For example, a chemical formula with digits in subscipt, C12H22O11, or a piece of text with some characters in bold some in italic.

Classical Find/replace/regex scripts just replace characters and do not count on the formatting.

It seems, the simplest option to keep formatting is to paste already formatted text from the clipboard.

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
Valorous Hero ,
Mar 15, 2018 Mar 15, 2018

I was going to suggest looking here:

Re: RegExp search and replace, keep original text formatting

However, you may actually be looking to replace a string with text that may have multiple style ranges within the same text-match?

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
New Here ,
Mar 15, 2018 Mar 15, 2018

Well, maybe you are right. If you want, I need to replace text "-" by "- C12H22O11", with all digits subsript.

In my opinion, the algorithm is pretty simple.

The script should move the cursor to the correct position within text string and execute something like app.executeMenuCommand('paste').

My problem is that I have no idea how to move the cursor to the right position and whether it is possible at all.

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
Valorous Hero ,
Mar 15, 2018 Mar 15, 2018

Can you post a screenshot of what this looks like? Pasting may be okay, and cursor stuff is handled by selecting the text range matching the '-' character, and pasting would not be necessary because at that point you just set the contents of the text range to your word, it should take on the styling originally applied to the '-'.  So the thread I pointed out may work anyway.

But it may not work if your 'copied' item is something looking like this: C12H22O11

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
Advocate ,
Mar 15, 2018 Mar 15, 2018

Bonjour,

Il faut utiliser : textRf.insertionPoints[index];

caractère par caractère...

formule2.PNG

Ici je remplace des par H2S04 formaté size font color

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
New Here ,
Mar 16, 2018 Mar 16, 2018

to Silly-V​:

For example:

to renél80416020​:

Many thanks for the suggestion.

What is under the textRf? Text reference?

Could you please show the final code to insert the content of the clipboard to the position after every hyphen-sign?

I am not so much experienced in js coding to regret.

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
Advocate ,
Mar 16, 2018 Mar 16, 2018

Bonjour,

Je n'utilise pas (copy\paste) mais un text placé au premier plan reconnu par le symbole @.

ce text peut comporter plusieurs lignes pour des remplacements successifs.

Remplacer le chien par le loup

   Comme :

    @le chien:le loup

    la vache:la chêvre
    ....

- J'ai simplement ajouté pour l'occasion 5 lignes à un script existant
que je fourni à des clients, ce qui explique [i+4], ces lignes
commencent par curentChar .

Ce script peut remplacer des groupes de mots par d'autres groupes en
conservant le style du texte d'origine pour tous les documents ouverts.

Je donne juste le principe :

index = textRf.contents.search(RegExp(rx,drap));

    if (index != -1) {

        fg = new RegExp(rx).exec(textRf.contents);

          ip = textRf.insertionPoints[index];

        for(i = 0; i < ch.length; i++) {

          ip = textRf.insertionPoints[index];

          ip.characters.add(ch.charAt(i));

          curentChar = textRf.characters[index];

          curentChar.textFont = text.characters[i+4].textFont;

          curentChar.size = text.characters[i+4].size;

          curentChar.fillColor =  text.characters[i+4].fillColor;

          curentChar.baselineShift = text.characters[i+4].baselineShift;

          index++;

        }

formule4.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
New Here ,
Mar 16, 2018 Mar 16, 2018

renél80416020, many thanks for the answer.

But for me your snippet of a little use because I cannot transform it into the final code.

Would you or somebody else be so kind to help with the transforming into the working script?

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
Advocate ,
Mar 16, 2018 Mar 16, 2018
LATEST

Sylvio,

Je veux bien t'aider mais il faut me faire parvenir un document .ai avant et après transformation,

avec les explications utiles par mail. (voir Photo)

Pour travailler en situation réelle.

A+

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