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.
Solved! Go to Solution.
Solved by matt_jlt. Go to Solution.
Solved by JelteDeJong. Go to Solution.
Solved by jjstr8. Go to Solution.
Solved by WCrihfield. Go to Solution.
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
(Not an Autodesk Employee)
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.
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.
Blog: hjalte.nl - github.com
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.
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.