Hallo Zusammen
Ich bin stetig nebenher bemüht mir vb.Net beizubringen. Nun stehe ich aber auf dem Schlauch. Ich möchte via textbox und einem Button ein neues Part erstellen und danach über einen Filedialog im Workspace abspeichern.
Den Ablaufplan stelle ich mir so vor:
1. Textbox befüllen (von Hand)
2. Speicherdialog (von Inventor), Pfad auswählen
3. Bei "Abbrechen"--> alles Abbrechen
4. Bei "Speichern" --> Schritt 5
5. Part aus Templates erstellen und in gewähltes Verzeichnis abspeichern
6. Textbox wieder zurücksetzen
In der API steht ein Beispiel in VBA.
Public Sub TestFileDialog()
' Create a new FileDialog object.
Dim oFileDlg As FileDialog
Call ThisApplication.CreateFileDialog(oFileDlg)
' Define the filter to select part and assembly files or any file.
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
' Define the part and assembly files filter to be the default filter.
oFileDlg.FilterIndex = 1
' Set the title for the dialog.
oFileDlg.DialogTitle = "Open File Test"
' Set the initial directory that will be displayed in the dialog.
oFileDlg.InitialDirectory = "C:\Temp"
' Set the flag so an error will be raised if the user clicks the Cancel button.
oFileDlg.CancelError = True
' Show the open dialog. The same procedure is also used for the Save dialog.
' The commented code can be used for the Save dialog.
On Error Resume Next
oFileDlg.ShowOpen
' oFileDlg.ShowSave
' If an error was raised, the user clicked cancel, otherwise display the filename.
If Err Then
MsgBox "User cancelled out of dialog"
ElseIf oFileDlg.FileName <> "" Then
MsgBox "File " & oFileDlg.FileName & " was selected."
End If
End Sub
Mithilfe dieses Beispiels habe ich dann versucht den Dialog in vb.Net abzubilden. Was ich bis jetzt herausgefunden habe ist, dass offenbar die Cancelerror methode mit vb.net nicht funktioniert. Wie kann ich also an das Dialogresultat herankommen?
Hier mein Code:
Public Function SaveDialog(ByVal strSelectedFormat As String)
' Create a new FileDialog object.
Dim oFileDlg As FileDialog = Nothing
invApp.CreateFileDialog(oFileDlg)
' Define the filter to select part and assembly files or any file.
oFileDlg.Filter = "Inventor Files (*." & strSelectedFormat & ")|*." & strSelectedFormat & ";*"
' Define the part and assembly files filter to be the default filter.
oFileDlg.FilterIndex = 1
oFileDlg.FileName = TextBox1.Text
'MsgBox oFileDlg.FileName
' Set the title for the dialog.
oFileDlg.DialogTitle = "SAVEMENU"
' Set the initial directory that will be displayed in the dialog.
oFileDlg.InitialDirectory = invApp.DesignProjectManager.ActiveDesignProject.WorkspacePath
' Set the flag so an error will be raised if the user clicks the Cancel button.
oFileDlg.CancelError = True
' Show the open dialog. The same procedure is also used for the Save dialog.
' The commented code can be used for the Save dialog.
On Error Resume Next
'oFileDlg.ShowOpen
oFileDlg.ShowSave()
end Function
Für eine hilfreiche Antwort wäre ich wirklich sehr dankbar.
[Diese Nachricht wurde von Luti91 am 03. Nov. 2016 editiert.]
[Diese Nachricht wurde von Luti91 am 03. Nov. 2016 editiert.]
[Diese Nachricht wurde von Luti91 am 03. Nov. 2016 editiert.]
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP