SaveAs to defined ViewRep

SaveAs to defined ViewRep

donnie.morris
Enthusiast Enthusiast
329 Views
4 Replies
Message 1 of 5

SaveAs to defined ViewRep

donnie.morris
Enthusiast
Enthusiast

Good morning,

 

I have adapted a piece of code I found on the forums to SaveAs (Choose folder for Export) and open the file saved. The problem is the file always defaults to the "Master" ViewRep. Is there a way to have the saved file to open to the defined "Default" ViewRep?

 

' 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! - 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("Project", "Part Number")

' Define the filename of the file to be exported - in this case it is a PDF file extension
ExportFilename = oFileName & ".iam"

' Do export operation (using save as)
Try
    ThisDoc.Document.SaveAs(ExportPath & ExportFilename, True)
Catch
    MsgBox("File export failed...", 64, "Lord iLogic")
End Try

' Ask user if they want to open (launch) the file we just exported...
If MsgBox("File exported: " & _
        ExportPath & ExportFilename & vbLf & vbLf & _
        "Do you want to open the Assembly Now?", 36, "Lord iLogic - File Exported") = 6 Then
    ' User says yes...launch exported file
    ThisDoc.Launch(ExportPath & ExportFilename)
End If 

 

0 Likes
Accepted solutions (1)
330 Views
4 Replies
Replies (4)
Message 2 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

Forget ThisDoc.Launch

Use ThisApplication.Documents.OpenWithOptions method or set the ThisApplication.FileOptions.FileOpenOptions.DefaultDesignViewInPart() property


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 5

donnie.morris
Enthusiast
Enthusiast

ThisApplication.FileOptions.FileOpenOptions.DefaultDesignViewInPart()

 

This worked to set the View Rep however the saved document no longer opens, I get an error opening the file.

0 Likes
Message 4 of 5

donnie.morris
Enthusiast
Enthusiast

What am I missing, why won't the file open?

   
' 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! - 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("Project", "Part Number")

' Define the filename of the file to be exported - in this case it is a iam file extension
ExportFilename = oFileName & ".iam"

' Do export operation (using save as)
Try
	    ThisDoc.Document.SaveAs(ExportPath & ExportFilename, True)
Catch
    MsgBox("File export failed...", 64, "Lord iLogic")
End Try

' Ask user if they want to open (launch) the file we just exported...
If MsgBox("File exported: " & _
        ExportPath & ExportFilename & vbLf & vbLf & _
        "Do you want to open the Assembly Now?", 36, "Lord iLogic - File Exported") = 6 Then
    
	ThisApplication.Documents.OpenWithOptions(ExportPath & ExportFilename, DefaultDesignView, True)
	
End If

 

0 Likes
Message 5 of 5

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

If there's an error message, please post it.

OpenWithOptions requieres a NameValueMap containing the options. Try it as follows:

' Ask user if they want to open (launch) the file we just exported...
If MsgBox("File exported: " & _
	ExportPath & ExportFilename & vbLf & vbLf & _
	"Do you want to open the Assembly Now?", 36, "Lord iLogic - File Exported") = 6 Then
	
	'Create a NameValue Map
	Dim oNVMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	'Add option to NameValueMap
	oNVMap.Value("DesignViewRepresentation") = "Default"
	
	ThisApplication.Documents.OpenWithOptions(ExportPath & ExportFilename, oNVMap, True)

End If

R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes