Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Embed wordpad file via API?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
CAD_CAM_MAN
821 Views, 6 Replies

Embed wordpad file via API?

Running Inventor Professional 2022.2

 

I would like to add / attach a text file to automatically created part files to hold some metadata.

 

Is it possible to create / embed and write to a wordpad file with the API? The screen shot below shows the "manual" workflow to get what I am ideally after (less writing to the file).

 

I am having difficulty finding anything in the admapi reference. Can anybody provide some examples of how to create an embedded wordpad file and write to that file? 

 

Other ideas on embedding /attaching metadata in a text file format to a part model would be welcome as well.

 

CAD_CAM_MAN_0-1642009108409.png

 

6 REPLIES 6
Message 2 of 7
WCrihfield
in reply to: CAD_CAM_MAN

One thought would be to use a Microsoft.Windows.Forms.RichTextBox object, and its various methods, to create the file, then the usual Document.ReferencedOLEFileDescriptors.Add method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7
jjstr8
in reply to: CAD_CAM_MAN

 If you can live with basic text, creating and embedding a text file is pretty simple.  Here's a quick VBA example.

Public Sub EmbedTest()

Dim fileSys As FileSystemObject
Dim embedFile As TextStream

Set fileSys = New FileSystemObject
Set embedFile = fileSys.CreateTextFile("C:\temp\myTestFile.txt")
embedFile.WriteLine ("First line of text")
embedFile.WriteLine ("Second line of text")
embedFile.Close
ThisApplication.ActiveDocument.ReferencedOLEFileDescriptors.Add "C:\temp\myTestFile.txt", kOLEDocumentEmbeddingObject

End Sub

I'm not sure what code environment you're doing this in, but an add-in might let you do something like @WCrihfield  described, where you create the RTF object then stream to a file for embedding in the Inventor document.

 

One method I've used when I don't want information to be readily available to the end-user is adding it under the AttributeSets collection.

Message 4 of 7
JelteDeJong
in reply to: jjstr8

you can create and save RTF files like this in an iLogic rule.

 

imports System.Windows.Forms
Dim doc As PartDocument = ThisApplication.ActiveDocument

Dim tempFileName = IO.Path.GetTempFileName()
tempFileName = IO.Path.ChangeExtension(tempFileName, "rtf")

Using RTB As New RichTextBox
    RTB.Rtf = "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard This is {\b bold} text.\par} "
    RTB.SaveFile(tempFileName, RichTextBoxStreamType.RichText)
End Using

Dim refDoc = doc.ReferencedOLEFileDescriptors.Add(tempFileName, OLEDocumentTypeEnum.kOLEDocumentEmbeddingObject)
refDoc.DisplayName = "Foo Bar"
IO.File.Delete(tempFileName

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 7
jjstr8
in reply to: JelteDeJong

An iLogic-savy user to the rescue!
Message 6 of 7
matt_jlt
in reply to: CAD_CAM_MAN

Not sure what your meta-data is exactly and how much info you are storing, but you could also look at using attribute sets instead of embedding an object. That way its all structured / easy to query and you dont have to deal with an embedded file.

Message 7 of 7
CAD_CAM_MAN
in reply to: CAD_CAM_MAN

Thank you to everybody that responded. All work. I believe the attribute set option suggested by matt_jlt will suit this project best. I did not realize such an object existed. 🤔 This opens some doors! 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report