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

copying appearance from text frame to another in scripting

Explorer ,
May 13, 2021 May 13, 2021

Copy link to clipboard

Copied

guys I search for this all day and I can't find how to copy appearance from a text frame or any other object into another i know how to apply effects by XML but idk how to copy thise effects  

TOPICS
Scripting

Views

1.6K

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 2 Correct answers

Community Expert , May 17, 2021 May 17, 2021

Solution 1

 

Use "app.executeMenuCommand" to generate a graphic style for the source item, and apply that style to the destination item.

 

This script will duplicate the appearance of the front item of the two selected items to the back item.

(function() {
  if(app.documents.length <= 0) {return ;}
  var doc = app.documents[0] ;
  var sel = doc.selection ;
  if(sel.length != 2) {return ;}
  
  var tempGraphicStyle = addGraphicStyle(doc, sel[0]) ;
  tempGraphicStyle.applyTo(sel[1], true) ;
  tempGraph
...

Votes

Translate

Translate
Community Expert , May 17, 2021 May 17, 2021

Solution 2

 

Use the third party plugin "OnegaiSDK". This allows control of the appearance through scripting.

 

The behavior of this script is the same as in Solution 1.

(function() {
  if(app.documents.length <= 0) {return ;}
  var doc = app.documents[0] ;
  var sel = doc.selection ;
  if(sel.length != 2) {return ;}
  
  var pluginName = 'OnegaiSDK' ;
  sel[0].sendScriptMessage(pluginName, 'copyStyle', '') ;
  sel[1].sendScriptMessage(pluginName, 'pasteStyle', '') ;
})() ;

 

Votes

Translate

Translate
Adobe
Guide ,
May 13, 2021 May 13, 2021

Copy link to clipboard

Copied

You can use a graphic style, which includes fill, stroke, effects and transparency. You will need to create a graphic style manually (see here).  Once you have a named graphic style (e.g "Custom Graphic Style"), you can apply it to text frames. This applies it to a selected text frame:

 

app.activeDocument.graphicStyles["Custom Graphic Style"].applyTo(app.activeDocument.selection[0]);

 

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 ,
May 13, 2021 May 13, 2021

Copy link to clipboard

Copied

thanks man 🙂 i know this one , but how i can copy any object appearance to another without making it graphic style ? 

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
Guide ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

Fill and stroke are easy enough to "copy".  But copying effects requires access to live effect XML on the fly.  Is that possible?  I would guess probably not, but I am happy to be proven wrong.  

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 ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

i don't realy have an answer to this 😞 but I search alot for this but it's seems you can just apply effects through xml but not copy it and 'scripts don't have the ability to view more complex appearances like pattern fills' as @Disposition_Dev  say , regards

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 ,
May 13, 2021 May 13, 2021

Copy link to clipboard

Copied

Dont know much about XML to apply effects, but you can double click the eyedropper change default OFF to ON for to pick up and apply appearance.

MikeGondek_0-1620938953278.png

Sounds really interesting what you are working on, love when people use appearance.

 

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 ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

Thank you so much, I appreciate this But i wont it by scripting ❤ do you know how i reach eyedropper in scripting 

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 ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

each textFrame has a property called textRange which has a property called characterAttributes.

 

characterAttributes is an object that contains all of the properties that define the appearance of the text. If you copy those values from one textFrame to another, it should work pretty well. HOWEVER... scripts don't have the ability to view more complex appearances like pattern fills, stacked appearances with multiple fills/strokes/effects, etc. But for simple copying of font, font size, tracking, kerning, character height, etc etc, this function seems to do ok:

#target Illustrator
function applyAppearance(srcItem,destItem)
{
	for(var x in srcItem.textRange.characterAttributes)
	{
		destItem.textRange.characterAttributes[x] = srcItem.textRange.characterAttributes[x];
	} 	
}

applyAppearance(app.activeDocument.textFrames["src"],app.activeDocument.textFrames["dest"]);

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 ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

You are a legend man, using this with the expand appearance menu command i think its going to be great but its seems it work with every thing expect gradient , any thougts how i can copy gradient from text frame to another , and thnk you soo much 

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 ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

for gradients... i suggest using a graphic style and dispensing with the logic i posted above.. lol

 

It's possible to create a graphic style on the fly and then apply that graphic style to any items you want, all from a script. So if you're just worried about not wanting to manually create graphic styles so that you can apply them via script, i got you covered.

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
Guide ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

Hi@Disposition_Dev.  How can you create a graphic style with a script?  The documentation explicitly states that:  "Scripts cannot create new graphic styles." 

 

https://ai-scripting.docsforadobe.dev/jsobjref/GraphicStyle/ 

 

 

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 ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

Select item that has the appearance you want. Run action that creates a graphic style from current selection, then rename the new graphic style with:

 

var gs = app.activeDocument.graphicStyles;

gs[gs.length - 1].name = "new name";

 

I've been meaning to add this logic to my public illustrator scripts on github. I'll try to get that done this weekend. 

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
Guide ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

Ahh. Cheating with actions.  But seriously, thanks for the tip.

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 ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

instead of copying the appearance from A to B, why don't you duplicate A and change it's contents to B? wouldn't that work similarly?

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 ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

That's a great point Carlos. Nothing immediately comes to mind that would break that.. 

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 ,
May 14, 2021 May 14, 2021

Copy link to clipboard

Copied

right? unless we're missing something it should work

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 ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

Solution 1

 

Use "app.executeMenuCommand" to generate a graphic style for the source item, and apply that style to the destination item.

 

This script will duplicate the appearance of the front item of the two selected items to the back item.

(function() {
  if(app.documents.length <= 0) {return ;}
  var doc = app.documents[0] ;
  var sel = doc.selection ;
  if(sel.length != 2) {return ;}
  
  var tempGraphicStyle = addGraphicStyle(doc, sel[0]) ;
  tempGraphicStyle.applyTo(sel[1], true) ;
  tempGraphicStyle.remove() ;

  doc.selection = sel ;
})() ;

/**
  * create a new graphic style based on the target item and return it
  * @Param {Document} doc target document
  * @Param {PageItem} targetItem target item
  * @Return {GraphicStyle}
*/
function addGraphicStyle(doc, targetItem) {
  var res ;
  try {
    // suppress dialog
    var oldLevel = app.userInteractionLevel ;
    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS ;

    // select only the target item and execute 'Adobe New Style Shortcut'
    doc.selection = [targetItem] ;
    app.executeMenuCommand('Adobe New Style Shortcut') ;

    // return the last graphic style
    res = doc.graphicStyles[doc.graphicStyles.length - 1] ;
  } catch(e) {
    alert(e) ;
  } finally {
    app.userInteractionLevel = oldLevel ;
  }
  return res ;
}

 

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 ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

LATEST

Solution 2

 

Use the third party plugin "OnegaiSDK". This allows control of the appearance through scripting.

 

The behavior of this script is the same as in Solution 1.

(function() {
  if(app.documents.length <= 0) {return ;}
  var doc = app.documents[0] ;
  var sel = doc.selection ;
  if(sel.length != 2) {return ;}
  
  var pluginName = 'OnegaiSDK' ;
  sel[0].sendScriptMessage(pluginName, 'copyStyle', '') ;
  sel[1].sendScriptMessage(pluginName, 'pasteStyle', '') ;
})() ;

 

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