Ejemplo n.º 1
0
 public static bool STL(ProductDocument prod, string path)
 {
     prod.ExportData(path, "stl");
     return(true);
 }
Ejemplo n.º 2
0
        public string ExportToCgr(string path, string dir)
        {
            string dirName = path.Substring(0, path.LastIndexOf('\\'));

            dirName = dirName.Substring(0, dirName.LastIndexOf('\\'));
            dirName = dirName.Substring(dirName.LastIndexOf('\\') + 1);
            string name = path.Substring(path.LastIndexOf('\\') + 1);

            name = name.Substring(0, name.LastIndexOf('.'));

            ProductDocument prodDoc = null;

            try
            {
                prodDoc = (ProductDocument)myCATIA.Documents.Read(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Path '" + path + "' could not be read.");
                String errType = ex.GetType().Name;
                if (errType == "TimeoutException")
                {
                    //TimeoutException e = ex as TimeoutException;
                    Console.WriteLine("It's the TimeoutException !");
                }
                if (errType == "COMException")
                {
                    COMException COMex = ex as COMException;
                    Console.WriteLine("COMerror " + COMex.ErrorCode.ToString() + ": " + COMex.Message);
                }
                if (prodDoc != null)
                {
                    prodDoc.Close();
                }
                return(null);
            }

            string prodDocName = dir + "\\" + dirName + " - " + name;

            if (System.IO.File.Exists(prodDocName + ".cgr"))
            {
                System.IO.File.Delete(prodDocName + ".cgr");
            }
            try
            {
                prodDoc.ExportData(prodDocName + ".CGR", "cgr");
            }
            catch (Exception)
            {
                Console.WriteLine("Path '" + path + "' could not be exported.");
                if (prodDoc != null)
                {
                    prodDoc.Close();
                }
                return(null);
            }

            if (prodDoc != null)
            {
                prodDoc.Close();
            }
            return(prodDocName);
        }