/// <summary> /// Updates the Libarary Layout spec to include layout for Steel nodes. /// The Steel layout spec is embeded as resource "LayoutSpecs.json". /// </summary> private static void UpdateLibraryLayoutSpec() { var customization = Model.DynamoModel.ExtensionManager.Service <ILibraryViewCustomization>(); if (customization == null) { return; } //Make sure to notify customization for application closing DynamoSteelApp.ShutdownHandler = () => customization.OnAppShutdown(); //Register the icon resource /*customization.RegisterResourceStream("/icons/Category.AdvanceSteel.svg", * GetResourceStream("Dynamo.Applications.Resources.Category.AdvanceSteel.svg"));*/ LayoutSpecification steelSpecs; using (Stream stream = GetResourceStream("Dynamo.Applications.Resources.LayoutSpecs.json")) { steelSpecs = LayoutSpecification.FromJSONStream(stream); } //The steelSpec should have only one section, add all its child elements to the customization var elements = steelSpecs.sections.First().childElements; customization.AddElements(elements); //add all the elements to default section }
/// <summary> /// Updates the Libarary Layout spec to include layout for Revit nodes. /// The Revit layout spec is embeded as resource "LayoutSpecs.json". /// </summary> private static void UpdateLibraryLayoutSpec() { //Get the library view customization service to update spec var customization = revitDynamoModel.ExtensionManager.Service <ILibraryViewCustomization>(); if (customization == null) { return; } if (shutdownHandler == null && extCommandData != null) { //Make sure to notify customization for application closing, so that //the CEF can be shutdown for clean Revit exit shutdownHandler = () => customization.OnAppShutdown(); extCommandData.Application.ApplicationClosing += (o, _) => shutdownHandler(); } //Register the icon resource customization.RegisterResourceStream("/icons/Category.Revit.svg", GetResourceStream("Dynamo.Applications.Resources.Category.Revit.svg")); //Read the revitspec from the resource stream LayoutSpecification revitspec; using (Stream stream = GetResourceStream("Dynamo.Applications.Resources.LayoutSpecs.json")) { revitspec = LayoutSpecification.FromJSONStream(stream); } //The revitspec should have only one section, add all its child elements to the customization var elements = revitspec.sections.First().childElements; customization.AddElements(elements); //add all the elements to default section }
/// <summary> /// Updates the Libarary Layout spec to include layout for Steel nodes. /// The Steel layout spec is embeded as resource "LayoutSpecs.json". /// </summary> private static void UpdateLibraryLayoutSpec() { //Get the library view customization service to update spec var customization = advanceSteelModel.ExtensionManager.Service <ILibraryViewCustomization>(); if (customization == null) { return; } //Register the icon resource /*customization.RegisterResourceStream("/icons/Category.AdvanceSteel.svg", * GetResourceStream("Dynamo.Applications.Resources.Category.AdvanceSteel.svg"));*/ //Read the steelSpec from the resource stream LayoutSpecification steelSpecs; using (Stream stream = GetResourceStream("Dynamo.Applications.Resources.LayoutSpecs.json")) { steelSpecs = LayoutSpecification.FromJSONStream(stream); } //The steelSpec should have only one section, add all its child elements to the customization var elements = steelSpecs.sections.First().childElements; customization.AddElements(elements); //add all the elements to default section }
/// <summary> /// Updates the Libarary Layout spec to include layout for Revit nodes. /// The Revit layout spec is embeded as resource "LayoutSpecs.json". /// </summary> private static void UpdateLibraryLayoutSpec() { //Get the library view customization service to update spec var customization = revitDynamoModel.ExtensionManager.Service <ILibraryViewCustomization>(); if (customization == null) { return; } if (shutdownHandler == null && extCommandData != null) { //Make sure to notify customization for application closing, so that //the CEF can be shutdown for clean Revit exit shutdownHandler = () => customization.OnAppShutdown(); extCommandData.Application.ApplicationClosing += (o, _) => shutdownHandler(); } //Register the icon resource customization.RegisterResourceStream("/icons/Category.Revit.svg", GetResourceStream("Dynamo.Applications.Resources.Category.Revit.svg")); //Read the revitspec from the resource stream LayoutSpecification revitspec; using (Stream stream = GetResourceStream("Dynamo.Applications.Resources.LayoutSpecs.json")) { revitspec = LayoutSpecification.FromJSONStream(stream); } //The revitspec should have only one section, add all its child elements to the customization var elements = revitspec.sections.First().childElements; // Extend it with the layoutSpecs from internal nodes var internalNodesLayouts = DynamoRevitInternalNodes.GetLayoutSpecsFiles(); foreach (var layoutSpecsFile in internalNodesLayouts) { try { LayoutSpecification spec = LayoutSpecification.FromJSONString(File.ReadAllText(layoutSpecsFile)); var revitSection = spec.sections.First(); var revitCategory = revitSection.childElements.First(); var revitCategoryToExtend = elements.First(elem => elem.text == "Revit"); revitCategoryToExtend.childElements.AddRange(revitCategory.childElements); } catch (Exception ex) { Console.WriteLine(string.Format("Exception while trying to load {0}", layoutSpecsFile)); } } customization.AddElements(elements); //add all the elements to default section }
/// <summary> /// 构造函数 /// </summary> /// <param name="resource">The resource name of json resource in the given assembly.</param> /// <param name="assembly">Assembly which contains the specified resource</param> public LayoutSpecProvider(ILibraryViewCustomization customization, string resource, Assembly assembly = null) : base(false) { assembly = assembly == null?Assembly.GetExecutingAssembly() : assembly; var stream = assembly.GetManifestResourceStream(resource); //Get the spec from the stream var spec = LayoutSpecification.FromJSONStream(stream); customization.AddSections(spec.sections); this.customization = customization; this.customization.SpecificationUpdated += OnSpecificationUpdate; }
public void ToJSONStream() { ILibraryViewCustomization customization = new LibraryViewCustomization(); var sections = new[] { "A", "B", "C" }.Select(s => new LayoutSection(s)); customization.AddSections(sections); using (var stream = customization.ToJSONStream()) { var spec = LayoutSpecification.FromJSONStream(stream); Assert.AreEqual(3, spec.sections.Count); Assert.AreEqual("A, B, C", string.Join(", ", spec.sections.Select(s => s.text))); } }