I got that to work now, thank you. I created another rule to do the same thing for .stl files and it saves the file ok, but will not attach it to the .ipt file. It shouldn't matter what type of file it is, should it?
Here is the rule for an .stl file
SyntaxEditor Code Snippet
''' <summary>
''' Will only run if the activedocument has been saved.
''' </summary>
Sub Main()
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Export and Attach Stl file")
Try
If Not ThisApplication.ActiveDocument.FullFilename = String.Empty Then 'won't run if the active document isn't saved.
Dim filenameToAttach As String = ExportToStl()
If Not filenameToAttach = String.Empty Then
Dim doc As Document = ThisApplication.ActiveDocument
AddReferences(doc, filenameToAttach)
End If
Else
MessageBox.Show("File not saved; save the file and try again!")
trans.Abort()
End If
trans.End()
Catch
trans.Abort()
End Try
End Sub
''' <summary>
''' Returns an empty string if the stl file didn't save for some reason.
''' </summary>
''' <returns></returns>
Function ExportToStl() As String
oPath = ThisDoc.Path
oStlFileName = iProperties.Value("Project", "Part Number")
Dim STLAddIn As TranslatorAddIn
STLAddIn = ThisApplication.ApplicationAddIns.ItemById("{81CA7D27-2DBE-4058-8188-9136F85FC859}")
Dim oDocument As Document = ThisDoc.Document
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If STLAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
oOptions.Value("OutputFileType") = 0 ' 0 = Binary , 1 = ASCII
oOptions.Value("ExportUnits") = 2 ' INCH = 2 , FOOT = 3 , CENTIMETER = 4 , MILLIMETER = 5 , METER = 6 , MICRON = 7
oOptions.Value("Resolution") = 0 ' HIGH = 0 , MEDIUM = 1 , LOW = 2 , CUSTOM = 3 , BREP = 4
oOptions.Value("ExportColor") = False
End If
'Set the destination file name
oDataMedium.FileName = oPath & "\" & oStlFileName & ".stl"
'Publish document.
Call STLAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Function
''' <summary>
''' Attaches any file using the full c:\path\to\your\file.extension format.
''' </summary>
''' <param name="odoc"></param>
''' <param name="selectedfile"></param>
Public Sub AddReferences(ByVal odoc As Inventor.Document, ByVal selectedfile As String)
Dim oleReference As ReferencedOLEFileDescriptor
If selectedfile.Contains("|") Then ' we have multiple files selected.
Dim file As String() = selectedfile.Split("|")
For Each s As String In file
oleReference = odoc.ReferencedOLEFileDescriptors _
.Add(s, OLEDocumentTypeEnum.kOLEDocumentLinkObject)
oleReference.BrowserVisible = True
oleReference.Visible = False
oleReference.DisplayName = Mid$(s, InStrRev(s, "\") + 1)
Next
Else
oleReference = odoc.ReferencedOLEFileDescriptors _
.Add(selectedfile, OLEDocumentTypeEnum.kOLEDocumentLinkObject)
oleReference.BrowserVisible = True
oleReference.Visible = False
oleReference.DisplayName = Mid$(selectedfile, InStrRev(selectedfile, "\") + 1)
End If
End Sub