TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: baitang36 on August 11, 2021, 02:25:49 AM

Title: AutoCAD 2008 and 2018's princ are different
Post by: baitang36 on August 11, 2021, 02:25:49 AM
The execution results of the following code under AutoCAD2008 and 2018 are different, and the generated file contents are different
Code - Auto/Visual Lisp: [Select]
  1. (setq fo (open "d:/tt.txt" "w"))
  2.  (princ (strcat "aaa" (chr 256) "bbb") fo)
  3.  (close fo)
In other words, the function princ of the higher version of autoCAD has been castrated,  princ has lost the ability to write binary data
Title: Re: AutoCAD 2008 and 2018's princ are different
Post by: It's Alive! on August 11, 2021, 03:04:37 AM
is the 2008 version you're testing with 64bit?
Title: Re: AutoCAD 2008 and 2018's princ are different
Post by: VovKa on August 11, 2021, 05:39:51 AM
In other words, the function princ of the higher version of autoCAD has been castrated,  princ has lost the ability to write binary data
i tested your code on acad2008 and the size of tt.txt is only 3 bytes
looks like my acad2008 is also 'castrated'

if you want to write 0 into the file then do it this way
Code: [Select]
(setq fo (open "d:/tt.txt" "w"))
    (foreach c '(97 97 97 256 98 98 98) (write-char c fo))
    (close fo)
or use 'ADODB.Stream'
Title: Re: AutoCAD 2008 and 2018's princ are different
Post by: baitang36 on August 11, 2021, 07:55:27 PM
In other words, the function princ of the higher version of autoCAD has been castrated,  princ has lost the ability to write binary data
i tested your code on acad2008 and the size of tt.txt is only 3 bytes
looks like my acad2008 is also 'castrated'

if you want to write 0 into the file then do it this way
Code: [Select]
(setq fo (open "d:/tt.txt" "w"))
    (foreach c '(97 97 97 256 98 98 98) (write-char c fo))
    (close fo)
or use 'ADODB.Stream'
thank you very much
Title: Re: AutoCAD 2008 and 2018's princ are different
Post by: baitang36 on August 11, 2021, 08:01:01 PM
In other words, the function princ of the higher version of autoCAD has been castrated,  princ has lost the ability to write binary data
i tested your code on acad2008 and the size of tt.txt is only 3 bytes
looks like my acad2008 is also 'castrated'

if you want to write 0 into the file then do it this way
Code: [Select]
(setq fo (open "d:/tt.txt" "w"))
    (foreach c '(97 97 97 256 98 98 98) (write-char c fo))
    (close fo)
or use 'ADODB.Stream'
After a test, this method can't write 10 to the file alone. It becomes 0D 0A .  one byte becomes two.
Code - Auto/Visual Lisp: [Select]
  1. (setq fo (open "d:/tt.txt" "w"))
  2.     (foreach c '(97 97 97 256 98 10 98) (write-char c fo))
  3.     (close fo)
  4.  
  5.  
Title: Re: AutoCAD 2008 and 2018's princ are different
Post by: mm_clover on August 12, 2021, 11:26:26 AM
0A=10,Hexadecimal?
Title: Re: AutoCAD 2008 and 2018's princ are different
Post by: VovKa on August 12, 2021, 03:38:28 PM
In other words, the function princ of the higher version of autoCAD has been castrated,  princ has lost the ability to write binary data
i tested your code on acad2008 and the size of tt.txt is only 3 bytes
looks like my acad2008 is also 'castrated'

if you want to write 0 into the file then do it this way
Code: [Select]
(setq fo (open "d:/tt.txt" "w"))
    (foreach c '(97 97 97 256 98 98 98) (write-char c fo))
    (close fo)
or use 'ADODB.Stream'
After a test, this method can't write 10 to the file alone. It becomes 0D 0A .  one byte becomes two.
we can fool autocad the same way we did with 0
Code: [Select]
(setq fo (open "d:/tt.txt" "w"))
(foreach c '(97 97 97 256 98 266 98) (write-char c fo))
(close fo)
Title: Re: AutoCAD 2008 and 2018's princ are different
Post by: baitang36 on August 13, 2021, 03:21:29 AM
Code: [Select]
(setq fo (open "d:/tt.txt" "w"))
(foreach c '(97 97 97 256 98 266 98) (write-char c fo))
(close fo)
ok
Title: Re: AutoCAD 2008 and 2018's princ are different
Post by: d2010 on August 13, 2021, 11:29:09 AM
Can you found other solution?
Write char by char, into file-disk, you slow-down 100% entire Win10, because
many AntivirusPrograms, contain Real-LiveWatch of HardDisk

Code: [Select]
(setq fo (open "d:/tt.txt" "w"))
(foreach c '(97 97 97 256 98 266 98) (write-char c fo))
(close fo)
ok
Title: Re: AutoCAD 2008 and 2018's princ are different
Post by: baitang36 on August 15, 2021, 09:35:57 AM
Can you found other solution?
Write char by char, into file-disk, you slow-down 100% entire Win10, because
many AntivirusPrograms, contain Real-LiveWatch of HardDisk
You mean, write many bytes at a time?.This may use the unpublished function of Acad, which can read and write binary files. The compiler in vlide is also implemented with lisp