[Closed] How to fix issue of non-English symbols
Hi,
Does anyone know,is there a way to fix non-English symbols in maxscript from max 2009 to max 2012 in English system (win7)?Below is the codes for test:
Fn デδぞёд=
(
print "hello"
)
デδぞёд()
I know it works fine in max 2013 or higher version,but lower version will cause error, my script has a lot of these symbols in functions and global values,if I translate them into English symbols will take me too much time,so if there is a good solution will save my life…
any help would be appreciated.
you need a decoder
it’s not hard to write… i think that the task might be an interesting challenge:
find all words in a text with ‘invalid’ symbols
make a dictionary for replacing
using a custom filled dictionary replace all ‘invalid’ words with ‘valid’
Too much thanks,denisT,it’s a good idea,but I worry about its decode time,whatever,before has another more better solution,I’ll try your suggestion :bowdown:
here is a rough version of ‘converter’:
global dictDialog_pos = unsupplied
try (dictDialog_pos = getdialogpos dictDialog) catch()
try (destroydialog dictDialog) catch()
struct UnicodeReplace (source = "", target = "")
rollout dictDialog "Replace Unicode" width:400
(
fn sortBySubstring i1 i2 =
(
if (findstring i1.source i2.source) != undefined then -1 else
if (findstring i2.source i1.source) != undefined then 1 else 0
)
fn findAllUnicodes file =
(
fn hasUnicode word =
(
has = off
for k=1 to word.count while not has do has = (bit.charasint word[k] > 255)
has
)
unicodes = #()
text = try((dotnetclass "System.IO.File").ReadAllText file) catch()
if text != undefined do
(
words = filterstring text "
"
for word in words where (hasUnicode word) do appendifunique unicodes word
)
unicodes
)
fn replaceAllUnicodes file items =
(
text = try((dotnetclass "System.IO.File").ReadAllText file) catch()
if text != undefined do
(
qsort items sortBySubstring
for item in items do text = substitutestring text item.source item.target
sw = try(dotnetobject "System.IO.StreamWriter" file) catch()
if sw != undefined do
(
sw.Write (dotnetobject "System.String" text)
sw.Close()
)
)
)
fn loadUniFile file =
(
items = #()
lines = try((dotnetclass "System.IO.File").ReadAllLines file) catch()
if lines != undefined do
(
for line in lines do
(
data = execute line
if isstruct data do append items data
)
)
items
)
fn saveUniFile file items =
(
global _sw = sw = try(dotnetobject "System.IO.StreamWriter" file) catch()
if sw != undefined do
(
for item in items do
(
sw.WriteLine (dotnetobject "System.String" (item as string))
)
sw.Close()
)
)
dotnetcontrol lv "ListView" width:390 height:300 align:#left offset:[-8,0]
button load_bt "Load" width:90 across:4
button save_bt "Save" width:90
button replace_bt "Replace" width:90
button cancel_bt "Cancel" width:90
fn initLV =
(
lv.LabelEdit = on
lv.View = lv.View.Details
lv.HeaderStyle = lv.HeaderStyle.Clickable
lv.Columns.Add "Target" 190
lv.Columns.Add "Source" 190
)
fn fillLV items =
(
lv.items.clear()
qsort items sortBySubstring
for item in items do
(
i = lv.items.Add item.target
i.subitems.add item.source
)
)
on load_bt pressed do
(
file = getOpenFileName caption:"Load Text File" types:"Text (.txt)|*.txt|Uni Text (.uni)|*.uni|Any (.*)|*.*"
if (file != undefined) do
(
items = #()
if stricmp (getfilenametype file) ".uni" == 0 then
(
items = loadUniFile file
)
else
(
unicodes = findAllUnicodes file
sort unicodes
items = for source in unicodes collect (UnicodeReplace source:source target:source)
)
fillLV items
)
)
on save_bt pressed do
(
file = getSaveFileName caption:"Save Uni File" types:"Uni Text (.uni)|*.uni"
if (file != undefined) do
(
items = for k=0 to lv.items.count-1 collect
(
i = lv.items.item[k]
s = i.subitems.item[1]
UnicodeReplace source:s.text target:i.text
)
saveUniFile file items
)
)
on replace_bt pressed do
(
file = getOpenFileName caption:"Load Text File" types:"Text (.txt)|*.txt|Any (.*)|*.*"
if (file != undefined) do
(
items = for k=0 to lv.items.count-1 collect
(
i = lv.items.item[k]
s = i.subitems.item[1]
UnicodeReplace source:s.text target:i.text
)
replaceAllUnicodes file items
)
)
on cancel_bt pressed do destroydialog dictDialog
on dictDialog close do
(
dictDialog_pos = getdialogpos dictDialog
)
on dictDialog open do
(
initLV()
)
)
createdialog dictDialog pos:dictDialog_pos
how to use:
load any ‘unicode’ included file
edit targets in listview (words that has to replace sources)
use replace button to replace source (‘unicode’) words to new targets
save changes in new file for next time use
enjoy!
Wow!Thank you for taking the time to create this script,denis,I think it’s very professional even though a rough version,I tested,it’s work,awesome!!
BTW,I searched forum,I found a topic talked about handle unicode,
http://forums.cgsociety.org/showthread.php?t=950434
in that way can fix this problem too?
I tried,seemed not work.
it was about to see characters in mxs editor (for comments or labels for example). it’s not about be able to use them in function or variable names.