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

Issue modify symbol in a document using scripting

Contributor ,
Dec 14, 2022 Dec 14, 2022

 

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
477
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

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();

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

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

tempLayer.layers[0].pageItems

 

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

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

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 ,
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();

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
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