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();
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();
...
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
Copy link to clipboard
Copied
Thank you Femke ... This was very useful ...
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();