Copy link to clipboard
Copied
Hello
I have a question - is it possible to automatically give mc names (from name layers for example) when importing from Photoshop? I just want the same instance names as object names... Scripts/extensions or other solution?
thanks, Remigiusz Szwed
you can use this to assing instance names to all main timeline instances (that don't have name):
var tl = fl.getDocumentDOM().getTimeline();
var instanceObj = {};
for(var i=0;i<tl.layers.length;i++){
var framesA = tl.layers.frames;
for(var j=0;j<framesA.length;j++){
if(j==framesA
var elementsA = framesA
for(var k=0;k<elementsA.length;k++){
if(elementsA
if(elementsA
if(!instanceObj[elementsA
instanceObj[elementsA
Copy link to clipboard
Copied
you can use jsfl to assign instance names to eligible objects, but what kind of eligible objects are you importing from photoshop?
Copy link to clipboard
Copied
hello
when I import .psd file I get movieclips with names created from psd layers' names. I just want to get something like that: .psd layer name -> adobe animate mc name -> aa instance name
Copy link to clipboard
Copied
i see that, but don't know any way for the import dialog to automatically assign instance names. jsfl is the only way i see to do that.
Copy link to clipboard
Copied
yeah, I know:-) I wash hoping that anyone know extension/script that could make something like that...
Copy link to clipboard
Copied
OK, I search again (with different keywrods) and voila: Flash JSFL script example: autoname instances | dezza's blog
thx for your time and replays!
Copy link to clipboard
Copied
This script will rename objects on stage, but won't get info from a imported PSD.
If works for you, just go for it!
But if you still want a script to rename objects the way you described in the first comment, that gets info from a imported PSD, try the one from comment 6.
Regards,
JC
Copy link to clipboard
Copied
you can use this to assing instance names to all main timeline instances (that don't have name):
var tl = fl.getDocumentDOM().getTimeline();
var instanceObj = {};
for(var i=0;i<tl.layers.length;i++){
var framesA = tl.layers.frames;
for(var j=0;j<framesA.length;j++){
if(j==framesA
var elementsA = framesA
for(var k=0;k<elementsA.length;k++){
if(elementsA
if(elementsA
if(!instanceObj[elementsA
instanceObj[elementsA
elementsA
} else {
var ii = 0;
while(instanceObj[elementsA
ii++;
}
instanceObj[elementsA
elementsA
}
}
}
}
}
}
}
function charF(s){
return s.split(" ").join("_");
}
Copy link to clipboard
Copied
Actually it is possible.
Because luckily Animate sets the layer name of each imported asset to the original PSD layer name and also keep the imported objects selected. So all we have to do is to save the selection and set each selected item name to its corresponding layer name.
So here is the code:
function renameInstances(importToLibrary, showDialog, showImporterUI)
{
if (importToLibrary === undefined) importToLibrary = false;
if (showDialog === undefined) showDialog = true;
if (showImporterUI === undefined) showImporterUI = false;
var doc = fl.getDocumentDOM();
var selection;
var uri = fl.browseForFileURL("select", "Import File");
doc.importFile(uri, importToLibrary, showDialog, showImporterUI);
selection = doc.selection;
doc.selectNone();
for (var i = 0; i < selection.length; i++)
{
var name;
var validName = /^[$A-Z_][0-9A-Z_$]*$/i;
selection.selected = true;
name = selection.layer.name;
if (selection.instanceType != "symbol")
{
doc.convertToSymbol("movie clip", name, "center");
if (validName.test(name))
doc.selection[0].name = name;
doc.selectNone();
continue;
}
if (validName.test(name))
selection.name = name;
selection.selected = false;
}
}
renameInstances(false, true, false);
Please notice some things:
- The script makes a basic name validation. So make sure to not name your PSD layers to invalid names for AS3, like names starting with number, that have blank space, special characters or reserved words like "var" or "Number". If the name is invalid, the script will leave the instance name empty.
[OPTIONAL]
- The last line (43) is where the function is called: renameInstances(importToLibrary, showDialog, showImporterUI). The three arguments you can pass are:
• importToLibrary: if the imported assets will be added to stage or not. To add them to stage, set to false;
• showDialog: wheter or not to call the Import dialog box. Set to true to show it.
• showImporterUI: specifies whether to display errors visually (for example, using the Library Conflict dialog box). The default is false.
Download the script here: rename_instances_from_psd_layers.jsfl. To use the script, drag and drop over the Animate IDE or go to Commands > Run Command....
I hope it helps.
Regards,
JC