Ouverture de fichiers edrawingsviewer à partir de java


J'ai une application que j'exécute sur un PC avec une souris, je veux lancer edrawingsviewer avec un nom de fichier particulier de java, puis lorsque l'utilisateur revient à l'application plein écran, s'il ne l'a pas fermée, je veux la fermer. C'est ce que j'ai jusqu'à présent pour une démo rapide, mais je ne peux pas comprendre quoi mettre dans les arguments pour lancer solidworks avec un fichier particulier.

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");
    }
}

Je ne pense pas que ce soit un problème solidworks, je pense que c'est juste quelque chose que je passe mal ou formatage incorrect ou quelque chose.

Author: davidahines, 2011-12-21

1 answers

Il semble que son exécution à travers le FileProtocolHandler le provoque à s'ouvrir correctement.

final Process process = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler \\\\itsugar\\www\\HMI\\POD EDRAWINGS\\"+fileName);
 0
Author: davidahines, 2011-12-21 14:58:11