FANDOM


Importing and Exporting all animations in a specific order
This tutorial was written by Pinguiculous. Please give credit.

This tutorial is related to the following pages:

Click here for more tutorials!


This tutorial explains how to edit the External Editor to add two more options in the "Animation Editor" menu, to export and import animation in a custom order (specified in a text file).

These two options allow to keep the original order when importing all the animations, and to change the order, if needed, in an easy way.

How to edit the External Editor Scripts

The External Editor scripts ("Data/EditorScripts.rxdata") aren't directly accessible from the RPG Maker XP script editor, since it loads by default the "Data/Scripts.rxdata" files. To edit them, we can use an external editor (e.g. Gemini), or you can rename "Data/EditorScripts.rxdata" to "Data/Scripts.rxdata" (keep a copy of the old Scripts.rxdata file), open your project in RPG Maker XP, edit the scripts, save, close and restore the original names of the script files.

Add two more options in the "Animation Editor" menu

After choosing your preferred way to edit the scripts, you have to alter the following lines of code:

go to the "EditorMain #####" script, and replace lines 143 to 268 (included, pay attention to the indentation) with:

    elsif ret==11 # Animations
      subcommand=Kernel.pbShowCommands(nil,[
         _INTL("Animation Editor"),
         _INTL("Export All Animations"),
         _INTL("Import All Animations"),
         _INTL("Export All Animations, memorize order"),
         _INTL("Import All Animations, custom order")
      ],-1)
      if subcommand==0 # Animation Editor
        pbFadeOutIn(99999) { pbAnimationEditor }
      elsif subcommand==1 # Export All Animations
        begin
          Dir.mkdir("Animations") rescue nil
          animations=tryLoadData("Data/PkmnAnimations.rxdata")
          if animations
            msgwindow=Kernel.pbCreateMessageWindow
            for anim in animations
              next if !anim || anim.length==0 || anim.name==""
              Kernel.pbMessageDisplay(msgwindow,anim.name,false)
              Graphics.update
              safename=anim.name.gsub(/\W/,"_")
              Dir.mkdir("Animations/#{safename}") rescue nil
              File.open("Animations/#{safename}/#{safename}.anm","wb"){|f|
                 f.write(dumpBase64Anim(anim))
              }
              if anim.graphic && anim.graphic!=""
                graphicname=RTP.getImagePath("Graphics/Animations/"+anim.graphic)
                pbSafeCopyFile(graphicname,"Animations/#{safename}/"+File.basename(graphicname))
              end
              for timing in anim.timing
                if !timing.timingType || timing.timingType==0
                  if timing.name && timing.name!=""
                    audioName=RTP.getAudioPath("Audio/SE/"+timing.name)
                    pbSafeCopyFile(audioName,"Animations/#{safename}/"+File.basename(audioName))
                  end
                elsif timing.timingType==1 || timing.timingType==3
                  if timing.name && timing.name!=""
                    graphicname=RTP.getImagePath("Graphics/Animations/"+timing.name)
                    pbSafeCopyFile(graphicname,"Animations/#{safename}/"+File.basename(graphicname))
                  end
                end
              end
            end
            Kernel.pbDisposeMessageWindow(msgwindow)
            Kernel.pbMessage(_INTL("All animations were extracted and saved to the Animations folder."))
          else
            Kernel.pbMessage(_INTL("There are no animations to export."))
          end
        rescue
          p $!.message,$!.backtrace
          Kernel.pbMessage(_INTL("The export failed."))
        end
      elsif subcommand==2 # Import All Animations
        animationFolders=[]
        if safeIsDirectory?("Animations")
          Dir.foreach("Animations"){|fb|
             f="Animations/"+fb
             if safeIsDirectory?(f) && fb!="." && fb!=".."
               animationFolders.push(f)
             end
          }
        end
        if animationFolders.length==0
          Kernel.pbMessage(
             _INTL("There are no animations to import. Put each animation in a folder within the Animations folder."))
        else
          msgwindow=Kernel.pbCreateMessageWindow
          animations=tryLoadData("Data/PkmnAnimations.rxdata")
          animations=PBAnimations.new if !animations
          for folder in animationFolders
            Kernel.pbMessageDisplay(msgwindow,folder,false)
            Graphics.update
            audios=[]
            files=Dir.glob(folder+"/*.*")
            %w( wav ogg mid wma mp3 ).each{|ext|
               upext=ext.upcase
               audios.concat(files.find_all{|f| f[f.length-3,3]==ext})
               audios.concat(files.find_all{|f| f[f.length-3,3]==upext})
            }
            for audio in audios
              pbSafeCopyFile(audio,
                 RTP.getAudioPath("Audio/SE/"+File.basename(audio)),
                 "Audio/SE/"+File.basename(audio))
            end
            images=[]
            %w( png jpg bmp gif ).each{|ext|
               upext=ext.upcase
               images.concat(files.find_all{|f| f[f.length-3,3]==ext})
               images.concat(files.find_all{|f| f[f.length-3,3]==upext})
            }
            for image in images
              pbSafeCopyFile(image,
                 RTP.getImagePath("Graphics/Animations/"+File.basename(image)),
                 "Graphics/Animations/"+File.basename(image))
            end
            Dir.glob(folder+"/*.anm"){|f|
               textdata=loadBase64Anim(IO.read(f)) rescue nil
               if textdata && textdata.is_a?(PBAnimation)
                 index=pbAllocateAnimation(animations,textdata.name)
                 missingFiles=[]
                 if textdata.name==""
                   textdata.name=File.basename(folder)
                 end
                 textdata.id=-1 # this is not an RPG Maker XP animation
                 pbConvertAnimToNewFormat(textdata)
                 if textdata.graphic && textdata.graphic!=""
                   if !safeExists?(folder+"/"+textdata.graphic) &&
                      !FileTest.image_exist?("Graphics/Animations/"+textdata.graphic)
                     textdata.graphic=""; missingFiles.push(textdata.graphic)
                   end
                 end
                 for timing in textdata.timing
                   if timing.name && timing.name!=""
                     if !safeExists?(folder+"/"+timing.name) &&
                        !FileTest.audio_exist?("Audio/SE/"+timing.name)
                       timing.name=""; missingFiles.push(timing.name)
                     end
                   end
                 end
                 animations[index]=textdata
               end
            }
          end
          save_data(animations,"Data/PkmnAnimations.rxdata")
          Kernel.pbDisposeMessageWindow(msgwindow)
          Kernel.pbMessage(_INTL("All animations were imported."))
        end
      elsif subcommand==3 # Export All Animations w/ orderlist
        safetogo=true
        if safeExists?("Animations/orderlist.txt")
          safetogo=Kernel.pbConfirmMessage(
            _INTL("A different file named 'orderlist.txt' already exists. Overwrite it?"))
        end
        if safetogo
          begin
            orderlist = File.new("Animations/orderlist.txt", "w")
            Dir.mkdir("Animations") rescue nil
            animations=tryLoadData("Data/PkmnAnimations.rxdata")
            if animations
              msgwindow=Kernel.pbCreateMessageWindow
              for anim in animations
                next if !anim || anim.length==0 || anim.name==""
                Kernel.pbMessageDisplay(msgwindow,anim.name,false)
                Graphics.update
                safename=anim.name.gsub(/\W/,"_")
                orderlist.puts(safename)
                Dir.mkdir("Animations/#{safename}") rescue nil
                File.open("Animations/#{safename}/#{safename}.anm","wb"){|f|
                   f.write(dumpBase64Anim(anim))
                }
                if anim.graphic && anim.graphic!=""
                  graphicname=RTP.getImagePath("Graphics/Animations/"+anim.graphic)
                  pbSafeCopyFile(graphicname,"Animations/#{safename}/"+File.basename(graphicname))
                end
                for timing in anim.timing
                  if !timing.timingType || timing.timingType==0
                    if timing.name && timing.name!=""
                      audioName=RTP.getAudioPath("Audio/SE/"+timing.name)
                      pbSafeCopyFile(audioName,"Animations/#{safename}/"+File.basename(audioName))
                    end
                  elsif timing.timingType==1 || timing.timingType==3
                    if timing.name && timing.name!=""
                      graphicname=RTP.getImagePath("Graphics/Animations/"+timing.name)
                      pbSafeCopyFile(graphicname,"Animations/#{safename}/"+File.basename(graphicname))
                    end
                  end
                end
              end
              Kernel.pbDisposeMessageWindow(msgwindow)
              orderlist.close
              Kernel.pbMessage(_INTL("All animations were extracted and saved to the Animations folder; an ordered list of the animation is stored in \"orderlist.txt\"."))
            else
              Kernel.pbMessage(_INTL("There are no animations to export."))
            end
          rescue
            p $!.message,$!.backtrace
            Kernel.pbMessage(_INTL("The export failed."))
          end
        else
          Kernel.pbMessage(_INTL("Export aborted."))
        end
      elsif subcommand==4 # Import All Animations w/ orderlist
        if safeExists?("Animations/orderlist.txt")
          orderlist = File.open("Animations/orderlist.txt","r")
          animationFolders=[]
          for line in orderlist
            line="Animations/"+line.strip
            if safeIsDirectory?(line)
              animationFolders << line
            else
              Kernel.pbMessage(_INTL("Folder {1} not found, the animation was skipped.",line))
            end
          end
          if animationFolders.length==0
            Kernel.pbMessage(
               _INTL("There are no animations to import. The \"orderlist.txt\" file is empty."))
          else
            msgwindow=Kernel.pbCreateMessageWindow
            animations=tryLoadData("Data/PkmnAnimations.rxdata")
            animations=PBAnimations.new if !animations
            for folder in animationFolders
              Kernel.pbMessageDisplay(msgwindow,folder,false)
              Graphics.update
              audios=[]
              files=Dir.glob(folder+"/*.*")
              %w( wav ogg mid wma mp3 ).each{|ext|
                 upext=ext.upcase
                 audios.concat(files.find_all{|f| f[f.length-3,3]==ext})
                 audios.concat(files.find_all{|f| f[f.length-3,3]==upext})
              }
              for audio in audios
                pbSafeCopyFile(audio,
                   RTP.getAudioPath("Audio/SE/"+File.basename(audio)),
                   "Audio/SE/"+File.basename(audio))
              end
              images=[]
              %w( png jpg bmp gif ).each{|ext|
                 upext=ext.upcase
                 images.concat(files.find_all{|f| f[f.length-3,3]==ext})
                 images.concat(files.find_all{|f| f[f.length-3,3]==upext})
              }
              for image in images
                pbSafeCopyFile(image,
                   RTP.getImagePath("Graphics/Animations/"+File.basename(image)),
                   "Graphics/Animations/"+File.basename(image))
              end
              Dir.glob(folder+"/*.anm"){|f|
                 textdata=loadBase64Anim(IO.read(f)) rescue nil
                 if textdata && textdata.is_a?(PBAnimation)
                   index=pbAllocateAnimation(animations,textdata.name)
                   missingFiles=[]
                   if textdata.name==""
                     textdata.name=File.basename(folder)
                   end
                   textdata.id=-1 # this is not an RPG Maker XP animation
                   pbConvertAnimToNewFormat(textdata)
                   if textdata.graphic && textdata.graphic!=""
                     if !safeExists?(folder+"/"+textdata.graphic) &&
                        !FileTest.image_exist?("Graphics/Animations/"+textdata.graphic)
                       textdata.graphic=""; missingFiles.push(textdata.graphic)
                     end
                   end
                   for timing in textdata.timing
                     if timing.name && timing.name!=""
                       if !safeExists?(folder+"/"+timing.name) &&
                          !FileTest.audio_exist?("Audio/SE/"+timing.name)
                         timing.name=""; missingFiles.push(timing.name)
                       end
                     end
                   end
                   animations[index]=textdata
                 end
              }
            end
            save_data(animations,"Data/PkmnAnimations.rxdata")
            Kernel.pbDisposeMessageWindow(msgwindow)
            Kernel.pbMessage(_INTL("All animations in the \"orderlist.txt\" file were imported."))
          end
        else
          Kernel.pbMessage(_INTL("File \"orderlist.txt\" is missing. The import failed."))
        end
      end

This code will add two more options in the "Animation Editor" menu: "Export All Animations, memorize order" and "Import All Animations, custom order".

The first option (fourth in the menu) will export all the animations, and will create a file called "orderlist.txt" in the generated "Animations" folder. This file contains an ordered list of the exported animations.

The second option (fifth in the menu) will import the animations listed in the "orderlist.txt" file, keeping their order and ignoring non-listed animations. If an animation listed in the txt file doesn't have its own folder, an error message will be returned and the process will continue, skipping that animation.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.