Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
reorderItemsEdenSQM v1.02
# reorderItemsEdenSQM v1.02
# Made by AgentRev
# Recalculates "Item" and "id" numbers from top to bottom in unbinarized SQM files produced by Arma 3's Eden editor
# For use with "Python Script" plugin (http://npppythonscript.sourceforge.net/) and Notepad++ v6.5.1 & up only
# In order for this script to work:
# - the SQM file must be indented with tabs the same way as originally produced by Eden
# - there must be no spaces on either side of equal signs (=) and semicolons (;) in the SQM file
# - you must click once anywhere inside the targeted SQM right before running the script, for it to run on the correct file
import re;
console.write('--- reorderItemsEdenSQM ---\n')
#if not editor.getLine(0).startswith('version=51;'):
# raise Exception('[ERROR] mission.sqm incompatible, not version=51;')
# Adjust text formatting to Eden standard
notepad.menuCommand(45001) # Windows Format EOL
notepad.menuCommand(42024) # Trim Trailing Space
notepad.menuCommand(42053) # Space to TAB (Leading)
notepad.menuCommand(42055) # Remove Empty Lines
editor.appendText('\r\n') # Newline at EOF
lineCount = editor.getLineCount()
# Item renumbering
for i in range(lineCount):
classMatch = r'^(\t+)class Entities'
classEnd = r'\};\r\n'
classIndent = ''
itemMatch = r'(\tclass Item)\d+'
itemN = 0
lineStart = 0
lineEnd = 0
classFound = False
curText = editor.getLine(i)
if not classFound:
m = re.search(classMatch, curText)
if m:
classIndent = '(' + m.group(1) + ')'
itemMatch = '^' + classIndent + itemMatch
classEnd = '^' + classIndent + classEnd
console.write('Line ' + str(i) + ': ' + curText)
classFound = True
lineStart = i + 3
if classFound:
for j in range(lineStart, lineCount):
curText = editor.getLine(j)
if re.match(classEnd, curText):
lineEnd = j - 1
break
for j in range(lineStart, lineEnd):
curText = editor.getLine(j)
if re.match(itemMatch, curText):
newText = re.sub(itemMatch, r'\g<1>\g<2>' + str(itemN), curText)
console.write('Line ' + str(j) + ': ' + newText)
if curText != newText:
editor.replaceWholeLine(j, newText)
itemN += 1
curText = editor.getLine(lineStart - 1)
newText = re.sub('^' + classIndent + r'(\titems=)\d+;', r'\g<1>\g<2>' + str(itemN) + ';', curText)
if curText != newText:
editor.replaceWholeLine(lineStart - 1, newText)
# id renumbering
idMatch = r'^(\t{3}id=)\d+;'
idMatchGroup = r'^(\t{5}id=)\d+;'
curlyMatch = r'^\t{2}\{\r\n'
markerMatch = r'^\s*dataType="Marker";'
layerMatch = r'^\s*dataType="Layer";'
idN = 0
lastItemCurly = 0
markerN = 0
layerN = 0
console.write('id\n')
for i in range(lineCount):
curText = editor.getLine(i)
if re.match(curlyMatch, curText):
lastItemCurly = i
if re.match(markerMatch, curText):
markerN += 1
if re.match(layerMatch, curText):
layerN += 1
if re.match(idMatch, curText):
newText = re.sub(idMatch, r'\g<1>' + str(idN) + ';', curText)
console.write('Line ' + str(i) + ': ' + newText)
if curText != newText:
editor.replaceWholeLine(i, newText)
idN += 1
for j in range(lastItemCurly + 1, i - 1):
curText = editor.getLine(j)
if re.match(idMatchGroup, curText):
newText = re.sub(idMatchGroup, r'\g<1>' + str(idN) + ';', curText)
console.write('Line ' + str(j) + ': ' + newText)
if curText != newText:
editor.replaceWholeLine(j, newText)
idN += 1
# IDProvider renumbering
itemProviderMatch = r'^\tclass ItemIDProvider\r\n'
markerProviderMatch = r'^\tclass MarkerIDProvider\r\n'
layerProviderMatch = r'^\tclass LayerIndexProvider\r\n'
nextIdMatch = r'^(\t{2}nextID=)\d+;'
itemDone = False
markerDone = False
layerDone = False
for i in range(lineCount):
curText = editor.getLine(i)
if re.match(itemProviderMatch, curText):
for j in range(i + 1, lineCount):
curText = editor.getLine(j)
if re.match(nextIdMatch, curText):
newText = re.sub(nextIdMatch, r'\g<1>' + str(idN) + ';', curText)
console.write('Line ' + str(j) + ': ' + newText)
if curText != newText:
editor.replaceWholeLine(j, newText)
break
itemDone = True
if re.match(markerProviderMatch, curText):
for j in range(i + 1, lineCount):
curText = editor.getLine(j)
if re.match(nextIdMatch, curText):
newText = re.sub(nextIdMatch, r'\g<1>' + str(markerN) + ';', curText)
console.write('Line ' + str(j) + ': ' + newText)
if curText != newText:
editor.replaceWholeLine(j, newText)
break
markerDone = True
if re.match(layerProviderMatch, curText):
for j in range(i + 1, lineCount):
curText = editor.getLine(j)
if re.match(nextIdMatch, curText):
newText = re.sub(nextIdMatch, r'\g<1>' + str(layerN) + ';', curText)
console.write('Line ' + str(j) + ': ' + newText)
if curText != newText:
editor.replaceWholeLine(j, newText)
break
layerDone = True
if itemDone and markerDone and layerDone:
break
console.write('done, you can now save the file!\n')
@AgentRev

This comment has been minimized.

Copy link
Owner Author

commented May 1, 2016

I commented out the version check, as SQMs saved by Eden are now at version 52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.