What are the possibility of the Preset class?

That wasn’t really correct, I just hadn’t looked into it properly. The actual issue is, the error can happen with brushes with embedded patterns.
For some reason “Texture/Pattern/PatternMD5” is basically saved in binary, which breaks the XML parser. (I’d come across this issue before and forgotten about it.)

The bit causing the issue can replaced with this code (before parsing the XML);

import re

pat = '<param type="string" name="Texture/Pattern/PatternMD5"><!\[CDATA\[(.+)\]\]></param>'
match = re.search(pat, presetXMLString)
md5sum = match.group(1)

pat2 = '<param type="string" name="Texture/Pattern/PatternMD5"><!\[CDATA\[%s\]\]></param>' % re.escape(md5sum)
def replfunc(m):
    return '<param type="string" name="Texture/Pattern/PatternMD5"><![CDATA[%s]]></param>' % \
                "TEMP"

presetXMLString = re.sub(pat2, replfunc, presetXMLString, count=1)

but the MD5 can’t be put back afterward, because Preset.fromXML() will complain it’s invalid. In theory that might break the pattern if you were to resave the preset afterward? But in practice, I’m not sure.

1 Like