Jump to content

null character


potencjalek

Recommended Posts

i try to export data do external application from Autocad

i have one problem

i cannot create proper null character for that file

i need null character for determine end of string in that file

function

(write-line (strcat "text" (chr 256)))

doesn't create null sign on the end of line

attached file i want to create (please open it by notepad++ to see null character)

is it possible to create such a file by lisp?

null_charakter.txt

Link to comment
Share on other sites

Try the following

[color=GREEN];; Null Character Example by Lee Mac 2014-01-12[/color]
([color=BLUE]defun[/color] nullchartest ( str txt [color=BLUE]/[/color] fso stm )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] fso ([color=BLUE]vlax-create-object[/color] [color=MAROON]"scripting.filesystemobject"[/color]))
       ([color=BLUE]progn[/color]
           ([color=BLUE]vl-catch-all-apply[/color]
              '([color=BLUE]lambda[/color] ( )
                   ([color=BLUE]setq[/color] stm ([color=BLUE]vlax-invoke[/color] fso 'createtextfile txt -1 0))
                   ([color=BLUE]vlax-invoke[/color] stm 'write ([color=BLUE]strcat[/color] str ([color=BLUE]chr[/color] 256)))
                   ([color=BLUE]vlax-invoke[/color] stm '[color=BLUE]close[/color])
               )
           )
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'vla-object ([color=BLUE]type[/color] stm))
               ([color=BLUE]vlax-release-object[/color] stm)
           )
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'vla-object ([color=BLUE]type[/color] fso))
               ([color=BLUE]vlax-release-object[/color] fso)
           )
           ([color=BLUE]findfile[/color] txt)
       )
   )
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Test program:

([color=BLUE]defun[/color] c:test ( )
   (nullchartest [color=MAROON]"line-text"[/color] ([color=BLUE]vl-filename-mktemp[/color] [color=MAROON]"test"[/color] ([color=BLUE]getvar[/color] 'dwgprefix) [color=MAROON]".txt"[/color]))
)

Link to comment
Share on other sites

When you write a normal line of text if you hex dump it it will actually have two codes as end of string OD & OA this is carriage return & line feed. Can you not check for these codes if your reading the file like a database and 1 character at a time. If I remember correct is (chr 13)

Link to comment
Share on other sites

Try the following

[color=GREEN];; Null Character Example by Lee Mac 2014-01-12[/color]
([color=BLUE]defun[/color] nullchartest ( str txt [color=BLUE]/[/color] fso stm )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] fso ([color=BLUE]vlax-create-object[/color] [color=MAROON]"scripting.filesystemobject"[/color]))
       ([color=BLUE]progn[/color]
           ([color=BLUE]vl-catch-all-apply[/color]
              '([color=BLUE]lambda[/color] ( )
                   ([color=BLUE]setq[/color] stm ([color=BLUE]vlax-invoke[/color] fso 'createtextfile txt -1 0))
                   ([color=BLUE]vlax-invoke[/color] stm 'write ([color=BLUE]strcat[/color] str ([color=BLUE]chr[/color] 256)))
                   ([color=BLUE]vlax-invoke[/color] stm '[color=BLUE]close[/color])
               )
           )
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'vla-object ([color=BLUE]type[/color] stm))
               ([color=BLUE]vlax-release-object[/color] stm)
           )
           ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'vla-object ([color=BLUE]type[/color] fso))
               ([color=BLUE]vlax-release-object[/color] fso)
           )
           ([color=BLUE]findfile[/color] txt)
       )
   )
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Test program:

([color=BLUE]defun[/color] c:test ( )
   (nullchartest [color=MAROON]"line-text"[/color] ([color=BLUE]vl-filename-mktemp[/color] [color=MAROON]"test"[/color] ([color=BLUE]getvar[/color] 'dwgprefix) [color=MAROON]".txt"[/color]))
)

works perfectly for me

thank you very much

i think its time to donate your website :D

Link to comment
Share on other sites

one more question

i tried to change little bit your function to write more then one line

(defun nullchartest ( str 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 (strcat str (chr 256)))
                   (vlax-invoke stm 'write (strcat "text for line 2" (chr 256)))   ;;;;;changes
                   (vlax-invoke stm 'close)
               )
           )
           (if (= 'vla-object (type stm))
               (vlax-release-object stm)
           )
           (if (= 'vla-object (type fso))
               (vlax-release-object fso)
           )
           (findfile txt)
       )
   )
)

but in results it write only one (first) line, why is that?

Link to comment
Share on other sites

ok, topic closed

i figured it out

i forgot about

(vlax-invoke stm 'write (chr 10))  ;;; starting next line

between lines

 

thanks you all for help

Link to comment
Share on other sites

works perfectly for me

thank you very much

i think its time to donate your website :D

 

Excellent, I'm glad it works as required.

Thank you also for your kind offer of a donation, I appreciate it :)

 

but in results it write only one (first) line, why is that?

 

As you have gathered, a carriage return & line feed are required for a new line:

;; Null Character Example by Lee Mac 2014-01-14
(defun nullchartest ( 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
                       (strcat
                           "This is line 1"     (chr 256)
                           "\r\nThis is line 2" (chr 256)
                       )
                   )
                   (vlax-invoke stm 'close)
               )
           )
           (if (= 'vla-object (type stm))
               (vlax-release-object stm)
           )
           (if (= 'vla-object (type fso))
               (vlax-release-object fso)
           )
           (findfile txt)
       )
   )
)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...