Write to embedded text file in IDW?

Write to embedded text file in IDW?

DRoam
Mentor Mentor
976 Views
7 Replies
Message 1 of 8

Write to embedded text file in IDW?

DRoam
Mentor
Mentor

I'd like to have my add-in write the actions that it performs on a Drawing file to a log file stored within the drawing itself. I'm having a hard time figuring out how to do so.

 

If found this: Mfg DevBlog: Read / Write embedded file, but it seems overly complicated. I'm hoping someone knows of a simpler way?

 

I need the add-in to create the log file as well as write (append) to it.

0 Likes
Accepted solutions (1)
977 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor

What kind of information would you like to write the text file?

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 8

bradeneuropeArthur
Mentor
Mentor

With this piece of code you can create the txt file and add it to the drawing...

 

Public Sub AttchAddToDwg()

Dim oDrawingDwgdoc As DrawingDocument
Set oDrawingDwgdoc = ThisApplication.ActiveDocument

Dim InvFilelocation As String
InvFilelocation = oDrawingDwgdoc.FullFileName

Dim InvFileName As String
InvFileName = oDrawingDwgdoc.DisplayName
           
                    Dim CompleteSendPathPartlistXls As String
                    CompleteSendPathPartlistXls = "File path and .txt"

    ' Referenceto a Other to be linked document.
    Dim objDocument As DrawingDocument
    Set objDocument = ThisApplication.ActiveDocument
    
    Dim objReferenceOLE As ReferencedOLEFileDescriptor

                'Set objReferenceOLE = objDocument.ReferencedOLEFileDescriptors.Add(CompleteSendpathPdf)

                Set objReferenceOLE = objDocument.ReferencedOLEFileDescriptors.Add(CompleteSendPathPartlistXls)


        

End Sub 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 8

DRoam
Mentor
Mentor

Just the things my add-in is doing as it processes things about the drawing. Things like:

 

 

Filled in "Drawing #" iProperty for "Part X.ipt"
Filled in "Title" prompted entry in Title Block on Sheet 2
Toggled visibility of (3) rows in Parts List on Sheet 2.

 

 

The purpose is mainly for verification and tracking. The designer can look back through the log to see what the add-in changed and when, relative to each time the drawing has been printed.

 

Your code is a good start. Is there any way to read the embedded file? Perhaps by saving it back as a text file again first?

 

I don't want to create a new log file every time the update command runs. I want to either append to the existing file, or copy it, append the new log lines, then delete the original and re-save.

0 Likes
Message 5 of 8

DRoam
Mentor
Mentor

Actually, I think I came up with a simpler way to do this. I think what I may do is just store the log in a String attribute of the drawing document object. Then I'll just make a simple Windows Form to display the log in a text field, and add a command to display the form. This will be cleaner than adding the embedded file anyway.

0 Likes
Message 6 of 8

JelteDeJong
Mentor
Mentor
Accepted solution

You could also save the text in a attribute of the file. here an example (in a ilogic rule)

Public Class ThisRule
	
	Private Log As String
	Private doc As Document
	
	Sub Main()
	
		doc = ThisApplication.ActiveDocument
	
		loadLog()
	
		writeToLog("Test 1")
		writeToLog("Test 2")
	
		writeLogToFile("c:\temp\log.txt")
	
	End Sub
	
	Private Sub writeToLog(text As String)
		Log = Log + text + System.Environment.NewLine
		saveLog()
	End Sub
	
	Private Sub loadLog()
		If (doc.AttributeSets.NameIsUsed("log")) Then
			Dim attSet As AttributeSet = doc.AttributeSets.Item("log")
			Dim attLines As Attribute = attSet.Item("Lines")
			Log = attLines.Value
		Else
			Log = ""
		End If
	End Sub
	
	Private Sub saveLog()
		If (doc.AttributeSets.NameIsUsed("log")) Then
			Dim attSet As AttributeSet = doc.AttributeSets.Item("log")
			Dim attLines As Attribute = attSet.Item("Lines")
			attLines.Value = Log
		Else
			Dim attSet As AttributeSet = doc.AttributeSets.Add("log")
			Dim attLines As Attribute = attSet.Add("Lines", ValueTypeEnum.kStringType, Log)
		End If
	End Sub
	
	Private Sub writeLogToFile(path As String)
		System.IO.File.AppendAllText(path, Log)
	End Sub
End Class

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 7 of 8

DRoam
Mentor
Mentor

Lol, talk about timing. At the very least you saved me some time working out the details. Thanks @JelteDeJong, will mark your answer as the solution.

0 Likes
Message 8 of 8

JelteDeJong
Mentor
Mentor

Great minds think alike, and as it turns out in the same minute

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

0 Likes