Reading a word document

Discussion in 'AutoCAD' started by Michel, Apr 15, 2005.

  1. Michel

    Michel Guest

    Hi to all,

    I had a request from several AutoCAD users here in the company. They
    want a routine that can read a word document, and import it as a Mtext
    entity in the
    AutoCAD drawing.

    I can open the document and read all the lines...but no indentations
    are import, neither the numbers or bullets...Does somebody can guide
    me through the vla-property, so i can find all theses indentations ??
    here is my codes that reads the doc and put it in the drawing. feel
    free to use it.

    Tia
    Michel

    ;;;Open a word document
    (defun Open-Word (xfile dmode / appsession)
    (princ "\nOuverture du document Word...")
    (cond
    ( (setq fn (findfile xfile))
    (cond
    ((setq appsession (vlax-get-or-create-object
    "Word.Application"))
    (vlax-invoke-method
    (vlax-get-property appsession 'Documents)
    'Open fn
    )
    (if (= (strcase dmode) "SHOW")
    (vla-put-visible appsession 1)
    (vla-put-visible appsession 0)
    )
    )
    )
    )
    ( T (alert (strcat "\nCannot find the source file: " xfile)) )
    )
    (princ)
    )

    ;;;Close the document
    (defun Word-Quit ()
    (cond
    ( (not (vlax-object-released-p appsession))
    (vlax-invoke-method appsession 'QUIT)
    (vlax-release-object appsession)
    )
    )
    (princ)
    )

    ;;;import in AutoCAD
    (defun c:Word2Acad ( / )
    (if (not (member "doslib16.arx" (arx)))
    (arxload "doslib16")
    )
    (setq fichier (dos_getfiled "Choose a Word document" (getvar
    "dwgprefix")
    "Documents Word (*.doc)|*.doc|Rich text
    format (*.rtf)|*.rtf|Fichier Ascii (*.txt)|*.txt|Tous les
    fichiers(*.*)|*.*||"))
    (if fichier
    (progn
    (if (open-word fichier "hide")
    (progn
    (setq Selection (vlax-get-property appsession 'selection))
    (setq TheDocument (vlax-get-property Selection 'document))
    (setq Sentences (vlax-get-property TheDocument 'sentences))
    (setq string nil)
    (vlax-for for-item
    Sentences
    (if (= (vlax-get-property for-item 'Underline) 1)
    (setq string (append string (list (strcat "{\\L"
    (vlax-get-property for-item 'text)))))
    (setq string (append string (list (vlax-get-property
    for-item 'text))))
    )
    )
    (setq cont 0)
    (repeat (length string1)
    (setq string (subst (substr (nth cont string) 1 (- (strlen
    (nth cont string)) 1)) (nth cont string) string))
    (if (dos_strreversefind (nth cont string) "\r")
    (setq string (subst (dos_strreplace (nth cont string)
    "\r" "\\P") (nth cont string) string))
    )
    (if (= (substr (nth cont string) 1 1) "{")
    (setq string (subst (strcat (nth cont string) "}") (nth cont
    string) string))
    )
    (setq cont (+ 1 cont))
    )
    (setq largeur (* 70 (getvar "textsize")))
    (setq p1 (getpoint "\nUpper left corner of text:"))
    (command "_-mtext" p1 "_w" largeur )
    (setq cont 0)
    (repeat (length string)
    (command (nth cont string))
    (setq cont (+ 1 cont))
    )
    (command "")
    (Word-Quit)
    )
    )
    )
    )
    (princ)
    )
     
    Michel, Apr 15, 2005
    #1
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.