Question

I have an application that I run on a pc with a mouse, I want to launch edrawingsviewer with a particular file name from java and then when the user returns to the fullscreen app, if they haven't closed it I want to close it. This is what I've got so far for a quick demo but I cannot figure out what to put in the arguments in order to launch solidworks with a particular file.

package com.protocase.hmiclient.edrawings;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 * @author DavidH
 */
public class EDrawingHelper {

    public static File[] getEDrawingsForJob(final String jobNumber) {
        File f = new File("\\\\itsugar\\www\\HMI\\POD EDRAWINGS");
        File[] matchingFiles = f.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.startsWith(jobNumber) && (name.endsWith("EASM") || name.endsWith("EDRW"));
            }
        });
        return matchingFiles;
    }
    public static void test(String[] args) {
        File[] files = getEDrawingsForJob("G080111004-13162-1");
        for (File file : files){
            System.out.println(file.getName());
        }
    }
    public static void openEDrawingForFileName(String fileName){
        try {
            final Process process = Runtime.getRuntime().exec("C:\\Program Files\\SolidWorks Corp\\SolidWorks eDrawings (2)\\EModelViewer.exe  \\\\itsugar\\www\\HMI\\POD EDRAWINGS\\"+fileName);
            JFrame frame = new JFrame();
            JButton killButton = new JButton("KILL");
            killButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    process.destroy();
                    System.exit(0);
                }
            });
            frame.getContentPane().add(killButton);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        openEDrawingForFileName("G080111004-13162-1 ASSEMBLY.EASM");
    }
}

I don't think this is a solidworks problem, I think this is just something I'm passing wrong or formatting wrong or something.

Was it helpful?

Solution

It appears as if running it through the FileProtocolHandler causes it to open fine.

final Process process = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler \\\\itsugar\\www\\HMI\\POD EDRAWINGS\\"+fileName);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top