Thanks for the additional links. I will look at them.
I finally got this to work as I wanted.
Added:
oODocName = ThisDoc.Document
and changed the line
oSTEPTranslator.SaveCopyAs(oODocName, oContext, oOptions, oData)
It now saves the correct STEP and fortunately in the correct folders of the different products as well. Got lucky.
Here is the rule as it is now:
' Start of iLogic code *******************************************
'query user
question = MessageBox.Show("Is a STEP file needed for " & ThisDoc.FileName(False), "Sav2STEP",MessageBoxButtons.YesNo,MessageBoxIcon.Question)
'set condition based on answer
If question = vbNo Then
Exit Sub
End If
oODocName = ThisDoc.Document
oPath=ThisDoc.Path
oFolder = oPath & "\STEP FILES"
oRevNum = iProperties.Value("Project", "Revision Number")
'check to see if in drawing
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
doc = ThisApplication.ActiveDocument
MsgBox("This iLogic rule will only run from a part or assembly", MsgBoxStyle.Exclamation, "Document Type Error")
Exit Sub
End If
Dim Sdate As String = DateString '& " " & TimeString
'Check for the STEP folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
'Delete Files from folder containing this file name
Dim path As String = ThisDoc.Path & "\STEP FILES\"
For Each foundFile As String In My.Computer.FileSystem.GetFiles (path,Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories,
"*" & ThisDoc.FileName(False) & "*")
My.Computer.FileSystem.DeleteFile(foundFile)
Next
'Start of export code ***********************************************
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById _
("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument _
, oContext, oOptions) Then
oOptions.Value("ApplicationProtocolType") = 3
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
' Set export name of STEP file
oData.FileName =ThisDoc.Path & "\STEP FILES\" & ThisDoc.FileName(False) & " " & oRevNum & ".stp"
'oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
oSTEPTranslator.SaveCopyAs(oODocName, oContext, oOptions, oData)
End If
' End of export code ***********************************************
' Ask user if they want to open the export folder
OpenFolder = MessageBox.Show("Export successful! " & _
"- open containing folder now?", "Sav2STEP", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Question,MessageBoxDefaultButton.Button1)
If OpenFolder = vbYes Then
Process.Start("explorer.exe", ThisDoc.Path & "\STEP FILES\")
Else ' User says continue
'Return
End If
' End of iLogic code **************************************************