TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: cjw on October 30, 2009, 12:19:50 AM

Title: Using "ADODB.Stream" Read/Write stream
Post by: cjw on October 30, 2009, 12:19:50 AM
Read / Write Stream
http://www.theswamp.org/index.php?topic=17465.msg210365
The "Scripting.FileSystemObject" can't  write stream.
(vlax-invoke stream 'Write text) ->return nil.

So i try to use "ADODB.Stream"
But also have something wrong with "write"

May be this link could give you some ideas.
http://www.motobit.com/tips/detpg_read-write-binary-files/
Code: [Select]
(defun CJW-STREAMREAD (FILENAME / ADODB TEXT)
  (vl-catch-all-apply
    '(lambda ()
       (setq ADODB (vlax-get-or-create-object "ADODB.Stream"))
       (if (= (vlax-get-property ADODB 'STATE) 1)
(vlax-invoke ADODB 'close)
       )
       ;;adTypeBinary =1  读写流的格式为二进制
       (vlax-put-property ADODB 'type 1)
       ;;打开流
       (vlax-invoke ADODB 'open)
       ;;加载文件
       (vlax-invoke ADODB 'LOADFROMFILE FILENAME)
       ;;重置指针
       (vlax-put-property ADODB 'POSITION 0)
       ;;读取流
       (setq VAR (vlax-invoke-method
  ADODB
  'read
  (vlax-get ADODB 'SIZE)
)
       )
       ;;重置指针
       (vlax-put-property ADODB 'POSITION 0)
       ;;以二进制格式写入文件流
       (vlax-invoke-method ADODB 'WRITE VAR)
       ;;重置指针
       (vlax-put-property ADODB 'POSITION 0)
       ;;adTypeText =2   读写流的格式为字符串
       (vlax-put-property ADODB 'type 2)
       ;;代码类型
       (vlax-put-property ADODB 'CHARSET "us-ascii")
       ;;以字符串格式读取流
       (setq TEXT (vlax-invoke ADODB 'READTEXT))
       ;;关闭流
       (vlax-invoke ADODB 'close)
     )
  )
  (and ADODB (vlax-release-object ADODB))
  TEXT
)

(defun CJW-STREAMWRITE (PATH TEXT / ADODB)
  (vl-catch-all-apply
    '(lambda ()
       (setq ADODB (vlax-create-object "ADODB.Stream"))
       (if (= (vlax-get-property ADODB 'STATE) 1)
(vlax-invoke ADODB 'close)
       )
       ;;打开流
       (vlax-invoke ADODB 'open)
       ;;adTypeText =2   读写流的格式为字符串
       (vlax-put-property ADODB 'type 2)
       ;;代码类型
       (vlax-put-property ADODB 'CHARSET "us-ascii")
       ;;重置指针
       (vlax-put-property ADODB 'POSITION 0)
       ;;以字符串格式写入流
       (vlax-invoke ADODB 'WRITETEXT TEXT)
       ;;保存文件
       (vlax-invoke ADODB 'SAVETOFILE PATH 2)
       ;;关闭流
       (vlax-invoke ADODB 'close)
     )
  )
  (and ADODB (vlax-release-object ADODB))
)

(defun C:TT ()
  (setq TEXT (CJW-STREAMREAD "C:\\ARC.SLD"))
  (CJW-STREAMWRITE "c:\\NEW.SLD" TEXT)
  (princ)
)

Can't return the right file.
Wishing for a good solution!!!
Thanks!!!
Title: Re: Using "ADODB.Stream" Read/Write stream
Post by: CAB on October 30, 2009, 12:34:32 AM
Have you read this thread?
http://www.theswamp.org/index.php?topic=10101.0
Title: Re: Using "ADODB.Stream" Read/Write stream
Post by: cjw on October 30, 2009, 04:44:47 AM
Have you read this thread?
http://www.theswamp.org/index.php?topic=10101.0

No,CAB
Thank you~
Nice code.
I have to pay 2 days to understand it.
Title: Re: Using "ADODB.Stream" Read/Write stream
Post by: cjw on November 01, 2009, 10:25:20 PM
After After thinking long time.
Have no good result.
The result is in sight,but i can't catch it. so hard. :-(
Please give me favor!!!