DomC Posted December 5, 2015 Share Posted December 5, 2015 (edited) Hi there I wonder how to handle special character issues in a smooth way. I use the following commands in my script: HSFPath=vs.GetFPathName() bool, path=vs.ConvertHSF2PosixPath(HSFPath) My File name is äöüéè.vwx. And Vectorscript procudes a file path like "C:\Users\dom\Desktop\‰ˆ¸ÈË.vwx" After that I have to replace those "characters" manually by script: umlaut={'ä':'‰','ö':'ˆ','ü':'¸','é':'È','è':'Ë','à':'à'} #Python dict with the replace character path=path.replace(umlaut.get('ä'),'ä') #umlaut.get(dictkey) path=path.replace(umlaut.get('ö'),'ö') path=path.replace(umlaut.get('ü'),'ü') path=path.replace(umlaut.get('é'),'é') path=path.replace(umlaut.get('è'),'è') path=path.replace(umlaut.get('à'),'à') OK, the path.replace part, maybe could maybe be better programmed. But is there any standard procedure for file-path-character issues like this? Handling pathes is daily business. Well, it works on mac platform. The complete script: HSFPath=vs.GetFPathName() bool, path=vs.ConvertHSF2PosixPath(HSFPath) umlaut={'ä':'‰','ö':'ˆ','ü':'¸','é':'È','è':'Ë','à':'à'} path=path.replace(umlaut.get('ä'),'ä') path=path.replace(umlaut.get('ö'),'ö') path=path.replace(umlaut.get('ü'),'ü') path=path.replace(umlaut.get('é'),'é') path=path.replace(umlaut.get('è'),'è') path=path.replace(umlaut.get('à'),'à') path=path[:-3]+'txt' inPath=path skipHeader= False asString=True delimiter="\t" codex='iso8859_2' #'latin_1', 'iso8859_2', 'mac_latin2','utf_8' #https://docs.python.org/3/library/codecs.html lines=[] rows=[] import csv import os if asString==False: quote=csv.QUOTE_NONNUMERIC else: quote=csv.QUOTE_NONE if os.path.isfile(inPath) == False: vs.AlrtDialog('Das Info-File der ERP Software wurde nicht gefunden. Dieses Script liesst eine Textdatei mit gleichem Namen wie die Vectorworks Datei ein. Bitte Erkundigen Sie sich bei Ihrem ERP/PPS Softwarelieferanten über diese Möglichkeit') rowNum=10 lineNum=10 if os.path.isfile(inPath) ==False: for x in range(rowNum): rows.append('error Import File') for x in range(lineNum): lines.append('error') FilePath=('import File missed') if os.path.isfile(inPath) ==True: with open(inPath, encoding=codex) as f: reader= csv.reader(f,dialect='excel',delimiter=delimiter,quoting=quote) if skipHeader==True: next(reader) for line in reader: lines.append(line) lineNum=len(lines) rowNum=len(line) for row in range(rowNum): rown=[] for line in range(lineNum): rown.append(lines[line][row]) rows.append(rown) if asString==False: rows = tuple(tuple(x) for x in rows) rows = list(rows) lines = tuple(tuple(x) for x in lines) lines = list(lines) erpdict=dict(zip(lines[0], lines[1])) plankopf="INSYMBOL & INOBJECT & INVIEWPORT & ('VAA Title Block'.'__Other4'='ERP_Plankopf')" #plankopf="INGROUP & INVIEWPORT & (R IN ['VAA Title Block'])" def PlankopfFelder(h): vs.SetRField(h, 'VAA Title Block', '__ProjName', erpdict.get('PRO_STAMM_PROJEKTBEZ')) vs.SetRField(h, 'VAA Title Block', '__ClientName', erpdict.get('ADR_NAME_FIRMA')) vs.SetRField(h, 'VAA Title Block', '__ProjAddress', erpdict.get('ADR_STRASSE')+', '+erpdict.get('ADR_PLZ')+' '+erpdict.get('ADR_ORT')) vs.SetRField(h, 'VAA Title Block', '__ProjNo', erpdict.get('PRO_STAMM_PROJEKTNR')) vs.ResetObject(h) return() vs.ForEachObject(PlankopfFelder, plankopf) Edited December 5, 2015 by DomC Quote Link to comment
rDesign Posted December 5, 2015 Share Posted December 5, 2015 @DomC: I am way out of my depth here, but maybe the Python 'unicodedata' module could help simplify things for you? Python 3.4 Documentation - Unicode HOWTO - Unicode Filenames Quote Link to comment
DomC Posted December 5, 2015 Author Share Posted December 5, 2015 Tim Thanks a lot. Your post brought me to search in the right direction There seems to be many solutions to convert with python. But after several encoding, decoding tries. I searched again "http://developer.vectorworks.net/" for encoding topics. Lo and behold: There was a vectorscript function to do that job :-)!!! vs.StringAnsiToMac(string) Nice. Thanks again Tim Dom Quote Link to comment
rDesign Posted December 5, 2015 Share Posted December 5, 2015 DomC - I'm happy to hear that my admittedly uninformed post was actually helpful! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.