VBS script to convert a Deck to a Collection

Suggest improvements and features you'd like to see while creating and editing my collection in MTG Studio...

VBS script to convert a Deck to a Collection

Postby Scytale » Tue Apr 28, 2009 6:58 am

This script will convert a Deck file to the Collection file format. You can then import the deck into your Collection.
MTG studio version: 1.6.6.2461 + updated hfw
OS: Windows XP Pro SP3
User avatar
Scytale
Registered User
Registered User
 
Posts: 114
Joined: Wed Feb 20, 2008 5:29 pm
Location: Munich

Postby Scytale » Tue Apr 28, 2009 7:00 am

' Convert.vbs
'
' PARAMETERS
const DECK_FOLDER = "C:\MTG Studio 1.6.6\My Decks\"
const DECK_FILENAME = "MyDeck.deck"
const OUTPUT_FOLDER = "C:\MTG Studio 1.6.6\My Decks\"
const OUTPUT_FILENAME = "deck-for-import.collection"
const NOTES = "General Note applied to all cards"
const STORAGE = "Box1"

' Variables
Const ForReading = 1
Const ForWriting = 2
CDATA_NOTES = "<notes><![CDATA[" & NOTES & "]]></notes>"
CDATA_STORAGE = "<storage><![CDATA[" & STORAGE & "]]></storage>"
IMPORT_FILE = DECK_FOLDER + DECK_FILENAME
EXPORT_FILE = OUTPUT_FOLDER & OUTPUT_FILENAME

' RUN
Call ConvertDecktoCollection()
Wscript.Echo "Conversion completed."

' Conversion routine
Sub ConvertDecktoCollection()
' Open the Deck file and read in the data
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(IMPORT_FILE, ForReading)
strContents = objFile.ReadAll
objFile.Close

' Create the collection file that will be used for importing

If objFSO.FileExists(EXPORT_FILE) Then
objFSO.DeleteFile(EXPORT_FILE)
End If
Set objFile = objFSO.CreateTextFile(EXPORT_FILE, False)

' Prepare the header
objFile.WriteLine "<?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?>"
objFile.WriteLine "<collection version=""1.1"">"
objFile.WriteLine "<cards>"

' Iterate through the Deck
arrLines = Split(strContents, vbCrLf)
For i = 0 to UBound(arrLines) - 1
line = arrLines(i)
If Instr(line, "card deck") Then
cardName = getCardName(line)
line = ReplaceText(line, cardName, "")
line = ReplaceText(line, "deck", "qty")
line = ReplaceText(line, "qty", "name=""" & cardName & """" & " qty")
line = ReplaceText(line, "</card>", CDATA_NOTES & CDATA_STORAGE& "</card>")
objFile.WriteLine line
End If
Next

' Write the footer
objFile.WriteLine "</cards>"
objFile.WriteLine "</collection>"

objFile.Close
End Sub

Function getCardName(string1)
insertString = Mid(string1, Instr(string1, ">")+1)
insertString = Left(insertString, Instr(insertString, "<")-1)

getCardName = insertString
End Function

Function ReplaceText(string1, oldStr, replStr)
Dim regEx, str1

' Create regular expression.
Set regEx = New RegExp
regEx.Pattern = oldStr
regEx.IgnoreCase = True

' Make replacement.
ReplaceText = regEx.Replace(string1, replStr)
End Function
MTG studio version: 1.6.6.2461 + updated hfw
OS: Windows XP Pro SP3
User avatar
Scytale
Registered User
Registered User
 
Posts: 114
Joined: Wed Feb 20, 2008 5:29 pm
Location: Munich

Postby gaddlord » Thu May 07, 2009 1:42 pm

Quite interesting but why don't you simply

1. Open the deck with MTG Studio
2. Select All cards from the deck
3. Press the Add to Collection button

Doesn't it work?
GET LATEST STABLE http://www.mtgstudio.com/download.aspx
Send feature requests and bugs to gaddlord@mtgstudio.com or vote online.
User avatar
gaddlord
MTG Studio Team
MTG Studio Team
 
Posts: 2900
Joined: Thu Dec 18, 2003 12:01 pm
Location: Europe

Postby Scytale » Fri May 08, 2009 12:14 am

There is an 'Add to Collection' button?!?

ROFL!!
MTG studio version: 1.6.6.2461 + updated hfw
OS: Windows XP Pro SP3
User avatar
Scytale
Registered User
Registered User
 
Posts: 114
Joined: Wed Feb 20, 2008 5:29 pm
Location: Munich

Postby gaddlord » Fri May 08, 2009 5:19 pm

Open the deck, select all cards, pick Cards|Add to Collection. As simple as that:

Image

Please tell me if it does not work for you. Thank you.
GET LATEST STABLE http://www.mtgstudio.com/download.aspx
Send feature requests and bugs to gaddlord@mtgstudio.com or vote online.
User avatar
gaddlord
MTG Studio Team
MTG Studio Team
 
Posts: 2900
Joined: Thu Dec 18, 2003 12:01 pm
Location: Europe

Re: VBS script to convert a Deck to a Collection

Postby longtian006 » Thu Oct 18, 2012 10:44 pm

I just tried again. I deleted all my cards in the "Collection from Pool" mode and tried to import again. It got to 651 cards this time and stopped again.








----------------------------------------------------------------------
obd2 connector |airbag reset tool |car diagnostic software
longtian006
Apprentice
 
Posts: 3
Joined: Thu Oct 18, 2012 10:18 pm


Return to Collection Suggestions (MTG Studio)

Who is online

Users browsing this forum: No registered users and 1 guest

cron