在新的程序实例中打开文件

时间:2018-11-26 18:48:45

标签: vb.net cad solidworks

全部;

我编写了一些代码,可以在我扫描条形码时打开设计蓝图。它运行良好,但是我想打开设计软件的一个新实例(Solidworks),并在新实例中显示打印内容。现在,无论我打开了多少个Solidworks实例,打印都只会在启动的第一个实例中打开。

下面注释掉的行是可行的行,只是不在正确的实例中。下面的行是我期望的工作,但是即使SolidWorks的路径和打印路径都正确,它也会返回“找不到文件”。

任何关于为什么它不起作用的解释将不胜感激,因为我显然是新来的...而且不知道我在做什么。

Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
    Try
        Dim barcode As String = tb_barcode.Text
        Dim filename As String = tb_barcode.Text
        'Add File Extension to end of path
        Dim ext As String = ".SLDDRW"
        'Split job number from detail number in barcode textbox
        barcode = Split(tb_barcode.Text, ".")(0)
        filename = Split(tb_barcode.Text, ".")(1)
        '- This works, just in primary instance
        'System.Diagnostics.Process.Start("G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext)
        '- This does not work
        System.Diagnostics.Process.Start("'C:\Program files\Solidworks Corp\Solidwork\SLDWORKS.exe' 'G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext + "'")

    Catch
        MessageBox.Show("File Not Found")
    End Try
End Sub

2 个答案:

答案 0 :(得分:0)

很抱歉,您会采用朴素的方法,但是Process.Start中2个参数之间不应该有逗号吗?

Start(String, String) 

通过指定应用程序的名称和一组命令行参数来启动流程资源,并将该资源与新的流程组件相关联。 docs

答案 1 :(得分:0)

Why don't you use the Application.ExecutablePath.That returns the Application's path with its full name. Then your code should be

   System.Diagnostics.Process.Start(Application.Executablepath, "G:\Fixtures\" & barcode & "\Details\" & barcode & " DET " & filename & ext + "'")

Also make sure that the second string argument is a valid path.