public Result OnStartup(UIControlledApplication uiApp) { CustomRibbon ribbon = new CustomRibbon(uiApp); //var myTab = ribbon.Tab("JOTools"); var ExButton = new ExistingButton(); var exBtn1 = ExButton.AdwinButton("Architecture", "Build", "Mullion", true); var exBtn2 = ExButton.AdwinButton("JOTools", "Copie Proprietes", "Options"); //var existedTab = myTab.Panel("Compare"); //var btn = existedTab.CreateButton<HelloWorld>("btnNew", "New\nButton", // b => b.SetLargeImage(Resources.arrow_carribean_blue_32x32)); return(Result.Succeeded); }
public Result OnStartup(UIControlledApplication uiApp) { CustomRibbon ribbon = new CustomRibbon(uiApp); var myTab = ribbon.Tab("TD"); var panelLearning = myTab.Panel("Learning"); var btn1 = panelLearning .CreateButton("btnInfoElement", "Info\nElement", typeof(CmdPickMultiObjects), btn => btn .SetLargeImage(Resources.arrow_royal_blue_32x32) .SetSmallImage(Resources.arrow_royal_blue_16x16) .SetContextualHelp(ContextualHelpType.Url, "https://help.autodesk.com")) .RvtPushButton;//Get the defaut autodesk pushbutton to use in other class panelLearning .CreateStackedItems(si => si .CreateButton <CmdCollectorWithLINQ>("btnCreateFamily", "CreateCars", btn => btn.SetSmallImage(Resources.circle_caribbean_blue_16x16)) .CreateButton <CmdCreateLineBaseElement>("btnCreateWall", "CreateWall", btn => btn.SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <CmdGetParameter>("btnGetParameter", "Get Parameter", btn => btn.SetSmallImage(Resources.circle_orange_16x16))) .CreatePullDownButton("pdbBtn1", "Options", pdb => { pdb.SetLargeImage(Resources.video_play_caribbean_blue_32x32) .SetSmallImage(Resources.video_play_caribbean_blue_16x16) .SetToolTips("This is a test for creating a pulldown button"); pdb.CreateButton <CmdSelectGeometry>("cmdSelectGeometry", "Select Geometry", btn => btn .SetLargeImage(Resources.circle_caribbean_blue_32x32) .SetSmallImage(Resources.circle_caribbean_blue_16x16)) .CreateButton <CmdHelloWorld>("pdbY", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16) .SetToolTips("Turn On Event")) .CreateButton <CmdHelloWorld>("pdbButtonZ", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .SetContextualHelp(ContextualHelpType.Url, "https://github.com/TienDuyNGUYEN") .SetToolTips("This is a awesome button!"); }); var pdbEvent = panelLearning .CreatePullDownButton("pdbBtn2", "Options", pdb => { pdb.SetLargeImage(Resources.video_play_caribbean_blue_32x32) .SetSmallImage(Resources.video_play_caribbean_blue_16x16) .SetToolTips("This is a test for creating a pulldown button"); pdb.CreateButton <UIEvent>("btnEvent", "Event", btn => btn .SetLargeImage(Resources.circle_caribbean_blue_32x32) .SetSmallImage(Resources.circle_caribbean_blue_16x16) .SetToolTips("Turn On Event")) .CreateButton <CmdHelloWorld>("pdbY", "Not Assign 1", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <CmdHelloWorld>("pdbButtonZ", "Not Assign 2", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)); }).RvtPulldownButton; panelLearning .CreateSplitButton("splBtn1", "Selection", spl => spl.CreateButton <CmdHelloWorld>("splButton1", "Not Assign", btn => btn .SetLargeImage(Resources.circle_caribbean_blue_32x32) .SetSmallImage(Resources.circle_caribbean_blue_16x16)) .CreateButton <CmdHelloWorld>("splButton2", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <CmdHelloWorld>("splButton3", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <CmdHelloWorld>("splButton4", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <CmdHelloWorld>("splButton5", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <CmdHelloWorld>("splButton6", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <CmdHelloWorld>("splButton7", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16))); myTab .Panel("Panel2") .CreateButton("pl2_btn1", "Not Assign", typeof(CmdHelloWorld), btn => btn .SetLargeImage(Resources.arrow_royal_blue_32x32) .SetSmallImage(Resources.arrow_royal_blue_16x16) .SetContextualHelp(ContextualHelpType.Url, "https://help.autodesk.com")) .CreateSeparator() .CreateButton("pl2_btn2", "Not Assign", typeof(CmdHelloWorld), btn => btn .SetLargeImage(Resources.video_play_caribbean_blue_32x32) .SetSmallImage(Resources.video_play_caribbean_blue_16x16) .SetContextualHelp(ContextualHelpType.Url, "https://help.autodesk.com")); //Create the ribbon on the systemtab ribbon .Tab(Autodesk.Revit.UI.Tab.AddIns) .Panel("VC1") .CreateButton <CmdHelloWorld>("btn1_1", "Button1", btn => btn.SetLargeImage(Resources.x_mark_soylent_red_16x16)); return(Result.Succeeded); }
public static void DoUpgrade(Word.Document doc) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; int sel = doc.Application.Selection.Range.Start; Globals.Chem4WordV3.DisableDocumentEvents(doc); try { string extension = doc.FullName.Split('.').Last(); string guid = Guid.NewGuid().ToString("N"); string timestamp = DateTime.Now.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture); string destination = Path.Combine(Globals.Chem4WordV3.AddInInfo.ProductAppDataPath, "Backups", $"Chem4Word-{timestamp}-{guid}.{extension}"); File.Copy(doc.FullName, destination); } catch (Exception ex) { // Nothing much we can do here :-( Debug.WriteLine(ex.Message); } List <UpgradeTarget> targets = CollectData(doc); int upgradedCCs = 0; int upgradedXml = 0; foreach (var target in targets) { if (target.ContentControls.Count > 0) { upgradedXml++; upgradedCCs += target.ContentControls.Count; } foreach (var cci in target.ContentControls) { foreach (Word.ContentControl cc in doc.ContentControls) { if (cc.ID.Equals(cci.Id)) { if (cci.Type.Equals("2D")) { cc.LockContents = false; cc.Title = Constants.ContentControlTitle; cc.Tag = target.Model.CustomXmlPartGuid; cc.LockContents = true; } else { cc.LockContents = false; cc.Range.Delete(); int start = cc.Range.Start; cc.Delete(); doc.Application.Selection.SetRange(start - 1, start - 1); bool isFormula = false; string source; string text = CustomRibbon.GetInlineText(target.Model, cci.Type, ref isFormula, out source); Word.ContentControl ccn = CustomRibbon.Insert1D(doc.Application, doc, text, isFormula, $"{cci.Type}:{target.Model.CustomXmlPartGuid}"); ccn.LockContents = true; } } } } CMLConverter converter = new CMLConverter(); CustomXMLPart cxml = doc.CustomXMLParts.SelectByID(target.CxmlPartId); cxml.Delete(); doc.CustomXMLParts.Add(converter.Export(target.Model)); } EraseChemistryZones(doc); Globals.Chem4WordV3.EnableDocumentEvents(doc); doc.Application.Selection.SetRange(sel, sel); if (upgradedCCs + upgradedXml > 0) { Globals.Chem4WordV3.Telemetry.Write(module, "Information", $"Upgraded {upgradedCCs} Chemistry Objects for {upgradedXml} Structures"); UserInteractions.AlertUser($"Upgrade Completed{Environment.NewLine}{Environment.NewLine}Upgraded {upgradedCCs} Chemistry Objects for {upgradedXml} Structures"); } }
public static void InsertChemistry(bool isCopy, Application app, FlexDisplay flexDisplay) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; Document doc = app.ActiveDocument; Selection sel = app.Selection; ContentControl cc = null; if (Globals.Chem4WordV3.SystemOptions == null) { Globals.Chem4WordV3.LoadOptions(); } bool allowed = true; string reason = ""; if (Globals.Chem4WordV3.ChemistryAllowed) { if (sel.ContentControls.Count > 0) { cc = sel.ContentControls[1]; if (cc.Title != null && cc.Title.Equals(Constants.ContentControlTitle)) { reason = "a chemistry object is selected"; allowed = false; } } } else { reason = Globals.Chem4WordV3.ChemistryProhibitedReason; allowed = false; } if (allowed) { app.ScreenUpdating = false; Globals.Chem4WordV3.DisableDocumentEvents(doc); try { CMLConverter cmlConverter = new CMLConverter(); Model.Model chem = cmlConverter.Import(flexDisplay.Chemistry); double before = chem.MeanBondLength; if (before < Constants.MinimumBondLength - Constants.BondLengthTolerance || before > Constants.MaximumBondLength + Constants.BondLengthTolerance) { chem.ScaleToAverageBondLength(Constants.StandardBondLength); double after = chem.MeanBondLength; Globals.Chem4WordV3.Telemetry.Write(module, "Information", $"Structure rescaled from {before.ToString("#0.00")} to {after.ToString("#0.00")}"); } if (isCopy) { // Always generate new Guid on Import chem.CustomXmlPartGuid = Guid.NewGuid().ToString("N"); } string guidString = chem.CustomXmlPartGuid; string bookmarkName = "C4W_" + guidString; if (Globals.Chem4WordV3.SystemOptions == null) { Globals.Chem4WordV3.LoadOptions(); } Globals.Chem4WordV3.SystemOptions.WordTopLeft = Globals.Chem4WordV3.WordTopLeft; IChem4WordRenderer renderer = Globals.Chem4WordV3.GetRendererPlugIn( Globals.Chem4WordV3.SystemOptions.SelectedRendererPlugIn); if (renderer == null) { UserInteractions.WarnUser("Unable to find a Renderer Plug-In"); } else { // Export just incase the CustomXmlPartGuid has been changed string cml = cmlConverter.Export(chem); renderer.Properties = new Dictionary <string, string>(); renderer.Properties.Add("Guid", guidString); renderer.Cml = cml; string tempfileName = renderer.Render(); if (File.Exists(tempfileName)) { cc = CustomRibbon.Insert2D(doc, tempfileName, bookmarkName, guidString); if (isCopy) { doc.CustomXMLParts.Add(cml); } try { // Delete the temporary file now we are finished with it File.Delete(tempfileName); } catch { // Not much we can do here } } } } catch (Exception ex) { new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex) .ShowDialog(); } finally { // Tidy Up - Resume Screen Updating and Enable Document Event Handlers app.ScreenUpdating = true; Globals.Chem4WordV3.EnableDocumentEvents(doc); if (cc != null) { // Move selection point into the Content Control which was just edited or added app.Selection.SetRange(cc.Range.Start, cc.Range.End); } } } else { UserInteractions.WarnUser($"You can't insert a chemistry object because {reason}"); } }
public static void DoUpgrade(Word.Document doc) { string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()"; int sel = doc.Application.Selection.Range.Start; Globals.Chem4WordV3.DisableDocumentEvents(doc); List <UpgradeTarget> targets = CollectData(doc); int upgradedCCs = 0; int upgradedXml = 0; foreach (var target in targets) { if (target.ContentControls.Count > 0) { upgradedXml++; upgradedCCs += target.ContentControls.Count; } foreach (var cci in target.ContentControls) { foreach (Word.ContentControl cc in doc.ContentControls) { if (cc.ID.Equals(cci.Id)) { if (cci.Type.Equals("2D")) { cc.LockContents = false; cc.Title = Constants.ContentControlTitle; cc.Tag = target.Model.CustomXmlPartGuid; cc.LockContents = true; } else { cc.LockContents = false; cc.Range.Delete(); int start = cc.Range.Start; cc.Delete(); doc.Application.Selection.SetRange(start - 1, start - 1); bool isFormula = false; string source; string text = CustomRibbon.GetInlineText(target.Model, cci.Type, ref isFormula, out source); Word.ContentControl ccn = CustomRibbon.Insert1D(doc.Application, doc, text, isFormula, $"{cci.Type}:{target.Model.CustomXmlPartGuid}"); ccn.LockContents = true; } } } } CMLConverter converter = new CMLConverter(); CustomXMLPart cxml = doc.CustomXMLParts.SelectByID(target.CxmlPartId); cxml.Delete(); doc.CustomXMLParts.Add(converter.Export(target.Model)); } EraseChemistryZones(doc); Globals.Chem4WordV3.EnableDocumentEvents(doc); doc.Application.Selection.SetRange(sel, sel); if (upgradedCCs + upgradedXml > 0) { Globals.Chem4WordV3.Telemetry.Write(module, "Information", $"Upgraded {upgradedCCs} Chemistry Objects for {upgradedXml} Structures"); UserInteractions.AlertUser($"Upgrade Completed{Environment.NewLine}{Environment.NewLine}Upgraded {upgradedCCs} Chemistry Objects for {upgradedXml} Structures"); } }
public Result OnStartup(UIControlledApplication uiApp) { CustomRibbon ribbon = new CustomRibbon(uiApp); var myTab = ribbon.Tab("TD"); var panelLearning = myTab.Panel("Learning"); var btn1 = panelLearning .CreateButton("btnInfoElement", "Info\nElement", typeof(CmdPickMultiObjects), btn => btn .SetLargeImage(Resources.arrow_royal_blue_32x32) .SetSmallImage(Resources.arrow_royal_blue_16x16) .SetContextualHelp(ContextualHelpType.Url, "https://help.autodesk.com")) .ConvertToPushButton; panelLearning .CreateSeparator() .CreateButton("btnCollectWindow", "Collect\nWindow", typeof(CmdCollector), btn => btn .SetLargeImage(Resources.video_play_caribbean_blue_32x32) .SetSmallImage(Resources.video_play_caribbean_blue_16x16) .SetContextualHelp(ContextualHelpType.Url, "https://help.autodesk.com")); panelLearning .CreateSeparator() .CreateStackedItems(si => si .CreateButton <CmdCollectorWithLINQ>("btnCreateFamily", "CreateCars", btn => btn.SetSmallImage(Resources.circle_caribbean_blue_16x16)) .CreateButton <CmdCreateLineBaseElement>("btnCreateWall", "CreateWall", btn => btn.SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <CmdGetParameter>("btnGetParameter", "Get Parameter", btn => btn.SetSmallImage(Resources.circle_orange_16x16))) .CreateStackedItems(si => si .CreateButton <CmdSetParameter>("btnSetParameter", "Set Parameter", btn => btn.SetSmallImage(Resources.circle_guacamole_green_16x16)) .CreateButton <CmdChangeLocation>("btnChangeLoc", "Change Location", btn => btn.SetSmallImage(Resources.circle_soylent_red_16x16)) .CreateButton <CmdEditElement>("btnEditElement", "EditElement", btn => btn.SetSmallImage(Resources.emoticon_orange_16x16))) .CreateSeparator(); panelLearning .CreatePullDownButton("pdbBtn1", "Options", pdb => { pdb.SetLargeImage(Resources.video_play_caribbean_blue_32x32) .SetSmallImage(Resources.video_play_caribbean_blue_16x16) .SetToolTips("This is a test for creating a pulldown button"); pdb.CreateButton <CmdSelectGeometry>("cmdSelectGeometry", "Select Geometry", btn => btn .SetLargeImage(Resources.circle_caribbean_blue_32x32) .SetSmallImage(Resources.circle_caribbean_blue_16x16)) .CreateButton <HelloWorld>("pdbY", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16) .SetToolTips("Turn On Event")) .CreateButton <HelloWorld>("pdbButtonZ", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .SetContextualHelp(ContextualHelpType.Url, "https://github.com/TienDuyNGUYEN") .SetToolTips("This is a awesome button!"); }); var pdbEvent = panelLearning .CreatePullDownButton("pdbBtn2", "Options", pdb => { pdb.SetLargeImage(Resources.video_play_caribbean_blue_32x32) .SetSmallImage(Resources.video_play_caribbean_blue_16x16) .SetToolTips("This is a test for creating a pulldown button"); pdb.CreateButton <UIEvent>("btnEvent", "Event", btn => btn .SetLargeImage(Resources.circle_caribbean_blue_32x32) .SetSmallImage(Resources.circle_caribbean_blue_16x16) .SetToolTips("Turn On Event")) .CreateButton <HelloWorld>("pdbY", "Not Assign 1", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <HelloWorld>("pdbButtonZ", "Not Assign 2", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)); }).ConvertToPulldownButton; var btnData1 = new CustomPushButton("pdbButton2Z", "Not Assign", typeof(HelloWorld)); btnData1.SetLargeImage(Resources.circle_caribbean_blue_32x32); btnData1.SetSmallImage(Resources.circle_caribbean_blue_32x32); btnData1.SetToolTips("Turn on Event"); var btnSpecial1 = pdbEvent.AddPushButton((PushButtonData)btnData1.GetButtonData()); var btnData2 = new CustomPushButton("pdbButton2Z2", "Not Assign", typeof(HelloWorld)); btnData2.SetLargeImage(Resources.circle_caribbean_blue_32x32); btnData2.SetSmallImage(Resources.circle_caribbean_blue_32x32); var btnSpecial2 = pdbEvent.AddPushButton((PushButtonData)btnData2.GetButtonData()); panelLearning .CreateSplitButton("splBtn1", "Selection", spl => { spl.SetLargeImage(Resources.video_play_caribbean_blue_32x32) .SetSmallImage(Resources.video_play_caribbean_blue_16x16) .SetToolTips("This is a test for creating a pulldown button"); spl.CreateButton <HelloWorld>("splButton1", "Not Assign", btn => btn .SetLargeImage(Resources.circle_caribbean_blue_32x32) .SetSmallImage(Resources.circle_caribbean_blue_16x16)) .CreateButton <HelloWorld>("splButton2", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <HelloWorld>("splButton3", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <HelloWorld>("splButton4", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <HelloWorld>("splButton5", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <HelloWorld>("splButton6", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .CreateButton <HelloWorld>("splButton7", "Not Assign", btn => btn .SetLargeImage(Resources.circle_orange_32x32) .SetSmallImage(Resources.circle_orange_16x16)) .SetContextualHelp(ContextualHelpType.Url, "https://github.com/TienDuyNGUYEN") .SetToolTips("This is a awesome button!"); }); myTab .Panel("Panel2") .CreateButton("pl2_btn1", "Not Assign", typeof(CmdCommand), btn => btn .SetLargeImage(Resources.arrow_royal_blue_32x32) .SetSmallImage(Resources.arrow_royal_blue_16x16) .SetContextualHelp(ContextualHelpType.Url, "https://help.autodesk.com")) .CreateSeparator() .CreateButton("pl2_btn2", "Not Assign", typeof(CmdCommand), btn => btn .SetLargeImage(Resources.video_play_caribbean_blue_32x32) .SetSmallImage(Resources.video_play_caribbean_blue_16x16) .SetContextualHelp(ContextualHelpType.Url, "https://help.autodesk.com")); //Create the ribbon on the systemtab //ribbon // .Tab(Autodesk.Revit.UI.Tab.AddIns) // .Panel("VC1") // .CreateButton<HelloWorld>("btn1_1", "Button1", // btn => btn.SetLargeImage(Resources.x_mark_soylent_red_16x16)); return(Result.Succeeded); }