robierzo Posted January 26, 2016 Share Posted January 26, 2016 Usually when I create a text file with Lisp, ANSI encoding is always displayed by default. But I need to generate a text file whose encoding is UTF-8. Is this possible? thank you Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 26, 2016 Share Posted January 26, 2016 Writing Unicode to a Text File using AutoLISP Quote Link to comment Share on other sites More sharing options...
robierzo Posted January 26, 2016 Author Share Posted January 26, 2016 Lee, with your routine a 'Unicode' file is generated. But I need a file with UTF-8 format. I do not need the codes. Just an empty file in UTF-8 format. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 26, 2016 Share Posted January 26, 2016 Example: ;; Empty UTF-8 Text File - Example by Lee Mac (defun emptyutf8 ( txt / fso stm ) (if (setq fso (vlax-create-object "scripting.filesystemobject")) (progn (vl-catch-all-apply '(lambda ( ) (setq stm (vlax-invoke fso 'createtextfile txt -1 0)) (vlax-invoke stm 'write (vl-list->string '(239 187 191))) (vlax-invoke stm 'close) ) ) (if (= 'vla-object (type stm)) (vlax-release-object stm) ) (if (= 'vla-object (type fso)) (vlax-release-object fso) ) (findfile txt) ) ) ) (defun c:test ( ) (emptyutf8 (vl-filename-mktemp "utf.txt" (getvar 'dwgprefix))) ) Quote Link to comment Share on other sites More sharing options...
robierzo Posted January 27, 2016 Author Share Posted January 27, 2016 Lee Mac. Eres un auténtico genio!!!! Te debo un litro de cerveza "estrella de Galicia". Muchas gracias. Lee Mac. You're a genius !!!! I owe you a pint of beer "Estrella de Galicia". Thank you. Thank you. Thank you..... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 27, 2016 Share Posted January 27, 2016 You're most welcome robierzo, happy to help. Quote Link to comment Share on other sites More sharing options...
robierzo Posted January 27, 2016 Author Share Posted January 27, 2016 Hello again, Lee. I have detected an error. The accented letters misspelled. Example: á é í ó ú ü Á É Í Ó Ú Ü In these cases write a symbol: � :( Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 27, 2016 Share Posted January 27, 2016 The code I have posted is only creating an empty text file - what code are you using the write to this file? Quote Link to comment Share on other sites More sharing options...
robierzo Posted January 27, 2016 Author Share Posted January 27, 2016 I write in the file created, the following, using the command (write-line "Autor: Roberto González Gómez. Ingeniero Técnico en Topografía\n" my_file) But the file type: Autor: Roberto Gonz�lez G�mez. Ingeniero T�cnico en Topograf�a Texto utf.txt Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 27, 2016 Share Posted January 27, 2016 The write-line function is designed for the ASCII character set, writing to ANSI encoded text files; in order to write to a UTF-8 encoded text file you will need to use a method similar to that demonstrated by the example code in the link I provided above, following the UTF-8 encoding standard (i.e. with some characters comprised of multiple bytes). Quote Link to comment Share on other sites More sharing options...
robierzo Posted January 27, 2016 Author Share Posted January 27, 2016 Uhhhmmmm. I understand. But I see a little complicated. I will perform a function to replace accented letters by letters without accents. I think that it will be easier. jeje Thank Lee. Thank you so much. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 27, 2016 Share Posted January 27, 2016 As an alternative to the FSO, you could use the ADO Stream Object to write a text stream to file - here is an example. Quote Link to comment Share on other sites More sharing options...
robierzo Posted January 27, 2016 Author Share Posted January 27, 2016 I need register and asks me this: "Last name of the CEO of Autodesk:" Reply???? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 27, 2016 Share Posted January 27, 2016 I need register and asks me this: "Last name of the CEO of Autodesk:"Reply???? Google is your friend. Quote Link to comment Share on other sites More sharing options...
CadFrank Posted January 27, 2016 Share Posted January 27, 2016 Google is your friend. Can Bing me my friend also? Quote Link to comment Share on other sites More sharing options...
robierzo Posted January 27, 2016 Author Share Posted January 27, 2016 O.K. Thank you very much for everything Lee. It's perfect. Thank you very much. Quote Link to comment Share on other sites More sharing options...
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.