- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a piece of code that exports a file from the .idw to a STP. I was wondering if that code could be adapted to export both a .stp and .pdf? Is this possible?
Here's the code: Export to STP
Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = sheet.DrawingViews.Item(1)
Dim partDoc As PartDocument = view.ReferencedDocumentDescriptor.ReferencedDocument
' Get current location of this file
Dim ExportPath As String = ThisDoc.Path
' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
MsgBox("This file has not yet been saved and doesn't exist on disk!" _
& vbLf & "Please save it first", 64, "Lord iLogic")
Return
End If
Dim drawingNumber = iProperties.Value("Custom", "Drawing Number")
Dim dialog As Inventor.FileDialog
ThisApplication.CreateFileDialog(dialog)
dialog.InitialDirectory = ExportPath
dialog.FileName = drawingNumber
dialog.DialogTitle = "Save"
dialog.Filter = "Step files(*.stp)|*.stp|All Files (*.*)|*.*"
dialog.CancelError = True
Try
dialog.ShowSave()
Catch ex As Exception
Return
End Try
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
If oSTEPTranslator.HasSaveCopyAsOptions(partDoc, oContext, oOptions) Then
' Set application protocol.
' 2 = AP 203 - Configuration Controlled Design
' 3 = AP 214 - Automotive Design
oOptions.Value("ApplicationProtocolType") = 3
' Other options...
'oOptions.Value("Author") = ""
'oOptions.Value("Authorization") = ""
'oOptions.Value("Description") = ""
'oOptions.Value("Organization") = ""
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
oData.FileName = dialog.FileName
oSTEPTranslator.SaveCopyAs(partDoc, oContext, oOptions, oData)
End If
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Sure, after you export to .stp, export to pdf. There's an example in the API docs: Export to PDF
Some of the things in that code you've already done to get the .stp so you won't need to duplicate them for the pdf.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I can get the code to create both the .stp and .pdf; however, the .pdf is not created in the selected directory, it defaults to the same directory as the .idw file.
Any help would be greatly appreciated.
Dim doc As DrawingDocument = ThisDoc.Document Dim sheet As Sheet = doc.ActiveSheet Dim view As DrawingView = sheet.DrawingViews.Item(1) Dim partDoc As PartDocument = view.ReferencedDocumentDescriptor.ReferencedDocument ' Get current location of this file Dim ExportPath As String = ThisDoc.Path ' Check that this file has been saved and actually exists on disk If String.IsNullOrEmpty(ExportPath) Then MsgBox("This file has not yet been saved and doesn't exist on disk!" _ & vbLf & "Please save it first", 64, "Lord iLogic") Return End If Dim drawingNumber = iProperties.Value("Custom", "Drawing Number") Dim dialog As Inventor.FileDialog ThisApplication.CreateFileDialog(dialog) dialog.InitialDirectory = ExportPath dialog.FileName = drawingNumber dialog.DialogTitle = "Save" dialog.Filter = "Step files(*.stp)|*.stp|All Files (*.*)|*.*" dialog.CancelError = True Try dialog.ShowSave() Catch ex As Exception Return End Try ' Get the STEP translator Add-In. Dim oSTEPTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}") Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap If oSTEPTranslator.HasSaveCopyAsOptions(partDoc, oContext, oOptions) Then ' Set application protocol. ' 2 = AP 203 - Configuration Controlled Design ' 3 = AP 214 - Automotive Design oOptions.Value("ApplicationProtocolType") = 3 ' Other options... 'oOptions.Value("Author") = "" 'oOptions.Value("Authorization") = "" 'oOptions.Value("Description") = "" 'oOptions.Value("Organization") = "" oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism Dim oData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium oData.FileName = dialog.FileName oSTEPTranslator.SaveCopyAs(partDoc, oContext, oOptions, oData) End If oFileName = iProperties.Value("Custom", "Drawing Number") ' Define the filename of the file to be exported ' In this Case it Is a PDF file extension ExportFilename = oFileName & ".pdf" oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _ ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") oDocument = ThisApplication.ActiveDocument oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism oOptions = ThisApplication.TransientObjects.CreateNameValueMap oDataMedium = ThisApplication.TransientObjects.CreateDataMedium 'set PDF Options oOptions.Value("All_Color_AS_Black") = 1 oOptions.Value("Remove_Line_Weights") = 1 oOptions.Value("Vector_Resolution") = 400 oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets 'Set the PDF target file name oDataMedium.FileName = ExportPath & ExportFilename Try 'Publish document oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Catch MessageBox.Show("Error writing out PDF", "iLogic") bError = True End Try If bError <> True Then 'Ask user If they want To open (launch) the file we just exported... oMessage = "File exported: " & _ ExportPath & ExportFilename & vbLf & vbLf & _ "Do you want to open the PDF Now?" oQuestion = MessageBox.Show(oMessage, _ "Lord iLogic - File Exported",MessageBoxButtons.YesNo) If oQuestion = vbYes Then ThisDoc.Launch(ExportPath & ExportFilename) End If End If
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If you want both the .stp and the .pdf file in the same directory and with the same filename (except for extension), you can still use the result from the first FileDialog you use. You just have to change the extension of the save file, which is fairly easy to do. In your PDF section, instead of
'Set the PDF target file name oDataMedium.FileName = ExportPath & ExportFilename
use this:
'Set the PDF target file name
oDataMedium.FileName = System.IO.Path.GetFileNameWithoutExtension(dialog.FileName)&".pdf"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So this rule looks at .idw files that contain an .ipt in order to create the .stp file. Can the rule be written for an .idw that only contains .iam files.
I’m looking for a rule that will create .stp files for all .ipt files contained in the .iam used.
I’m not sure I’m asking the question correctly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The rule can be written for an .idw with an assembly, or it can be written for an assembly itself. Which do you need?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This rule assumes view #1 (normally the first view you placed) has the assembly you want to export .stp files from. It also assumes there are only parts, no subassemblies.
Imports System.Windows.Forms
Dim doc As DrawingDocument = ThisDoc.Document
Dim sheet As Sheet = doc.ActiveSheet
Dim view As DrawingView = sheet.DrawingViews.Item(1)
Dim assembyDoc As AssemblyDocument = view.ReferencedDocumentDescriptor.ReferencedDocument
' Get current location of this file
Dim ExportPath As String = ThisDoc.Path
' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
MsgBox("This file has not yet been saved and doesn't exist on disk!")
Return
End If
Dim dialog = New FolderBrowserDialog()
dialog.SelectedPath = ExportPath
If dialog.ShowDialog() = DialogResult.OK Then
For Each occurrence As ComponentOccurrence In assembyDoc.ComponentDefinition.Occurrences
If (occurrence.DefinitionDocumentType = kPartDocumentObject) Then
Dim partDoc As PartDocument = occurrence.Definition.Document
' Get the STEP translator Add-In.
Dim stepTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim translatorContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim translatorOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
If stepTranslator.HasSaveCopyAsOptions(partDoc, translatorContext, translatorOptions) Then
translatorOptions.Value("ApplicationProtocolType") = 3
translatorContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim translatorData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
translatorData.FileName = dialog.SelectedPath & "\" & System.IO.Path.ChangeExtension(partDoc.DisplayName, ".stp")
stepTranslator.SaveCopyAs(partDoc, translatorContext, translatorOptions, translatorData)
End If
End If
Next
End If
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Is there a way to make the view selectable instead of defaulting to View 1?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Just change the first part to allow a view selection:
Dim view As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, here code to export to STEP
sub main()
path_and_name = ThisDoc.PathAndFileName(False) ' without extension
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'Set the destination file name
oDataMedium.FileName = path_and_name & ".stp"
'Publish document.
ThisDoc.Document.SaveAs(oDataMedium.FileName , True)
end sub