# Is it possible to export units from a module or saved game?

**URL:** <https://forum.vassalengine.org/t/is-it-possible-to-export-units-from-a-module-or-saved-game/76773>\
**Category:** General Discussion\
**Created:** [March 18, 2023, 4:37pm UTC](https://forum.vassalengine.org/t/is-it-possible-to-export-units-from-a-module-or-saved-game/76773 "2023-03-18T16:37:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fatgreta](https://forum.vassalengine.org/letter_avatar_proxy/v4/letter/f/839c29/32.png) [@fatgreta](https://forum.vassalengine.org/u/fatgreta)\
**Post date:** [March 18, 2023, 4:37pm UTC](https://forum.vassalengine.org/t/is-it-possible-to-export-units-from-a-module-or-saved-game/76773/1 "2023-03-18T16:37:52Z")

</div>

I have done some searching and I think the answer is probably no, but I’m curious if it’s possible to save a group of units that are in a vassal saved game file and export them to load into another game (using the same module)? Or could I possibly edit a module to include a group of forces (obviously not making the module available for public use)?

Thanks for any help,

Chris

---

<div class="post-metadata">

**Author:** ![jrwatts](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/jrwatts/32/6972_2.png) [@jrwatts](https://forum.vassalengine.org/u/jrwatts)\
**Post date:** [March 18, 2023, 8:53pm UTC](https://forum.vassalengine.org/t/is-it-possible-to-export-units-from-a-module-or-saved-game/76773/2 "2023-03-18T20:53:53Z")

</div>

From a saved game, no (they’re encrypted to prevent cheating, IIRC). Version 3.7, which has an initial beta available now ([VASSAL 3.7.0-beta 1 released](https://forum.vassalengine.org/t/vassal-3-7-0-beta1-released/76755)), will have the ability to export and import sections of a module as XML files, however.

---

<div class="post-metadata">

**Author:** ![cholmcc](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cholmcc/32/8319_2.png) [@cholmcc](https://forum.vassalengine.org/u/cholmcc)\
**Post date:** [March 19, 2023, 11:52am UTC](https://forum.vassalengine.org/t/is-it-possible-to-export-units-from-a-module-or-saved-game/76773/3 "2023-03-19T11:52:59Z")

</div>

With a bit of hackery it is possible to extract piece, prototype, etc. information from a module.

- Open the `vmod` module with some ZIP utility

- In the ZIP file you will find the file `buildFile.xml` which contains all the definitions of pieces, prototypes, and so on. Use a plain text editor or some fancy XML editor to open this file.

- Now back in the ZIP file you will find the folder `images`. Open that folder

- Now open your target module with a ZIP manager

- Open the file `buildFile.xml` and copy’n’paste the definitions you previously copied into appropriate places in the target `buildFile.xml` (consult the source `buildFile.xml` for hints)

- Copy all the images you need into the sub directory `images` of the target ZIP file.

- Now close the target ZIP file (and possibly rename it back to end in `.vmod`).

- Open your target `vmod` in the VASSAL editor and fix up things.

_Alternatively_, if you have a bit of Python experience, you can use my module [`pywargame`](https://gitlab.com/wargames_tex/pywargame). I won’t go into details, about it here, but a rough sketch would be

```
from pywargame import *

with VMod('source.vmod','r') as sourceVmod:
     sourceBuild = sourceVmod.getBuildFile()
     sourceGame = sourceBuild.getGame()

     targetVmod = VMod('target.vmod')
     targetBuild = BuildFile()
     targetGame = targetBuild.addGame()
     targetGame.addBasicCommandEncoder()
     piecesWindow = targetGame.addPieceWindow(name = 'Counters',hotkey = key('C',ALT))
     
     piecesToCopy = ["soviet 1S", ...]

     for pieceName in piecesToCopy:
           sourcePieces = sourceGame.getSpecificPieces(pieceName)
           if len(sourcePieces) <= 0: continue 

           piecesWindow.addPiece(sourcePieces[0])
           images = []
           for trait in sourcePieces[0].getTraits():
                if isinstance(trait,BasicTrait):
                   images.append(trait.get('filename',''))
                elif isinstance(trait,LayerTrait):
                   images.extend(trait.get('images',[]))

           images = ['images/'+i for i in images if i != '']
           sourceImages = sourceVmod.getFiles(images)
           for imgName, imgData in zip(images, sourceImages):
                targetVmod.addFile(imgName, imgData)
           

    targetVmod.addFiles(**{VMod.BUILD_FILE :
                                     targetBuild.encode() })

```

Now, the above is of course only if you’re comfortable with Python programming.

Yours,

_Christian_

---

<div class="post-metadata">

**Author:** ![fatgreta](https://forum.vassalengine.org/letter_avatar_proxy/v4/letter/f/839c29/32.png) [@fatgreta](https://forum.vassalengine.org/u/fatgreta)\
**Post date:** [March 19, 2023, 1:24pm UTC](https://forum.vassalengine.org/t/is-it-possible-to-export-units-from-a-module-or-saved-game/76773/4 "2023-03-19T13:24:57Z")

</div>

Thanks fellows, it seems even attempting this is beyond my capabilities, which I expected to be the case. I appreciate you answering in such detail.

Chris

---

<div class="post-metadata">

**Author:** ![palad0n](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/palad0n/32/215_2.png) [@palad0n](https://forum.vassalengine.org/u/palad0n)\
**Post date:** [March 21, 2023, 12:30pm UTC](https://forum.vassalengine.org/t/is-it-possible-to-export-units-from-a-module-or-saved-game/76773/5 "2023-03-21T12:30:12Z")

</div>

You can also use notepad ++. Install the compare add in.  
Do all that unzipping stuff.  
Open the buildfile.xml of the module you want to copy from. Set this file as the one to compare against.  
Open the buildfile.xml of the module you want to copy stuff into from the first.  
Run compare.  
Notepad++ will highlight all the differences.  
Scroll down till you find the entries you want to copy across. Select whole lines and use copy, paste.

Be aware that this can set up a GPID conflict. Vassal handles that well enough, but the modules may not.

Save and rezip.

I find it easier to remember which is which by renaming the buildfile.xml to buildfile(modulename/version).xml. If you do that do not forget to remove the(modulesname/version) before rezipping.
