• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Issue modify symbol in a document using scripting

Contributor ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

 

I need to modify a symbol in a document. Due to limitations in the DOM, I'm trying a workaround by putting it on a new layer, and trying the modify it. Then I would like to add it again as a new symbol.

 

But when breaking the symbol, the layer.pageItems array is empty. So I'm not able to loop the list of items.

How do i fix this?

 

var doc = app.activeDocument;

var tempLayer = doc.layers.add();
tempLayer.name = "TEMP";

var badSymbol = doc.symbols.getByName("BAD");
var badSymbolItem = tempLayer.symbolItems.add(badSymbol);

// Making it a regular page/layer object
badSymbolItem.breakLink();

app.redraw();

for ( var j = 0; j < tempLayer.pageItems.length; j++ ) {
    // EMPTY ?
};

// Add content of a layer as new Symbol in the document


tempLayer.remove();

 

 

 

 

 

TOPICS
Scripting

Views

284

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 , Dec 14, 2022 Dec 14, 2022

Hi,

When you break link, the sublayers with the name of the symbol is created. So your TEMP layer will not have pagesItems, instead TEMP layer will have a sublayer with name 'BAD' and this BAD layer will have access to the pageItems. 

var doc = app.activeDocument;

var tempLayer = doc.layers.add();
tempLayer.name = "TEMP";

var badSymbol = doc.symbols.getByName("BAD");
var badSymbolItem = tempLayer.symbolItems.add(badSymbol);

// Making it a regular page/layer object
badSymbolItem.breakLink();

...

Votes

Translate

Translate
Adobe
Guide ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

What you seem to get when you break the link is items within a layer within tempLayer.  I.e.

tempLayer.layers[0].pageItems

 

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
Contributor ,
Dec 21, 2022 Dec 21, 2022

Copy link to clipboard

Copied

LATEST

Thank you Femke ... This was very useful  ...

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 ,
Dec 14, 2022 Dec 14, 2022

Copy link to clipboard

Copied

Hi,

When you break link, the sublayers with the name of the symbol is created. So your TEMP layer will not have pagesItems, instead TEMP layer will have a sublayer with name 'BAD' and this BAD layer will have access to the pageItems. 

var doc = app.activeDocument;

var tempLayer = doc.layers.add();
tempLayer.name = "TEMP";

var badSymbol = doc.symbols.getByName("BAD");
var badSymbolItem = tempLayer.symbolItems.add(badSymbol);

// Making it a regular page/layer object
badSymbolItem.breakLink();

app.redraw();
var _badLayer = tempLayer.layers['BAD'];
alert(_badLayer.pageItems.length);

for (var j = 0; j < _badLayer.pageItems.length; j++) {
  // EMPTY ?
};

// Add content of a layer as new Symbol in the document


tempLayer.remove();

 

Best 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