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

Sort selected textframes position by name inside layer, also change textframes position

Engaged ,
Mar 25, 2023 Mar 25, 2023

Hi,

I want to sort by name selected textframes

This works for sorting by name, layers

 

#target illustrator  
  
main();  
function main(){  
	
	if(!documents.length) return;  
    
	var doc = app.activeDocument;  
	
	var allLayers = app.activeDocument.layers;  
	
	var visibleLayers = [];  
	for(a=0; a<allLayers.length; a++){  
		var ilayer = allLayers[a];  
		if (ilayer.visible) {  
			visibleLayers.push(ilayer);  
		}  
	};  
		 
	var alphabetizedLayers = visibleLayers.sort( function(a,b) { return a > b } );
 	
	sort_layers(doc, alphabetizedLayers);
}  

function sort_layers(obj, abcLayers) {	
	for (var ri=0; ri<abcLayers.length;ri++) {
		abcLayers[ri].zOrder(ZOrderMethod.SENDTOBACK);
	};
}

 

 

Any help for modifying script for sorting selected textframes?

(Keeping textframe positions too)

From this

siomosp_0-1679771952751.jpegexpand image

to 

 

 

TOPICS
Scripting
451
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

Guide , Mar 25, 2023 Mar 25, 2023
// select text frames
main();
function main(){
    var frames = app.activeDocument.selection;
    var array = [];
    for(var i = 0; i < frames.length; i++){
        array.push(frames[i]);
    };  
    array.sort(function(a, b) {return a.contents > b.contents;});
    sortZOrder(array);
    bubbleSortTop(array);
}  

function sortZOrder(frames) {
	for (var j = 0; j < frames.length; j++) {
		frames[j].zOrder(ZOrderMethod.SENDTOBACK);
	};
}
function bubbleSortTop(a){
    for (var i = a.length - 1; 
...
Translate
Adobe
Engaged ,
Mar 25, 2023 Mar 25, 2023

Partial solved

Sorting text frames alphabetically

 

// Sort selected textframes alphabetically
#target illustrator  
  
main();  
function main(){  
	if(!documents.length) return;  
 	var doc = app.activeDocument; 
	var selected_text = [];  
	for(a=0; a<app.selection.length; a++){  
		var ilayer = app.selection[a].contents;
		 
			selected_text.push(ilayer);  
		var	selected_text_sorted = selected_text.sort();
		var	selected_text_sorted_reverse = selected_text.sort().reverse();
	};  
	// alert(selected_text_sorted);	 
	for(a=0; a<app.selection.length; a++){  
	app.selection[a].contents = selected_text_sorted_reverse[a]
	}
}

 

 

 

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
Guide ,
Mar 25, 2023 Mar 25, 2023
// select text frames
main();
function main(){
    var frames = app.activeDocument.selection;
    var array = [];
    for(var i = 0; i < frames.length; i++){
        array.push(frames[i]);
    };  
    array.sort(function(a, b) {return a.contents > b.contents;});
    sortZOrder(array);
    bubbleSortTop(array);
}  

function sortZOrder(frames) {
	for (var j = 0; j < frames.length; j++) {
		frames[j].zOrder(ZOrderMethod.SENDTOBACK);
	};
}
function bubbleSortTop(a){
    for (var i = a.length - 1; i > 0; i--){
        for (var j = 0; j < i; j++){
            if (a[j].top < a[j + 1].top){
                var temp = a[j].top;
                a[j].top = a[j + 1].top;
                a[j + 1].top = temp;
            }
        }
    }
    return a;
}
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
Engaged ,
Mar 25, 2023 Mar 25, 2023
LATEST

Great solution, thank you!

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