Script SelectObject.

Community Beginner ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

Right now the built in script SelectObject lets you choose what you want to select on the active spread.
The only issue right now with the script is that it also select chosen objects on EVERY layer, locked or not, visible or not.

What I'd like and need is for that script to do what it does but only on the active spread AND active layer.

Anyone that could help me with that?

TOPICS
Feature request , How to , Performance , Scripting

Views

113

Likes

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

Adobe Community Professional , Jan 27, 2022 Jan 27, 2022
Hi @Mitchell5E84 , See if this works—the code edit is on lines 102-104 & 125-127: //SelectObjects.jsx //An InDesign JavaScript /* @@@BUILDINFO@@@ "SelectObjects.jsx" 3.0.0 15 December 2009 */ //This script selects all objects of a given type or types on the active spread. //When you choose one of the imported graphic types, the script will select //the frame containing the graphic (and not the graphic itself). // //For more on InDesign/InCopy scripting see the documentation included in the...

Likes

Translate

Translate
Adobe Community Professional ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

Hi Mitchell5E84,

check every item that is addressed if:

itemLayer == app.documents[0].activeLayer

if false, do not select it.

 

If you want to post process the selection, do:

var doc = app.documents[0];
var sel = app.selection;
var remainingItems = [];

for( var n=0; n<sel.length; n++ )
{
	if( sel[n].itemLayer == doc.activeLayer )
	{
		remainingItems[remainingItems.length++] = sel[n] ;
	};
};

if( remainingItems.length > 0 )
{
	doc.select( remainingItems );
};
else
{
	doc.select( null );
}

 

Regards,
Uwe Laubender

( ACP )

 

Likes

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 Beginner ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

Okay so I'm not at all a scripter.

This is the original code:

main();
function main(){
	//Make certain that user interaction (display of dialogs, etc.) is turned on.
	app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
	if (app.documents.length != 0){
		if (app.activeWindow.activeSpread.pageItems.length != 0){
			myDisplayDialog();
		}
		else {
			alert("The active spread does not contain any page items.");
		}
	}
	else{
		alert("No documents are open. Please open a document and try again.");
	}
}
function myDisplayDialog(){
	var myDialog;
	//Create the SelectTEXT dialog box.
	with(myDialog = app.dialogs.add({name:"SelectTEXT"})){
		with(dialogColumns.add()){
			with(borderPanels.add()){
				staticTexts.add({staticLabel:"Select:"});
				with(dialogColumns.add()){					
					var myTextFramesCheckbox = checkboxControls.add({staticLabel:"&Text Frames", checkedState:true});
				}
			}
		}
	}
	myResult = myDialog.show();
	if (myResult == true){
		var myObjectTypes = new Array;
		//Gather control settings from the dialog box and build
		//an array containing the object types to select.
		if(myTextFramesCheckbox.checkedState==true){
			myObjectTypes.push("textFrames");
		}

		//Remove the dialog from memory.
		myDialog.destroy();
		mySelectTEXT(myObjectTypes);
	}
	else{
		//Remove the dialog from memory.
		myDialog.destroy();
	}
}
function mySelectTEXT(myObjectTypes){
	var myCounter;
	var myObjectsToSelect = new Array;
	with(app.activeWindow.activeSpread){
		for(myCounter = 0; myCounter < myObjectTypes.length; myCounter++){
			if((myObjectTypes[myCounter] != "images")&&(myObjectTypes[myCounter] != "epss")&&(myObjectTypes[myCounter] != "pdfs")){
				myPageItems = eval(myObjectTypes[myCounter]);
				if (myPageItems.length != 0){
					for(myPageItemCounter = 0; myPageItemCounter < myPageItems.length; myPageItemCounter ++){
						myObjectsToSelect.push(myPageItems[myPageItemCounter]);
					}
				}
			}
		}
		for(myCounter = 0; myCounter < pageItems.length; myCounter++){
			myPageItem = pageItems.item(myCounter);
			try{
				if(((myIsInArray("images", myObjectTypes) == true) && (myPageItem.images.length == 1))||
				((myIsInArray("epss", myObjectTypes) == true) && (myPageItem.epss.length == 1))||
				((myIsInArray("pdfs", myObjectTypes) == true) && (myPageItem.pdfs.length == 1))){
					//Is the page item already in the list of items to select?
					myID = myPageItem.id;
					myAlreadyAdded = false;
					for(myPageItemCounter = 0; myPageItemCounter<myObjectsToSelect.length; myPageItemCounter++){
						if(myObjectsToSelect[myPageItemCounter].id == myID){
							myAlreadyAdded = true;
							break;
						}
					}
					//If the page item was not already in the list of items to select, add it to the list.
					if (myAlreadyAdded == false){
						myObjectsToSelect.push(myPageItem);
					}
				}
			}
			catch(myError){
			}
		}
		parent.select(myObjectsToSelect, SelectionOptions.replaceWith);
	}
}
function myIsInArray(myString, myArray){
	var myResult = false;
	for (myCounter = 0; myCounter < myArray.length; myCounter ++){
		if (myArray[myCounter] == myString){
			myResult = true;
			break;
		}
	}	
	return myResult;
}

Where in the original script would I put your code?

Likes

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
Adobe Community Professional ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

"Where in the original script would I put your code?"

 

Just run my script code on the selection that the first script does.

 

Regards,
Uwe Laubender

( ACP )

Likes

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 Beginner ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

So I'd have to turn your code into a script and then first run the Original built in script and then yours.

Is that what you mean to say?

Likes

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
Adobe Community Professional ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

Exactly.

 

Regards,
Uwe Laubender

( ACP )

Likes

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 Beginner ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

I'll see if I can accompish that, though it would be easier if the original script could be editted with a line that would instantly do the same instead of having to use two seperate scripts.

Likes

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
Adobe Community Professional ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

Hi @Mitchell5E84 , See if this works—the code edit is on lines 102-104 & 125-127:

 

 

//SelectObjects.jsx
//An InDesign JavaScript
/*  
@@@BUILDINFO@@@ "SelectObjects.jsx" 3.0.0 15 December 2009
*/
//This script selects all objects of a given type or types on the active spread.
//When you choose one of the imported graphic types, the script will select
//the frame containing the graphic (and not the graphic itself).
//
//For more on InDesign/InCopy scripting see the documentation included in the Scripting SDK 
//available at http://www.adobe.com/devnet/indesign/sdk.html
//or visit the InDesign Scripting User to User forum at http://www.adobeforums.com
//
main();
function main(){
	//Make certain that user interaction (display of dialogs, etc.) is turned on.
	app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
	if (app.documents.length != 0){
		if (app.activeWindow.activeSpread.pageItems.length != 0){
			myDisplayDialog();
		}
		else {
			alert("The active spread does not contain any page items.");
		}
	}
	else{
		alert("No documents are open. Please open a document and try again.");
	}
}
function myDisplayDialog(){
	var myDialog;
	//Create the SelectObjects dialog box.
	with(myDialog = app.dialogs.add({name:"SelectObjects"})){
		with(dialogColumns.add()){
			with(borderPanels.add()){
				staticTexts.add({staticLabel:"Select:"});
				with(dialogColumns.add()){					
					var myRectanglesCheckbox = checkboxControls.add({staticLabel:"&Rectangles", checkedState:true});
					var myEllipsesCheckbox = checkboxControls.add({staticLabel:"&Ellipses", checkedState:true});
					var myPolygonsCheckbox = checkboxControls.add({staticLabel:"&Polygons", checkedState:true});
					var myGraphicLinesCheckbox = checkboxControls.add({staticLabel:"&Graphic Lines", checkedState:true});
					var myTextFramesCheckbox = checkboxControls.add({staticLabel:"&Text Frames", checkedState:true});
					var myGroupsCheckbox = checkboxControls.add({staticLabel:"G&roups", checkedState:true});
					var myImagesCheckbox = checkboxControls.add({staticLabel:"&Images", checkedState:true});
					var myPDFsCheckbox = checkboxControls.add({staticLabel:"P&DFs", checkedState:true});
					var myEPSsCheckbox = checkboxControls.add({staticLabel:"EP&Ss", checkedState:true});
				}
			}
		}
	}
	myResult = myDialog.show();
	if (myResult == true){
		var myObjectTypes = new Array;
		//Gather control settings from the dialog box and build
		//an array containing the object types to select.
		if (myRectanglesCheckbox.checkedState ==  true){
			myObjectTypes.push("rectangles");
		}
		if(myEllipsesCheckbox.checkedState==true){
			myObjectTypes.push("ovals");
		}
		if(myPolygonsCheckbox.checkedState==true){
			myObjectTypes.push("polygons");
		}
		if(myGraphicLinesCheckbox.checkedState==true){
			myObjectTypes.push("graphicLines");
		}
		if(myTextFramesCheckbox.checkedState==true){
			myObjectTypes.push("textFrames");
		}
		if(myGroupsCheckbox.checkedState==true){
			myObjectTypes.push("groups");
		}
		if(myImagesCheckbox.checkedState==true){
			myObjectTypes.push("images");
		}
		if(myPDFsCheckbox.checkedState==true){
			myObjectTypes.push("pdfs");
		}
		if(myEPSsCheckbox.checkedState==true){
			myObjectTypes.push("epss");
		}
		//Remove the dialog from memory.
		myDialog.destroy();
		mySelectObjects(myObjectTypes);
	}
	else{
		//Remove the dialog from memory.
		myDialog.destroy();
	}
}
function mySelectObjects(myObjectTypes){
	var myCounter;
    var iLayer = app.activeDocument.activeLayer;
	var myObjectsToSelect = new Array;
	with(app.activeWindow.activeSpread){
		for(myCounter = 0; myCounter < myObjectTypes.length; myCounter++){
			if((myObjectTypes[myCounter] != "images")&&(myObjectTypes[myCounter] != "epss")&&(myObjectTypes[myCounter] != "pdfs")){
				myPageItems = eval(myObjectTypes[myCounter]);
				if (myPageItems.length != 0){
					for(myPageItemCounter = 0; myPageItemCounter < myPageItems.length; myPageItemCounter ++){
						if( myPageItems[myPageItemCounter].itemLayer == iLayer ){
		                    myObjectsToSelect.push(myPageItems[myPageItemCounter]);
	                    };
					}
				}
			}
		}
		for(myCounter = 0; myCounter < pageItems.length; myCounter++){
			myPageItem = pageItems.item(myCounter);
			try{
				if(((myIsInArray("images", myObjectTypes) == true) && (myPageItem.images.length == 1))||
				((myIsInArray("epss", myObjectTypes) == true) && (myPageItem.epss.length == 1))||
				((myIsInArray("pdfs", myObjectTypes) == true) && (myPageItem.pdfs.length == 1))){
					//Is the page item already in the list of items to select?
					myID = myPageItem.id;
					myAlreadyAdded = false;
					for(myPageItemCounter = 0; myPageItemCounter<myObjectsToSelect.length; myPageItemCounter++){
						if(myObjectsToSelect[myPageItemCounter].id == myID){
							myAlreadyAdded = true;
							break;
						}
					}
					//If the page item was not already in the list of items to select, add it to the list.
					if ((myAlreadyAdded == false) && (myPageItem.itemLayer == iLayer)){
						myObjectsToSelect.push(myPageItem);
					}
				}
			}
			catch(myError){
			}
		}
		parent.select(myObjectsToSelect, SelectionOptions.replaceWith);
	}
}
function myIsInArray(myString, myArray){
	var myResult = false;
	for (myCounter = 0; myCounter < myArray.length; myCounter ++){
		if (myArray[myCounter] == myString){
			myResult = true;
			break;
		}
	}	
	return myResult;
}

 

Likes

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 Beginner ,
Jan 28, 2022 Jan 28, 2022

Copy link to clipboard

Copied

LATEST

This is amazing! Thank you so much!

Likes

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