Reading a word document
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Reading a word document
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization

Author Message
Michel
Guest





Posted: Fri Apr 15, 2005 3:26 pm    Post subject: Reading a word document Reply with quote

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)
)

Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> Customization All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Access Forum - Microsoft Office Forum - Electronics

Contact Us Powered by phpBB