Author Topic: hepl me ,Daniel  (Read 9872 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: hepl me ,Daniel
« Reply #15 on: January 05, 2010, 07:46:43 PM »
I honestly don't know what the problem would be. I have an ARX routine that you might try but it's for acad 2007-2009 wanna try it?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: hepl me ,Daniel
« Reply #16 on: January 05, 2010, 07:54:45 PM »
ONCE I USED AUTOCAD2008 TO RUN IT , IT ALSO FAILED!!!!!!!!



Both the VSLIDE and _readstream -> _writestream conversion work for me in AC2010 and AC2008
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

aicr317

  • Guest
Re: hepl me ,Daniel
« Reply #17 on: January 05, 2010, 07:57:47 PM »
WELL,THANK YOU!

IN THIS CASE,I THINK THE PROBLEM MAY BE IN THE "_WRITESTREAM",BECAUSE IT CREATED NEW FILE IS ONLY 0 KB! SO I THINK IT WIRTED INTO THE NEW FILE NOTHING!CAN YOU HELP ME CHECK IT (_WRITESTREAM)!!!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: hepl me ,Daniel
« Reply #18 on: January 05, 2010, 08:09:40 PM »
My readstream result is different to yours.
the first 18 values are the same,  after is different.
yours is 5792  characters
Mine is 7003 characters

Yours writes 16 characters.
Mine writes 7003 characters.

Try this :

(setq SlideText (vl-string->list (_readstream "D:\\bsph.sld" t)))

(_writestream "D:\\new.sld" (vl-list->string SlideText) "w")    

(command "._VSLIDE" "D:\\new.sld")

and reload the functions
Code: [Select]
;;; CodeHimBelonga MP fromTheSwamp
(defun _ReadStream ( path len / fso file stream result )

    ;;  If the file is successful read the data is returned as
    ;;  a string. Won't be tripped up by nulls, control chars
    ;;  including ctrl z (eof marker). Pretty fast (feel free
    ;;  to bench mark / compare to alternates).
    ;;
    ;;  If the caller wants the result as a list of byte values
    ;;  simply use vl-string->list on the result:
    ;;
    ;;      (setq bytes
    ;;          (if (setq stream (_ReadStream path len))
    ;;              (vl-string->list stream)
    ;;          )
    ;;      )            
    ;;
    ;;  Arguments:
    ;;
    ;;      path  <duh>
    ;;      len   Number of bytes to read. If non numeric, less
    ;;            than 1 or greater than the number of bytes in
    ;;            the file everything is returned.
    
    (vl-catch-all-apply
       '(lambda ( / iomode format size )
            (setq
                iomode   1 ;; 1 = read, 2 = write, 8 = append
                format   0 ;; 0 = ascii, -1 = unicode, -2 = system default
                fso      (vlax-create-object "Scripting.FileSystemObject")
                file     (vlax-invoke fso 'GetFile path)
                stream   (vlax-invoke fso 'OpenTextFile path iomode format)
                size     (vlax-get file 'Size)
                len      (if (and (numberp len) (< 0 len size)) (fix len) size)
                result   (vlax-invoke stream 'read len)
            )
            (vlax-invoke stream 'Close)
        )
    )
    
    (if stream (vlax-release-object stream))
    (if file (vlax-release-object file))
    (if fso (vlax-release-object fso))
    
    result

)


;;; CodeHimBelonga MP fromTheSwamp
(defun _WriteStream ( path text mode / fso stream file result )

    ;;  Return the file size if the file is successfully written
    ;;  to, otherwise nil. Will write all ascii chars to file
    ;;  including nulls. If the caller wants to pass a list of
    ;;  byte values to the function just call it like so:
    ;;
    ;;      (_WriteStream
    ;;          path
    ;;          (vl-list->string '(87 111 111 116 33))
    ;;          mode
    ;;      )
    ;;
    ;;  Arguments:
    ;;
    ;;      path  <duh>
    ;;      text  <duh>
    ;;      mode  "a" to create/append,
    ;;            "w" to create/overwrite (default)
    
    (setq mode (if (member mode '("a" "A")) "a" "w"))
    
    (vl-catch-all-apply
       '(lambda ( / format )
            (setq fso (vlax-create-object "Scripting.FileSystemObject"))
            (cond
                (   (or (null (findfile path)) (eq "w" mode))
                    (setq stream
                        (vlax-invoke
                            fso
                           'CreateTextFile
                            path
                           -1 ;; 0 (false) = don't overwrite , -1 (true) = overwrite
                            0 ;; 0 (false) = ascii, -1 (true) = unicode
                        )
                    )
                    (setq file (vlax-invoke fso 'GetFile path))
                )
                (   (setq file (vlax-invoke fso 'GetFile path))
                    (setq stream
                        (vlax-invoke
                            file
                           'OpenAsTextStream
                            8 ;; 1 = read, 2 = write, 8 = append
                            0 ;; 0 = ascii, -1 = unicode, -2 system default
                        )
                    )      
                )
            )
            (vlax-invoke stream 'Write text)
            (vlax-invoke stream 'Close)
            (setq result (vlax-get file 'Size))
        )
    )

    (if file (vlax-release-object file))
    (if stream (vlax-release-object stream))
    (if fso (vlax-release-object fso))
    
    result
    
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

aicr317

  • Guest
Re: hepl me ,Daniel
« Reply #19 on: January 05, 2010, 08:30:23 PM »
_$ (setq SlideText (vl-string->list (_readstream "D:\\bsph.sld" t)))

(_writestream "D:\\new.sld" (vl-list->string SlideText) "w") (command "._vslide" "d:\\new.sld")
;;ERROR, function canceled

what version of cad are you useing?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: hepl me ,Daniel
« Reply #20 on: January 05, 2010, 08:40:08 PM »
_$ (setq SlideText (vl-string->list (_readstream "D:\\bsph.sld" t)))

(_writestream "D:\\new.sld" (vl-list->string SlideText) "w") (command "._vslide" "d:\\new.sld")
;;ERROR, function canceled

what version of cad are you useing?


Both the VSLIDE and _readstream -> _writestream conversion work for me in AC2010 and AC2008


At the moment I can't think of any cause for your problem.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

aicr317

  • Guest
Re: hepl me ,Daniel
« Reply #21 on: January 05, 2010, 08:44:33 PM »
anyway,thank you for your help!

can you show your readstream result ?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: hepl me ,Daniel
« Reply #22 on: January 05, 2010, 08:50:27 PM »
anyway,thank you for your help!

can you show your readstream result ?

sure !

See attached :
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

aicr317

  • Guest
Re: hepl me ,Daniel
« Reply #23 on: January 05, 2010, 09:12:42 PM »
i try use your readstream result to set a list like this:
(setq aaa '(your result))
and _writestream ,the new.sld also 0kb!

i found my readstream different from yours,why ,didn't know!!!hoho!!!
may be the readstream and writestream is not work well on my machine!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: hepl me ,Daniel
« Reply #24 on: January 05, 2010, 09:27:23 PM »
Wild guess, could the language be affecting this?
Could the operating system play a role?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

aicr317

  • Guest
Re: hepl me ,Daniel
« Reply #25 on: January 05, 2010, 09:30:34 PM »
cab, i think so

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: hepl me ,Daniel
« Reply #26 on: January 05, 2010, 09:30:53 PM »
Try this

Download the MyTools.zip from this post
http://www.theswamp.org/index.php?topic=21875.msg264050#msg264050
load the ARX for your cad version i.e CrpARX16.arx
then test


(defun c:test ( /  a)
 (setq a (crpbinget "c:\\Drawing1.sld" ))
 (crpbinput "c:\\New.sld" a )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: hepl me ,Daniel
« Reply #27 on: January 05, 2010, 09:39:12 PM »
Might want to give another format type a try. -1 or -2
Code: [Select]
format   0 ;; 0 = ascii, -1 = unicode, -2 = system default
It is hard coded in the _WriteStream
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

aicr317

  • Guest
Re: hepl me ,Daniel
« Reply #28 on: January 05, 2010, 09:45:32 PM »
daniel,i try the test,it work very well,

but i want pack the arx into lisp,

first,I want lisp created new file ,example ,"111.arx"
AND (ARXLOAD "111.ARX")
then,used binget and binput function,how can i do?

so i think the readstream and writesteam fit me!!!HOHO!!!

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8702
  • AKA Daniel
Re: hepl me ,Daniel
« Reply #29 on: January 05, 2010, 09:48:23 PM »
Sorry, I don't know  :|