chr
2024-08-07 22beee93f14d042aa184148c53efb79e23416526
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.IO;
 
// SolidWorks 的命名空间们
using SolidWorks.Interop.swconst;
 
namespace PdmSwPlugin.Common.Util
{
    /// <summary>
    /// 得到 SolidWorks 文档的后缀名
    /// </summary>
    public static class FileExtentionChecker
    {
        /// <summary>
        /// 装配体的后缀名
        /// </summary>
        public static string AssemblyExtentionInLowerCase = @".sldasm";
 
        /// <summary>
        /// 零件的后缀名
        /// </summary>
        public static string PartExtentionInLowerCase = @".sldprt";
 
        /// <summary>
        /// 工程图的后缀名
        /// </summary>
        public static string DrawingExtentionInLowerCase = @".slddrw";
 
        /// <summary>
        /// 检查一个 SolidWorks 文件的类型
        /// </summary>
        /// <param name="sldFullPath">SolidWorks 文件</param>
        /// <param name="originalExt">返回原始的后缀名</param>
        /// <returns>文件类型,当前仅支持装配体、零件和工程图三种</returns>
        public static swDocumentTypes_e Check(string sldFullPath, out string originalExt)
        {
            originalExt = null;
            if (string.IsNullOrEmpty(sldFullPath))
                return swDocumentTypes_e.swDocNONE;
            originalExt = Path.GetExtension(sldFullPath);
            if (string.Compare(originalExt, AssemblyExtentionInLowerCase, true) == 0)
                return swDocumentTypes_e.swDocASSEMBLY;
            else if (string.Compare(originalExt, PartExtentionInLowerCase, true) == 0)
                return swDocumentTypes_e.swDocPART;
            else if (string.Compare(originalExt, DrawingExtentionInLowerCase, true) == 0)
                return swDocumentTypes_e.swDocDRAWING;
            else
                return swDocumentTypes_e.swDocNONE;
        }
    }
}