Created
June 25, 2011 08:51
-
-
Save frederickk/1046302 to your computer and use it in GitHub Desktop.
scriptographer scripts which rename layers (layer_ItemRename_0_1.js) and selects the layer by name (layer_ItemSelect_0_35.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Name Layer/Item 0.1 | |
* | |
* Ken Frederick | |
* ken.frederick@gmx.de | |
* | |
* http://cargocollective.com/kenfrederick/ | |
* http://kenfrederick.blogspot.com/ | |
* | |
*/ | |
// ------------------------------------------------------------------------ | |
// Properties | |
// ------------------------------------------------------------------------ | |
/** | |
* Note from the Scriptographer.org Team | |
* | |
* In Scriptographer 2.9, we switched to a top-down coordinate system and | |
* degrees for angle units as an easier alternative to radians. | |
* | |
* For backward compatibility we offer the possibility to still use the old | |
* bottom-up coordinate system and radians for angle units, by setting the two | |
* values bellow. Read more about this transition on our website: | |
* http://scriptographer.org/news/version-2.9.064-arrived/ | |
*/ | |
script.coordinateSystem = 'bottom-up'; | |
script.angleUnits = 'radians'; | |
// document properties | |
var sel; | |
var ebene; | |
var str; | |
// values | |
var values = { | |
strNew: 'Object_Name', | |
bAll: false | |
}; | |
// gui components | |
var components = { | |
strNew: { | |
type: 'string', | |
label: 'Desired Name' | |
}, | |
bAll: { | |
type: 'checkbox', | |
label: 'Rename all instances of this item?' | |
} | |
}; | |
// ------------------------------------------------------------------------ | |
// Setup | |
// ------------------------------------------------------------------------ | |
function Setup() { | |
// initialize the palette window | |
var dialog = new Dialog.prompt('Name Layer/Item 0.1', components, values); | |
} | |
// ------------------------------------------------------------------------ | |
// Update | |
// ------------------------------------------------------------------------ | |
function Update() { | |
} | |
// ------------------------------------------------------------------------ | |
// Main | |
// ------------------------------------------------------------------------ | |
function Main() { | |
sel = document.selectedItems.reverse(); | |
ebene = document.layers; | |
// first what object are we looking for? | |
for (i in sel) { | |
obj = sel[i]; | |
// bootleg! found out our selected item was | |
// a group or compound path so we're done. | |
// move on. | |
if(obj.hasChildren()) { | |
str = obj.name; | |
i = sel.length; | |
} | |
// single item | |
str = obj.name; | |
} | |
if(!values.bAll) { | |
if(sel.length == 1) { | |
Dialog.alert("Renaming only this instance of \"" + str + "\" to \"" + values.strNew + "\""); | |
rename(obj); | |
} else { | |
Dialog.alert("Renaming only these instances to \"" + values.strNew + "\""); | |
for (var i = 0; i < sel.length; i++) { | |
obj = sel[i]; | |
rename(obj); | |
} | |
} | |
} else { | |
Dialog.alert("Renaming all instances of \"" + str + "\" to \"" + values.strNew + "\""); | |
for(var i=0; i<ebene.length; i++){ | |
var objekt = ebene[i].items; | |
for(var j=0; j<objekt.length; j++) { | |
if(objekt[j].name == str) { | |
rename(objekt[j]); | |
} | |
} | |
} | |
} | |
} | |
// ------------------------------------------------------------------------ | |
// Methods | |
// ------------------------------------------------------------------------ | |
function random(minr, maxr) { | |
return minr + Math.random() * (maxr - minr); | |
} | |
function rename(obj) { | |
obj.name = values.strNew; | |
obj.selected = false; | |
} | |
// ------------------------------------------------------------------------ | |
// Execution | |
// ------------------------------------------------------------------------ | |
Setup(); | |
Update(); | |
Main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Select by Object 0.35 | |
* | |
* Ken Frederick | |
* ken.frederick@gmx.de | |
* | |
* http://cargocollective.com/kenfrederick/ | |
* http://kenfrederick.blogspot.com/ | |
* | |
*/ | |
// ------------------------------------------------------------------------ | |
// Properties | |
// ------------------------------------------------------------------------ | |
/** | |
* Note from the Scriptographer.org Team | |
* | |
* In Scriptographer 2.9, we switched to a top-down coordinate system and | |
* degrees for angle units as an easier alternative to radians. | |
* | |
* For backward compatibility we offer the possibility to still use the old | |
* bottom-up coordinate system and radians for angle units, by setting the two | |
* values bellow. Read more about this transition on our website: | |
* http://scriptographer.org/news/version-2.9.064-arrived/ | |
*/ | |
script.coordinateSystem = 'bottom-up'; | |
script.angleUnits = 'radians'; | |
// document properties | |
var sel; | |
var ebene; | |
// ------------------------------------------------------------------------ | |
// Setup | |
// ------------------------------------------------------------------------ | |
function Setup() { | |
} | |
// ------------------------------------------------------------------------ | |
// Update | |
// ------------------------------------------------------------------------ | |
function Update() { | |
} | |
// ------------------------------------------------------------------------ | |
// Main | |
// ------------------------------------------------------------------------ | |
function Main() { | |
sel = document.selectedItems.reverse(); | |
ebene = document.layers; | |
var str; | |
// first what object are we looking for? | |
for (i in sel) { | |
obj = sel[i]; | |
if(obj.firstChild != null) { | |
// bootleg! found out our selected item was | |
// a group or compound path so we're done. | |
// move on. | |
str = obj.name; | |
i = sel.length; | |
} | |
str = obj.name; | |
// print("looking for " + str); | |
} | |
Dialog.alert("Selecting all of the Layers/Items called \n\"" + str + "\""); | |
// now let's go through all of the layers and find it | |
for(var i=0; i<ebene.length; i++){ | |
var objLayer = ebene[i].items; | |
// level 1 | |
for(var j=0; j<objLayer.length; j++) { | |
var objName = objLayer[j].name; | |
if(objName == str) { | |
objLayer[j].selected = true; | |
// dig it | |
// print(objLayer[j].children.length); | |
// if(objLayer[j].children.length) { | |
digger(objLayer[j]); | |
// } | |
// dig it end | |
} | |
} | |
// level 1 end | |
} | |
} | |
// ------------------------------------------------------------------------ | |
// Methods | |
// ------------------------------------------------------------------------ | |
function digger(digObj) { | |
for(var k=0; k<digObj.children.length; k++) { | |
digObj.children[k].selected = true; | |
// if(digObj.children[k].children.length > 1) { | |
digger(digObj.children[k]); | |
// } | |
} | |
} | |
// ------------------------------------------------------------------------ | |
// Execution | |
// ------------------------------------------------------------------------ | |
Setup(); | |
Update(); | |
Main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment