How can I package a .txt file in a VLX?

Discussion in 'AutoCAD' started by Steve Adams, Mar 6, 2005.

  1. Steve Adams

    Steve Adams Guest

    Hello Everybody,

    I would like to be able retreive the entire text content of a text file. I
    should be able to do this with:

    (vl-get-resource text-file)
    (Returns the text stored in a .txt file packaged in a VLX )

    But first I have to package it.

    How could I package "c:\3.txt"?
     
    Steve Adams, Mar 6, 2005
    #1
  2. Steve Adams

    ECCAD Guest

    Steve,
    I believe that the context of 'packaged in a VLX', means
    that the 'text' file is 'included' in the over-all set of files
    that accompany your VLX 'application'. It does not 'mean'
    that it is 'included' (inside) the VLX..just a support file that
    you must distribute with your application.
    In your application, you could 'view' that file in Notepad by
    VB or VLisp - calling up Notepad, and feed in the path/file
    to 'open'.

    Bob
     
    ECCAD, Mar 6, 2005
    #2
  3. Steve Adams

    Steve Adams Guest

    Thanks Bob.

    Is there another way to "copy" the text contents, say to the clipboard?

    I want to "add" the contents of "3.txt", into an existing mtext entity in my
    dwg. Currently, to do this I am:

    Inserting (using a menu macro) an rtext entity with the contents of "3.txt",
    and then exploding it.

    Then I open the mtext string in my mtext editor, and copy the text contents
    to the clipboard

    Then I open the mtext entity in dwg that I want to insert those text
    contents, and paste them from the clipboard

    Any way to automatically send the contents of "3.txt" to the clipboard,
    and save me a step?

    Thanks,
    Steve
     
    Steve Adams, Mar 6, 2005
    #3
  4. Have you tried using the expert mode found here?

    Vlide -> File -> Make Applicattion

    Just follow the prompts. Be sure and specify
    the type of file to include as a resource
     
    Jason Piercey, Mar 6, 2005
    #4
  5. Steve Adams

    Jeff Mishler Guest

    How about this?:

    Code:
    (defun import_txt (fname / fil txt txt_line)
    (if (setq fname (findfile fname))
    (progn
    (setq fil (open fname "r")
    txt "")
    (while (setq txt_line (read-line fil))
    (setq txt (strcat txt "\\P" txt_line))
    ;;the "\\P" inserts a line break, remove
    ;; if you want a continuous string
    )
    )
    )
    (if txt
    txt
    ""
    )
    )
    
    (defun c:add2mtxt (/ ss ent txt newtxt)
    (if (setq ss (ssget ":S" '((0 . "MTEXT"))))
    (progn
    (vl-load-com)
    (setq ent (vlax-ename->vla-object (ssname ss 0))
    txt (vla-get-textstring ent)
    newtxt (strcat txt "\\P" (import_txt "c:\\3.txt"))
    )
    (vla-put-textstring ent newtxt)
    )
    )
    (princ)
    )
    
     
    Jeff Mishler, Mar 6, 2005
    #5
  6. Steve Adams

    Steve Adams Guest

    Thanks Jason.

    *That is the answer* to my original post.

    But I think now I realize what I need to do, is to be able to copy the all
    of contents of "3.txt" to clipboard, programatically.

    I'm not sure how to do that.
     
    Steve Adams, Mar 6, 2005
    #6
  7. Steve Adams

    Steve Adams Guest

    Jeff,

    I did not see your post until after I answered Jason.

    Thank you, that works great!

    I appreciate it.

    Steve

     
    Steve Adams, Mar 6, 2005
    #7
  8. Steve Adams

    ECCAD Guest

    Steve,
    This seems to work.
    (defun text2mtext ( text )
    (setq P1 (Getpoint "\nMtext Upper Left corner:"))
    (setq P2 (Getcorner P1 "\nLower Right corner:"))
    (command "_mtext" P1 P2 ".." ""); blank
    (setq en (entlast))
    (setq ent (entget en))
    (entmod (setq ent (subst (cons 1 text)(assoc 1 ent) ent)))
    (princ)
    ); function

    ;; Get the file to import, read it into memory
    (setq txt_file "")
    (setq txt_file (getfiled "Select Text File" "" "txt" 2))
    (if (/= txt_file "")
    (progn
    (setq txt "")
    (setq ifil (open txt_file "r"))
    (while (setq txtin (read-line ifil))
    (setq txt (strcat txt txtin "\\P"))
    ); while
    (setq txt (strcat txt ""))
    (close ifil)
    ); progn
    ); if
    (if (and (/= txt "")(/= txt_file ""))
    (text2mtext txt); call function to load Mtext with the text
    ); if
    (princ)

    You could read-in the file directly..
    (setq txt_file "c:/3.txt")
    (open txt_file "r")
    ........
    then call the function.

    Bob
     
    ECCAD, Mar 6, 2005
    #8
  9. Steve Adams

    Steve Adams Guest

    Thanks Bob.

    Steve
     
    Steve Adams, Mar 6, 2005
    #9
  10. Steve Adams

    Jeff Mishler Guest

    Hi Steve,
    you're welcome......however I should warn you that I forgot to include one
    very important line that may make your 3.txt unaccessable......
    Add (close fil) to the code just after the while loop:

    (while (setq txt_line (read-line fil))
    (setq txt (strcat txt "\\P" txt_line))
    ;;the "\\P" inserts a line break, remove
    ;; if you want a continuous string
    )
    (close fil)

    Sorry 'bout that!
    --
    Jeff
    check out www.cadvault.com
     
    Jeff Mishler, Mar 6, 2005
    #10
  11. Steve Adams

    Steve Adams Guest

    Thanks, Jeff.


     
    Steve Adams, Mar 6, 2005
    #11
  12. Maybe DOSLIB is a good start... it includes functions specific for what you want...
     
    Luis Esquivel, Mar 7, 2005
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.