public bool LoadFile(string path) { if (FindCuiFile(path)) { CustomizationSection cus = new CustomizationSection(path, true); CustomizationSection c = new CustomizationSection(); string AcadPath = Application.GetSystemVariable("MENUNAME").ToString() + ".cuix"; CustomizationSection acadCustomSection = new CustomizationSection(AcadPath); PartialCuiFileCollection cusparfile = acadCustomSection.PartialCuiFiles; if (cusparfile.Contains(path)) { ed.WriteMessage("程序中已经包含:" + path + " 的文件,同名文件将不再次加载"); } else { this.LoadCusCUI(path); } return(true); } else { System.Windows.Forms.MessageBox.Show("False"); return(false); } }
/// <summary>从局部Cui文件中加载选项卡(必须先添加对 AcCui.dll 的引用) </summary> /// <param name="strCuipath"></param> /// <remarks> /// 使用cuix文件添加对应 RibbonButton /// 先判断是否添加配置cuix /// 将配置cuix中的配置功能项添加到acad.cuix中的功能区 /// 刷新工作空间的功能区命令 /// </remarks> public static void AddRibbonButtonByCustomCui(string strCuipath) { string mainCuiFile = (string)Autodesk.AutoCAD.ApplicationServices.Core.Application.GetSystemVariable("MENUNAME"); mainCuiFile += ".cuix"; CustomizationSection csLoad = new CustomizationSection(mainCuiFile); PartialCuiFileCollection pPartialCuiFileCollection = csLoad.PartialCuiFiles; if (pPartialCuiFileCollection.Contains("mycui.cuix")) { MessageBox.Show("已加载插件!"); Autodesk.AutoCAD.ApplicationServices.Application.UnloadPartialMenu(strCuipath); //return; } bool isOK = Autodesk.AutoCAD.ApplicationServices.Application.LoadPartialMenu(strCuipath); //加载自定义cui if (!isOK) { MessageBox.Show("加载自定义配置文件失败!"); return; } //加载CUI //Application.QuitWillStart += new EventHandler(Application_BeginQuit); //Application.BeginQuit += new EventHandler(Application_BeginQuit); //Autodesk.Windows.ComponentManager.ApplicationMenu.Opening += new EventHandler<EventArgs>(ApplicationMenu_Opening); CustomizationSection cs = new CustomizationSection(mainCuiFile); PartialCuiFileCollection cuiFiles = cs.PartialCuiFiles; //acad.cuix配置文件 if (cuiFiles.Contains("mycui.cuix")) { //将my.cuix文件中的配置按钮写入acad.cuix文件中去 string strPartialCui = cuiFiles.GetFileNameByIndex(cuiFiles.IndexOf("mycui.cuix")); CustomizationSection csCustom = new CustomizationSection(strPartialCui); var pRibbonPanelSource = csCustom.MenuGroup.RibbonRoot.FindPanel("RBNU_191_C0DED"); //自定义panel中的ElementID var pCloneRibbonPanelSource = pRibbonPanelSource.Clone() as Autodesk.AutoCAD.Customization.RibbonPanelSource; cs.MenuGroup.RibbonRoot.RibbonPanelSources.Add(pCloneRibbonPanelSource); RibbonTabSource pRibbonTableSource2 = cs.MenuGroup.RibbonRoot.FindTab("RBN_00012112"); //插件Tab的ElementID RibbonPanelSourceReference pRibbonPanelSourceRefrence = new RibbonPanelSourceReference(pRibbonTableSource2); //这一步ID一定要赋值 pRibbonPanelSourceRefrence.PanelId = pCloneRibbonPanelSource.ElementID; pRibbonTableSource2.Items.Add(pRibbonPanelSourceRefrence); cs.Save(); Autodesk.AutoCAD.ApplicationServices.Application.ReloadAllMenus(); //否则不现实按钮 } }
private void LoadMyCui(string cuiFile) { Document doc = Application.DocumentManager.MdiActiveDocument; string mainCui = Application.GetSystemVariable("MENUNAME") + ".cuix"; CustomizationSection cs = new CustomizationSection(mainCui); PartialCuiFileCollection pcfc = cs.PartialCuiFiles; if (pcfc.Contains(cuiFile)) { doc.Editor.WriteMessage("\nCustomization file \"" + cuiFile + "\" already loaded."); return; } object oldCmdEcho = Application.GetSystemVariable("CMDECHO"); object oldFileDia = Application.GetSystemVariable("FILEDIA"); Application.SetSystemVariable("CMDECHO", 0); Application.SetSystemVariable("FILEDIA", 0); doc.SendStringToExecute( "_.cuiload " + "\"" + cuiFile + "\"" + " ", false, false, false ); doc.SendStringToExecute( "(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false ); doc.SendStringToExecute( "(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false ); }
string imagePath = ""; //15-04-2018 // string BaseImagePath = ""; public SymbolLibrary(string region, string typeofSign = "", string xmlName = "", string svOptionFromLisp = "", string folderPathFromLisp = "") { InitializeComponent(); DateTime dtmNow = DateTime.Now; //if (dtmNow.Day <= 31 && dtmNow.Year <= 2017 && dtmNow.Month <= 06) { try { string mainCui = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("MENUNAME") + ".cuix"; CustomizationSection cs = new CustomizationSection(mainCui); PartialCuiFileCollection pcfc = cs.PartialCuiFiles; foreach (var _pcfc in pcfc) { string cuixPath = System.IO.Path.GetFileNameWithoutExtension(_pcfc); if (cuixPath.Trim().ToLower().EndsWith("_au")) { region = "Aus"; } else if (cuixPath.Trim().ToLower().EndsWith("_sg")) { region = "SG"; } else { region = "NZ"; } } } catch { } _typeofSign = typeofSign; acsc = new AutoCompleteStringCollection(); txtSearch.AutoCompleteCustomSource = acsc; txtSearch.AutoCompleteMode = AutoCompleteMode.Suggest; txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource; dirPath = System.Reflection.Assembly.GetExecutingAssembly().Location; dirPath = dirPath.Substring(0, dirPath.LastIndexOf("\\")); //settingsFilePath = Path.Combine(dirPath, "Settings.ini"); //if (System.IO.File.Exists(settingsFilePath)) //{ // try // { // IniFile iniFile = new IniFile(settingsFilePath); // BaseImagePath = iniFile.IniReadValue("setting", "ImagePath"); // } // catch { } //} //IniFile iniFile = new IniFile(settingsFilePath); //signsDrawingPath =iniFile.IniReadValue("New Zealand", "Signs"); if (String.IsNullOrWhiteSpace(_typeofSign)) { MessageBox.Show("Type not found"); return; } try { //Code to read path from lisp // signsDrawingPath = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.GetLispSymbol("B:SYM").ToString(); //Autodesk.AutoCAD.Internal.Utils.GetLastCommandLines(10, true); if (string.IsNullOrEmpty(folderPathFromLisp)) { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; PromptResult pr = ed.GetString("Path:"); if (pr.Status == PromptStatus.OK) { path = pr.StringResult; } try { PromptResult PRSVOPtion = ed.GetString("SV"); if (PRSVOPtion.Status == PromptStatus.OK) { SVOption = PRSVOPtion.StringResult; } //PromptResult PRImagePath = ed.GetString("ImagePath"); //if (PRImagePath.Status == PromptStatus.OK) //{ // imagePath = PRImagePath.StringResult; // //if (BaseImagePath.Length > 0)//Add Base path if exists // // imagePath = System.IO.Path.Combine(BaseImagePath, imagePath); //} } catch { } } else { path = folderPathFromLisp; SVOption = svOptionFromLisp; } //17-05-2018 if (SVOption.Equals("SV-ON", StringComparison.InvariantCultureIgnoreCase)) { SVON = true;// chkScale.Checked = true; } else { SVON = false; chkScale.Checked = false; } if (!string.IsNullOrEmpty(path)) { //Added on 24-10-2017 to remove multiple commands, if the last folder is signs then it is signs if not it is road markings //string dirName = Path.GetFileName(path.TrimEnd(Path.DirectorySeparatorChar)); //if (dirName.Equals("Signs")) // _typeofSign = "Signs"; //else // _typeofSign = "RoadMarkings"; if (region.Equals("NZ", StringComparison.InvariantCultureIgnoreCase) || region.Equals("New Zealand", StringComparison.InvariantCultureIgnoreCase)) { region = "New Zealand"; xmlName = "B-Civil.xml"; } else if (region.Equals("Aus", StringComparison.InvariantCultureIgnoreCase) || region.Equals("Australia", StringComparison.InvariantCultureIgnoreCase)) { region = "Australia"; xmlName = "B-Civil_AU.xml"; } else if (region.Equals("SG", StringComparison.InvariantCultureIgnoreCase) || region.Equals("Singapore", StringComparison.InvariantCultureIgnoreCase)) { region = "Singapore"; xmlName = "B-Civil_SG.xml"; } //foreach (string strDir in path.Split('/')) //{ // if (strDir.Equals("NZ", StringComparison.InvariantCultureIgnoreCase)) // { // region = "New Zealand"; // xmlName = "B-Civil.xml"; // break; // } // else if (strDir.Equals("Aus", StringComparison.InvariantCultureIgnoreCase) || strDir.Equals("Australia", StringComparison.InvariantCultureIgnoreCase)) // { // region = "Australia"; // xmlName = "B-Civil_AU.xml"; // break; // } // else if (strDir.Equals("SG", StringComparison.InvariantCultureIgnoreCase) || strDir.Equals("Singapore", StringComparison.InvariantCultureIgnoreCase)) // { // region = "Singapore"; // xmlName = "B-Civil_SG.xml"; // break; // } //} signsDrawingPath = path; } if (string.IsNullOrEmpty(signsDrawingPath)) { MessageBox.Show("Invalid drawing path"); abortScreenOpen = true; // Environment.Exit(-1); } else if (!System.IO.Directory.Exists(signsDrawingPath)) { MessageBox.Show(signsDrawingPath + " - Path does not exist"); abortScreenOpen = true; // Environment.Exit(-1); } else if (string.IsNullOrEmpty(region)) { MessageBox.Show("Region not recognizable in the folder path"); abortScreenOpen = true; // Environment.Exit(-1); } //15-04-2018 //if (string.IsNullOrEmpty(imagePath)) // MessageBox.Show("Image path not found"); //else if (!System.IO.Directory.Exists(imagePath)) // MessageBox.Show("Invalid Image path"); //30-05-2018 //Read the below from CUIX //xmlPath = Path.Combine(dirPath, xmlName);// "NZSigns.xml"); //if (!System.IO.File.Exists(xmlPath)) // MessageBox.Show(xmlName + " - XML file not found"); } catch (Exception ex) { signsDrawingPath = ""; MessageBox.Show("Invalid drawing path - " + ex.ToString()); } txtRegion.Text = region; lblSigns.Text = _typeofSign; string dirName = ""; if (!string.IsNullOrEmpty(signsDrawingPath.Trim())) { dirName = new DirectoryInfo(signsDrawingPath.Trim()).Name; } this.Text = dirName;//11-11-2018 "Symbol Library - " + region + " - " + _typeofSign; } }