Need iLogic code to open and read word document

Need iLogic code to open and read word document

Anonymous
Not applicable
1,280 Views
5 Replies
Message 1 of 6

Need iLogic code to open and read word document

Anonymous
Not applicable

Hi

We always have different paint specifications from our clients.

I would like all our draftmen to place the same specification from the same doc file.

It could be easier if we could juste right click on an iLogic code and run it.

 

I'm looking for a code wich can goes on the drawing directory, open the word document and paste it in a simple annotation text.

Let say the file's name is PAINT SPEC.doc

 

Thanks

0 Likes
Accepted solutions (1)
1,281 Views
5 Replies
Replies (5)
Message 2 of 6

MechMachineMan
Advisor
Advisor

Look into:

  • CreateObject("Word.Application")
  • GetObject("", "Word.Application")
  • GetObject(,"Word.Application")

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 6

Anonymous
Not applicable

Hi

I won't be able to do this by myself.

I have this part of code but it's not good.

 

SyntaxEditor Code Snippet

'get the text file
'expects to find text file in same folder as 
'the current file
oWrdFile = ThisDoc.Path & "\" & "Paint Spec.docx"

'read the file
oRead = System.IO.File.OpenText(oWrdFile)
EntireFile = oRead.ReadToEnd()
oRead.Close()

oSheet = ThisDoc.Document.Sheets(1)

oGenNotes = oSheet.DrawingNotes.GeneralNotes

Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

oGenNotes.AddFitted(oTG.CreatePoint2d(3, 18), EntireFile)

I dont get the good text.

 

Can someone help please?

 

 Thanks

0 Likes
Message 4 of 6

MechMachineMan
Advisor
Advisor

I have not debugged this or tried it out, but it should be pretty close.

 

'Use late binding to access word to read through lines in a document
'MechMachineMan - March 2017

Sub Main()
Dim wdApp As Object
wdApp = CreateObject("Word.Application")

wdDoc = wdApp.Documents.Open("C:\WordFile.doc")
Call ParseLines()

Call wdDoc.Close(SaveChanges:= False)

wdApp.Quit
End Sub

Private wdDoc As Object

Public
Sub ParseLines()
Dim singleLine As Paragraph
Dim lineText As String

For Each singleLine In wdDoc.Paragraphs
lineText
= singleLine.Range.Text
MsgBox(lineText)

'// parse the text here...
Next
End Su
b   

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 6

Anonymous
Not applicable

Hi MMM

Close but not working.

It return this message "Error on Line 18 : Type 'Paragraph' non défini." (french)

 

Also my word document will always be in the same directory as my drawing and not at a stationnary directory.

It would be great if the code could search for my file in the drawing directory.

 

Maybe I ask to much but can it be possible to create the text every time at the same place with a coordonate on the drawing.

 

Thank you very much

0 Likes
Message 6 of 6

Anonymous
Not applicable
Accepted solution

Hi again MMM

I juste tryed something and it looks good.

You know the code I posted before yours, I just changed my word file for a text file and It is working.

 

If it could open a word document instead it will be great.

 

Thanks

0 Likes