private static void GetAndSetDrawingNo(IModelDoc2 modDoc) { string fileName; string pattern; string drawingNoEnd; string drawingNoPre; fileName = modDoc.GetTitle(); //去除后缀 fileName = fileName.Substring(0, fileName.LastIndexOf(".")); //正则提取5位图号 pattern = "((a|A)?[0-9]{3,5})(a|A)?$"; drawingNoEnd = Regex.Match(fileName, pattern).Value; //从配置文件获取前缀 drawingNoPre = ConfigurationManipulate.GetConfigValue("图号前缀"); //将提取的5位图号写入自定义属性 if (drawingNoEnd != "") { modDoc.AddCustomInfo("图号", "文字", drawingNoPre + drawingNoEnd); modDoc.set_CustomInfo("图号", drawingNoPre + drawingNoEnd); } else { modDoc.AddCustomInfo("图号", "文字", "外购件"); modDoc.set_CustomInfo("图号", "外购件"); } }