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

Automatic instance names when importing from Photoshop

New Here ,
Dec 12, 2017 Dec 12, 2017

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

Views

562

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

Community Expert , Dec 12, 2017 Dec 12, 2017

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.startFrame){

var elementsA = framesA.elements;

for(var k=0;k<elementsA.length;k++){

if(elementsA.name==""){

if(elementsA.instanceType=="symbol"){

if(!instanceObj[elementsA.libraryItem.name]){

instanceObj[elementsA.libraryItem.name]

...

Votes

Translate

Translate
Community Expert ,
Dec 12, 2017 Dec 12, 2017

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?

Votes

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
New Here ,
Dec 12, 2017 Dec 12, 2017

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

Votes

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 Expert ,
Dec 12, 2017 Dec 12, 2017

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.

Votes

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
New Here ,
Dec 12, 2017 Dec 12, 2017

Copy link to clipboard

Copied

yeah, I know:-) I wash hoping that anyone know extension/script that could make something like that...

Votes

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
New Here ,
Dec 12, 2017 Dec 12, 2017

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!

Votes

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 Expert ,
Dec 13, 2017 Dec 13, 2017

Copy link to clipboard

Copied

LATEST

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

Votes

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 Expert ,
Dec 12, 2017 Dec 12, 2017

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.startFrame){

var elementsA = framesA.elements;

for(var k=0;k<elementsA.length;k++){

if(elementsA.name==""){

if(elementsA.instanceType=="symbol"){

if(!instanceObj[elementsA.libraryItem.name]){

instanceObj[elementsA.libraryItem.name] = true;

elementsA.name = charF(elementsA.libraryItem.name);

} else {

var ii = 0;

while(instanceObj[elementsA.libraryItem.name+ii]){

ii++;

}

instanceObj[elementsA.libraryItem.name+ii] = true;

elementsA.name = charF(elementsA.libraryItem.name+ii);

}

}

}

}

}

}

}

function charF(s){

return s.split(" ").join("_");

}

Votes

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 Expert ,
Dec 12, 2017 Dec 12, 2017

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

Votes

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