Message 1 of 3
STP Protocol Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am trying to export to stp with the 242 protocol (Managed model based 3d engineering) however it just stays as automotive design. Below is my current code to export to stl, obj, stp and upload to vault. I have tried to change this number but have no luck. No matter the number it stays as automotive design
oOptions.Value("ApplicationProtocolType") = 3
I am also trying to get it to delete from vault if it exists before uploading. I have a check that returns true if it exists in vault but am having trouble deleting.
Any help would be much appreciated.
Sub Main()
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim fileFormats As String() = {"STL", "OBJ", "STEP" }
Dim exportPath As String = ThisDoc.Path
Dim ExportFileName As String = exportPath & "\"
For Each format As String In fileFormats
Dim fullExportPath As String
If Format = "STEP" Then
fullExportPath = ExportFileName & iProperties.Value("Project", "Part Number") & ".stp"
Else
fullExportPath = ExportFileName & iProperties.Value("Project", "Part Number") & "." & Format.ToLower()
End If
' Export the file
Dim oTranslatorAddin As TranslatorAddIn = Nothing
If Format = "STEP" Then
oTranslatorAddin = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Else If Format = "OBJ" Then
oTranslatorAddin = ThisApplication.ApplicationAddIns.ItemById("{F539FB09-FC01-4260-A429-1818B14D6BAC}")
Else If Format = "STL" Then
oTranslatorAddin = ThisApplication.ApplicationAddIns.ItemById("{533E9A98-FC3B-11D4-8E7E-0010B541CD80}")
End If
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Set translation options
If oTranslatorAddin.HasSaveCopyAsOptions(ThisApplication.ActiveDocument, oContext, oOptions) Then
oOptions.Value("Resolution") = 0
oOptions.Value("ApplicationProtocolType") = 3
oContext.Type = kFileBrowseIOMechanism
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
If Not Format = "STEP" Then
oData.FileName = ThisDoc.ChangeExtension(Format.ToLower())
Else
oData.FileName = ThisDoc.ChangeExtension(".stp")
End If
' Perform the export
Try
oTranslatorAddin.SaveCopyAs(ThisApplication.ActiveDocument, oContext, oOptions, oData)
Catch
MsgBox("File export failed... It may exist", 64, "3D Exporter")
End Try
End If
Dim mVltCon As VDF.Vault.Currency.Connections.Connection
mVltCon = VB.ConnectionManager.Instance.Connection
Dim folderPath As String = GetVaultFolderPath(exportPath)
Dim folderId As Long = -1
Dim folder As AWS.Folder = Nothing
folder = mVltCon.WebServiceManager.DocumentService.GetFolderByPath(folderPath)
folderId = folder.Id
Dim myFolder As VDFVault.Currency.Entities.Folder = New VDFVault.Currency.Entities.Folder(mVltCon, folder)
Dim filePath As String = fullExportPath
Dim myFileIterationNewFile As VDF.Vault.Currency.Entities.FileIteration = Nothing
Using fileStream As Stream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
' Add the file to the vault
CheckIfFileExistInVault(ExportFilename)
Try
myFileIterationNewFile = mVltCon.FileManager.AddFile(myFolder, System.IO.Path.GetFileName(filePath), System.IO.Path.GetFileName(filePath), DateTime.Now, Nothing, Nothing, Nothing, False, fileStream)
Catch
MsgBox(Format & " File exists in Vault. Delete and rerun rule or add manually", 64, "3D Exporter")
End Try
End Using
Next
End Sub
Function GetVaultFolderPath(localPath As String) As String
' Map local path to Vault path
Dim baseLocalPath As String = "C:\$Vault\Designs"
Dim baseVaultPath As String = "$/Designs"
If localPath.StartsWith(baseLocalPath) Then
Dim relativePath As String = localPath.Substring(baseLocalPath.Length).TrimStart("\"c)
Return System.IO.Path.Combine(baseVaultPath, relativePath).Replace("\", "/")
Else
' Handle cases where the path does not match the base path
Throw New Exception("Local path does not match expected base path.")
End If
End Function
Private Sub DeleteFileIfExists(filePath As String)
If System.IO.File.Exists(filePath) Then
Try
My.Computer.FileSystem.DeleteFile(filePath, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)
Catch ex As Exception
MsgBox("Error deleting existing local file: " & ex.Message, 64, "3D Exporter")
End Try
End If
End Sub