With the upgrade to 2.0 and 2.1 came a new way to add custom portraits to BG/SOD and BG2. You can still put them in the portraits folder and the appearance editor will cycle through them. Or you can put them in the override file and edit your BGEE.lua file to divide them into male and female portraits as detailed by
@Dee here:
On PortraitsScroll down a little in that thread and you'll find a utility I wrote that would go through a directory full of portraits and create the LUA code to paste into your BGEE.lua for those of us who like to keep a lot of portraits around and who use a naming scheme where the files start with M or F to denote gender.
I was playing around with my portraits yesterday and decided I could go one step better on this. So here's my improved version of this utility. Instead of creating a text file that you can open and copy & paste the contents from. This version will insert the code directly into your BGEE.lua file for you. And, if you add or delete some portraits, just run it again and it will bring the BGEE.lua file up to date.
How to use
This is a PowerShell script, so it only works on Window 7 or later. If you have Windows XP, you can download PowerShell from Microsoft and install it.
If you've never run PowerShell scripts before you need to do this:
1. Find Windows PowerShell in your Start menu.
2. Right click on it and choose Run as Administrator.
![]()
3. At the command prompt type this:
PS C:\WINDOWS\system32> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
4. Type Y for Yes and hit enter.
PS C:\WINDOWS\system32> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to
the security risks described in the about_Execution_Policies help topic at http://go.microsoft.com/fwlink/?LinkID=135170. Do
you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y
Close the PowerShell window. You only need to do this once and you'll be able to run scripts forever.
Download the zip attached to this post and unzip the Register-Portraits.ps1 file into your override folder. Copy your portraits into the override folder. Use
Near Infinity to extract BGEE.lua into your override folder. The script assumes that it is in the same folder as the portraits and BGEE.lua, so keep them together.
Now, run PowerShell from the Start menu. (Don't use Run as Administrator)
Bring up your override folder in an Explorer window and copy the location.
In PowerShell type:
PS C:\Users\Bill> cd "
Right click in PowerShell to paste the path to override, close the quotes and hit enter.
PS C:\Users\Bill> cd "C:\GOG Games\Baldur's Gate II - Enhanced Edition\override"
PS C:\GOG Games\Baldur's Gate II - Enhanced Edition\override>
Now run the script, you only need to type the first couple letters and hit tab and the script name will appear.
PS C:\GOG Games\Baldur's Gate II - Enhanced Edition\override> .\Register-Portraits.ps1
And that's it. Any time you need to update your portraits list, just pull up PowerShell, cd to your override folder and run the script again. BTW, if you don't have your BGEE.lua file in the folder, the script will create a file called portraits.txt with the list in it.
The script
$outfile = ".\portraits.txt"
[String[]] $portraitList = @()
$portraitList = "`t--Start Here`n"
$females = Get-ChildItem | Where-Object Name -Like "F*L.bmp"
$males = Get-ChildItem | Where-Object Name -Like "M*L.bmp"
foreach ($lady in $females)
{
$length = ($lady.BaseName).Length - 1
$charname = ($lady.BaseName).SubString(0,$length)
$nameLine = "`t{'" + $charname + "', 2},`n"
$portraitList = $portraitList, $nameLine
}
foreach ($dude in $males)
{
$length = ($dude.BaseName).Length - 1
$charname = ($dude.BaseName).SubString(0,$length)
$nameLine = "`t{'" + $charname + "', 1},`n"
$portraitList = $portraitList, $nameLine
}
$portraitList = $portraitList, "`t--End Here"
$bgeelua = ".\bgee.lua"
if (Test-Path $bgeelua)
{
$luaContents = Get-Content $bgeelua
$modifiedLua = $luaContents[0..1]
if ($luaContents[2] -eq "`t--Start Here")
{
$endPos = [array]::IndexOf($luaContents, $luaContents -eq "`t--End Here")
}
else
{
$endPos = 2
}
$modifiedLua = $modifiedLua, $portraitList, $luaContents[($endPos + 1)..($luaContents.Length - 1)]
$modifiedLua | Set-Content $bgeelua
}
else
{
$portraitList | Set-Content $outfile
}
Customization
Lines 6 & 7 of the script contain the file pattern for male and female:
$females = Get-ChildItem | Where-Object Name -Like "F*L.bmp"
$males = Get-ChildItem | Where-Object Name -Like "M*L.bmp"
If you use a different naming scheme you can change those lines. For example, if you use B & G for boy and girl instead of M & F, just edit those lines to:
$females = Get-ChildItem | Where-Object Name -Like "G*L.bmp"
$males = Get-ChildItem | Where-Object Name -Like "B*L.bmp"
If some of your portraits are M & F and some are B & G, then we can get a little more fancy and change to:
$females = Get-ChildItem | Where-Object {($_.Name -Like "F*L.bmp") -or ($_.Name -Like "G*L.bmp")}
$males = Get-ChildItem | Where-Object {($_.Name -Like "M*L.bmp") -or ($_.Name -Like "B*L.bmp")}
So, try it out and let me know what you think. If anyone wants to translate it into a bash script for Mac or Linux, feel free.