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

Hi,

Its an older post but maybe I get an answer here.

I used the rule above to attache pdf/stp/dxf exports to the file. It works fine.

 

My problem is the following.

When I change something on the drawing i will export the files again and it will automaticlly update the export-files always the same location. With my current rule it always adds new links in the 3rd party section. Can i add a command to the rule which is looking if these Reference is already existing, if so then just cancel and don't add new links?

 

Option Explicit On

Option Explicit On
Sub Main()
	
	'current document
	Dim doc As Inventor.Document = ThisDoc.Document
	
	'Verify the current document has been saved.
	If doc.FullFileName = "" Then
		MessageBox.Show("This document must be saved first.")
		Exit Sub
	End If
	
	'default folder
	Dim FolderName As String  = Left$(doc.FullFileName, InStrRev(doc.FullFileName, "\") )	
	Dim selectedfile As String = String.Empty
	Dim selectedfile2 As String = String.Empty
	Dim selectedfile3 As String = String.Empty
	Dim oFileDlg As Inventor.FileDialog = Nothing
	InventorVb.Application.CreateFileDialog(oFileDlg)
	'oFileDlg.Filter = "Dwg files (*.dwg)|*.dwg|Excel files (*.xlsx)|*.xlsx|pdf files (*.pdf)|*.pdf|Inventor parts (*.ipt)|*.ipt|Inventor iFeatures (*.ide)|*.ide|Other files (*.*)|*.*"
	'oFileDlg.InitialDirectory = FolderName
	'oFileDlg.CancelError = True
	'oFileDlg.MultiSelectEnabled = True
	
	Try
		'oFileDlg.ShowOpen()
		selectedfile = "C:\Vault_WORK\TC_VAULT\DOCUMENTS\KS US\00_EXPORT-2D\" & ThisDoc.FileName(False) & ".pdf"
		selectedfile2 = "C:\Vault_WORK\TC_VAULT\DOCUMENTS\KS US\00_EXPORT-2D\" & ThisDoc.FileName(False) & ".dxf"
		selectedfile3 = "C:\Vault_WORK\TC_VAULT\DOCUMENTS\KS US\00_EXPORT-2D\" & ThisDoc.FileName(False) & ".stp"
	Catch
		Return  'operation was cancelled by the user
	End Try
	AddReferences(doc, selectedfile)
	AddReferences2(doc, selectedfile2)
	AddReferences3(doc, selectedfile3)
End Sub
Public Sub AddReferences(ByVal odoc As Inventor.Document, ByVal selectedfile As String)
	Dim oleReference As ReferencedOLEFileDescriptor
		oleReference = odoc.ReferencedOLEFileDescriptors _
				.Add(selectedfile,OLEDocumentTypeEnum.kOLEDocumentLinkObject)
		oleReference.BrowserVisible = True
		oleReference.Visible = False
		oleReference.DisplayName = Mid$(selectedfile, InStrRev(selectedfile, "\") + 1)
End Sub
Public Sub AddReferences2(ByVal odoc As Inventor.Document, ByVal selectedfile2 As String)
	Dim oleReference As ReferencedOLEFileDescriptor
		oleReference = odoc.ReferencedOLEFileDescriptors _
				.Add(selectedfile2,OLEDocumentTypeEnum.kOLEDocumentLinkObject)
		oleReference.BrowserVisible = True
		oleReference.Visible = False
		oleReference.DisplayName = Mid$(selectedfile2, InStrRev(selectedfile2, "\") + 1)
End Sub
Public Sub AddReferences3(ByVal odoc As Inventor.Document, ByVal selectedfile3 As String)
	Dim oleReference As ReferencedOLEFileDescriptor
		oleReference = odoc.ReferencedOLEFileDescriptors _
				.Add(selectedfile3,OLEDocumentTypeEnum.kOLEDocumentLinkObject)
		oleReference.BrowserVisible = True
		oleReference.Visible = False
		oleReference.DisplayName = Mid$(selectedfile3, InStrRev(selectedfile3, "\") + 1)
End Sub