Export to STP

Export to STP

donnie.morris
Enthusiast Enthusiast
1,121 Views
3 Replies
Message 1 of 4

Export to STP

donnie.morris
Enthusiast
Enthusiast

I have located two pieces of code that I need to merge into one if anyone is willing to provide some assistance.

I am trying to Export to a ".stp" from an ".idw" but I need the user to be able to choose the location of the exported file.

 

The code I have found exports to .stp perfectly but to a defined location, in this case "C:\TEMP" , I need it to follow the location as defined by a piece of code meant to export to a .pdf

 Is there anyway to merge the .pdf location portion to the .stp file type code?

 

Here's the two pieces of code:

 

.pdf location 

' 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

' Define folder browse dialog
Dim Dialog = New FolderBrowserDialog()

' Set options for folder browser dialog
Dialog.SelectedPath = ExportPath
Dialog.ShowNewFolderButton = True
Dialog.Description = "Choose Folder for Export..."

' Show dialog box
If DialogResult.OK = Dialog.ShowDialog() Then
    ' User clicked 'ok' on dialog box - capture the export path
    ExportPath = Dialog.SelectedPath & "\"    
Else
    ' User clicked 'cancel' on dialog box - exit
    Return
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, _
	"Formsprag iLogic - File Exported",MessageBoxButtons.YesNo)
	
	If oQuestion = vbYes Then
		ThisDoc.Launch(ExportPath & ExportFilename)
	End If

End If

.stp code 

'Dim statement: Declares and allocates storage space for variables
Dim oPart As Inventor.PartDocument
'Takes the part shown in the 1st view
'of the current sheet's DrawingViews collection
oDrawingDoc = ThisDrawing.Document
oSheet = ActiveSheet.Sheet
oDrawingView = oSheet.DrawingViews.Item(1)

oPart = ActiveSheet.View(oDrawingView.Name).ModelDocument
' 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
		
	oStepFileName = iProperties.Value("Project", "Part Number") & " " & iProperties.Value("Project", "Description")
		
If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, 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
    oData = ThisApplication.TransientObjects.CreateDataMedium
		strFolder = "C:\TEMP\"
   		oData.FileName = strFolder & "\" & oStepFileName & ".stp"
	oSTEPTranslator.SaveCopyAs(oPart, oContext, oOptions, oData)
End If

 

0 Likes
Accepted solutions (1)
1,122 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

Does this work for you:

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 

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
Message 3 of 4

donnie.morris
Enthusiast
Enthusiast

Perfect,

 

Thanks!

0 Likes
Message 4 of 4

donnie.morris
Enthusiast
Enthusiast

Can this code create both a .stp and . pdf at the same time?

0 Likes