Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Embed wordpad file via API?

CAD_CAM_MAN
Advocate

Embed wordpad file via API?

CAD_CAM_MAN
Advocate
Advocate

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

 

0 Likes
Reply
Accepted solutions (4)
895 Views
6 Replies
Replies (6)

WCrihfield
Mentor
Mentor
Accepted 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

EESignature

(Not an Autodesk Employee)

jjstr8
Collaborator
Collaborator
Accepted solution

 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.

JelteDeJong
Mentor
Mentor
Accepted solution

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

jjstr8
Collaborator
Collaborator
An iLogic-savy user to the rescue!
0 Likes

matt_jlt
Collaborator
Collaborator
Accepted solution

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.

CAD_CAM_MAN
Advocate
Advocate

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! 

0 Likes