I show you the Bug that I detected If you try the code on a clipmask in which the content is greater than the mask you can verify that the code is malfunctioning. function getMaxCollectionBnds(collection, boundsType) { var bndsType = boundsType || 'geometricBounds'; var bounds = _getMaxBnds(collection, []); return bounds; function _getMaxBnds(collection, bounds) { var bnds = bounds; // case then passed one item rather then true collection try { var oneElemBnds = collection[boundsType]; if (oneElemBnds[0]) { return oneElemBnds; } } catch (e) { } for (var j = 0; j < collection.length; j++) { var el = collection ; // anything PageItem exclude GroupItem if (el.typename != 'GroupItem') { if (bnds == '') { bnds = _getElemBnds(el); continue; } bnds = _cmprBnds(el, bnds); } // group contains a mask -> search this mask if (el.typename == 'GroupItem' && el.clipped) { var groupPaths = el.pathItems; for (var i = 0; i < groupPaths.length; i++) { if (groupPaths.clipping) { if (bnds == '') { bnds = _getElemBnds(groupPaths); continue; } bnds = _cmprBnds(groupPaths, bnds); } } } // group contains no a mask and a groups if (el.typename == 'GroupItem' && !el.clipped && !el.groupItems) { if (bnds == '') { bnds = _getElemBnds(el); continue; } bnds = _cmprBnds(el[bndsType], bnds); } // group contains no a mask, but contains a groups -> recurse if (el.typename == 'GroupItem' && !el.clipped && el.groupItems) { bnds = _getMaxBnds(el.pageItems, bnds); continue; } } return bnds; } function _cmprBnds(elem, bndsToCompare) { var elemBnds = _getElemBnds(elem); return [ Math.min(elemBnds[0], bndsToCompare[0]), Math.max(elemBnds[1], bndsToCompare[1]), Math.max(elemBnds[2], bndsToCompare[2]), Math.min(elemBnds[3], bndsToCompare[3]) ] } function _getElemBnds(elem) { var elemBnds; if (elem.typename == 'TextFrame') { var elemCurvedCopy = elem.duplicate().createOutline(); elemBnds = elemCurvedCopy[bndsType]; elemCurvedCopy.remove(); } else { elemBnds = elem[bndsType]; } return elemBnds; } } var doc = app.activeDocument; sel = activeDocument.selection; for (var s = 0; s < sel.length; s++) { IntersectArtboardIndx = [] obj = sel Bounds=getMaxCollectionBnds(obj, 'visibleBounds') var rect = doc.pathItems.rectangle(Bounds[1], Bounds[0], (Bounds[2] - Bounds[0]), (Bounds[1] - Bounds[3])); } If we change this line: [obj] instead of obj Bounds = getMaxCollectionBnds ([obj], 'visibleBounds') The code seems to work correctly. Could you please help me correct it? Thank you very much in advance Regards
... View more