Skip to main content
Participant
November 26, 2023
Question

illustrator javascript code for selecting elements at specific area

  • November 26, 2023
  • 2 replies
  • 467 views

Hello guys,

 

is there a simple way how to select all the elements at specific area? Lets say, I need to select everything in rectangle 0,0 to 200,200? Only option I have got so far is to make a rectangle and go through all the objects and select all that intersects. This works, but I need to perform this several times in different areas and I have a lot of objects on the artboard, which make it pretty slow approach? Moreover, is there any way how to select guidelines as well? Previously mentioned approach doesnt work.

 

thanks for any answer

This topic has been closed for replies.

2 replies

Participant
December 22, 2023

Thanks guys, this works beautifully!

Legend
November 27, 2023

How about a flow that creates a temporary artboard in the specified region and selectObjectsOnActiveArtboard to select the contents?

 

/**
  * @￰file select page items in the specified bounds using selectObjectsOnActiveArtboard
  * @￰version 1.0.0
  * @￰author sttk3.com
*/

(function() {
  selectRegion(app.documents[0], [0, 0, 200, -200]) ;
})() ;

/**
  * select page items in the specified bounds
  * @￰param {Document} doc target document
  * @￰param {[number, number, number, number]} bounds left, top, right, bottom
  * @￰returns {Array<PageItem>} new selection
*/
function selectRegion(doc, bounds) {
  var res = [] ;
  var tempArtboard ;
  try {
    tempArtboard = doc.artboards.add(bounds) ;
    doc.selectObjectsOnActiveArtboard() ;
    res = doc.selection ;
  } finally {
    if(tempArtboard) {tempArtboard.remove() ;}
  }
  return res ;
}

 

 

 

femkeblanco
Legend
November 27, 2023

Pretty smart.