Esempio n. 1
0
        /// <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
        }
Esempio n. 2
0
        internal RevitPathResolver(string userDataFolder, string commonDataFolder)
        {
            // The executing assembly will be in Revit_20xx folder,
            // so we have to walk up one level.
            var currentAssemblyPath = Assembly.GetExecutingAssembly().Location;
            var currentAssemblyDir  = Path.GetDirectoryName(currentAssemblyPath);

            var nodesDirectory = Path.Combine(currentAssemblyDir, "nodes");
            var revitNodesDll  = Path.Combine(currentAssemblyDir, "RevitNodes.dll");

            // Just making sure we are looking at the right level of nesting.
            if (!Directory.Exists(nodesDirectory))
            {
                throw new DirectoryNotFoundException(nodesDirectory);
            }
            if (!File.Exists(revitNodesDll))
            {
                throw new FileNotFoundException(revitNodesDll);
            }

            // Add Revit-specific library paths for preloading.
            preloadLibraryPaths = new List <string>
            {
                "VMDataBridge.dll",
                "ProtoGeometry.dll",
                "DesignScriptBuiltin.dll",
                "DSCoreNodes.dll",
                "DSOffice.dll",
                "DSIronPython.dll",
                "FunctionObject.ds",
                "BuiltIn.ds",
                "DynamoConversions.dll",
                "DynamoUnits.dll",
                "Tessellation.dll",
                "Analysis.dll",
                "GeometryColor.dll",

                revitNodesDll
            };

            // Add an additional node processing folder
            additionalNodeDirectories = new List <string> {
                nodesDirectory
            };

            // Add the Revit_20xx folder for assembly resolution
            additionalResolutionPaths = new List <string> {
                currentAssemblyDir
            };

            // Add other internal nodes to preload list
            var internalNodes = DynamoRevitInternalNodes.GetNodesToPreload();

            foreach (var assemblyPath in internalNodes)
            {
                if (File.Exists(assemblyPath))
                {
                    preloadLibraryPaths.Add(assemblyPath);
                    string assemblyDir = Path.GetDirectoryName(assemblyPath);
                    additionalNodeDirectories.Add(assemblyDir);
                    additionalResolutionPaths.Add(assemblyDir);
                }
            }

            this.userDataRootFolder   = userDataFolder;
            this.commonDataRootFolder = commonDataFolder;
        }