public PyRevitAttachment(RevitAddonManifest manifest,
                          RevitProduct product,
                          PyRevitAttachmentType attachmentType)
 {
     Manifest       = manifest;
     Product        = product;
     AttachmentType = attachmentType;
 }
Example #2
0
        // clear all bim360 caches
        public static void ClearAllCaches(RevitCacheType cacheType)
        {
            var cacheDirFinder = new Regex(@"\d\d\d\d");

            foreach (RevitProduct revitProduct in RevitProduct.ListInstalledProducts())
            {
                ClearCache(revitProduct.ProductYear, cacheType);
            }
        }
Example #3
0
        private void ProcessBasicFileInfo(string rawBasicInfo)
        {
            bool workSharedFound        = false;
            bool lastPathFound          = false;
            bool centralPathFound       = false;
            bool openWorksetFound       = false;
            bool documentIncrementFound = false;
            bool guidFound = false;

            foreach (string line in rawBasicInfo.Split(new string[] { "\0", "\r\n" },
                                                       StringSplitOptions.RemoveEmptyEntries))
            {
                // find build number
                logger.Debug("Parsing info from BasicFileInfo: \"{0}\"", line);
                var revitProduct = RevitProduct.LookupRevitProduct(line);
                if (revitProduct != null)
                {
                    RevitProduct = revitProduct;
                }

                // find workshared
                if (!workSharedFound)
                {
                    var match = IsWorksharedFinder.Match(line);
                    if (match.Success)
                    {
                        var workshared = match.Groups["workshared"].Value;
                        logger.Debug("IsWorkshared: {0}", workshared);
                        if (!workshared.Contains("Not"))
                        {
                            IsWorkshared = true;
                        }
                        workSharedFound = true;
                    }
                }

                // find last saved path
                if (!lastPathFound)
                {
                    var match = LastSavedPathFinder.Match(line);
                    if (match.Success)
                    {
                        var path = match.Groups["path"].Value;
                        logger.Debug("Last Saved Path: {0}", path);
                        LastSavedPath = path;
                        lastPathFound = true;
                    }
                }

                // find central model path
                if (!centralPathFound)
                {
                    var match = CentralPathFinder.Match(line);
                    if (match.Success)
                    {
                        var path = match.Groups["path"].Value;
                        logger.Debug("Central Model Path: {0}", path);
                        CentralModelPath = path;
                        centralPathFound = true;
                    }
                }

                // find central model path
                if (!openWorksetFound)
                {
                    var match = OpenWorksetFinder.Match(line);
                    if (match.Success)
                    {
                        var owconfig = match.Groups["type"].Value;
                        logger.Debug("Open Workset Default: {0}", owconfig);
                        OpenWorksetConfig = (RevitModelFileOpenWorksetConfig)Enum.ToObject(typeof(RevitModelFileOpenWorksetConfig), int.Parse(owconfig));
                        openWorksetFound  = true;
                    }
                }

                // find central model path
                if (!documentIncrementFound)
                {
                    var match = DocumentIncrementFinder.Match(line);
                    if (match.Success)
                    {
                        var docincrement = match.Groups["type"].Value;
                        logger.Debug("Unique Document Increments: {0}", docincrement);
                        DocumentIncrement      = int.Parse(docincrement);
                        documentIncrementFound = true;
                    }
                }

                // find document guid
                if (!guidFound && line.Contains("Unique Document GUID: "))
                {
                    var guid = line.ExtractGuid();
                    logger.Debug("Extracted GUID: {0}", guid);
                    UniqueId  = guid;
                    guidFound = true;
                }
            }
        }
Example #4
0
        public static List <RevitProduct> ListInstalledProducts()
        {
            var installedRevits = new HashSet <RevitProduct>();

            // pattern for finding revit installation entries in registry
            // matching:
            //     Revit 2019
            //     Revit 2019 - German
            //     Revit Architecture 2016 - Imperial
            // fails:
            //     Revit Content Libraries 2016
            var revitFinder = new Regex(@"^Revit\s[A-Za-z]*\s*\d{4}\s?($|\s-)");

            // open parent regkey
            var uninstallKey =
                Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");

            // loop thru subkeys and find matching
            foreach (var key in uninstallKey.GetSubKeyNames())
            {
                var subkey  = uninstallKey.OpenSubKey(key);
                var appName = subkey.GetValue("DisplayName") as string;
                logger.Debug("Analysing registered app: {0} @ {1}", appName, subkey.Name);
                if (appName != null && revitFinder.IsMatch(appName))
                {
                    logger.Debug("App is a Revit product: {0}", appName);
                    try {
                        // collect info from reg key
                        var regName        = subkey.GetValue("DisplayName") as string;
                        var regVersion     = subkey.GetValue("DisplayVersion") as string;
                        var regInstallPath = (subkey.GetValue("InstallLocation") as string);
                        int regLangCode    = (int)subkey.GetValue("Language");
                        // try to find binary location
                        var binaryFilePath = RevitProductData.GetBinaryLocation(regInstallPath)?.NormalizeAsPath();
                        logger.Debug("Version from registery key: \"{0}\"", regVersion);
                        logger.Debug("Install path from registery key: \"{0}\"", regInstallPath);
                        logger.Debug("Binary path from registery key: \"{0}\"", binaryFilePath);
                        logger.Debug("Language code from registery key: \"{0}\"", regLangCode);

                        // attempt at finding revit product
                        RevitProduct revitProduct = null;
                        logger.Debug("Looking up Revit Product in database...");
                        revitProduct = LookupRevitProduct(regVersion);
                        // if could not determine product by version
                        if (revitProduct is null)
                        {
                            logger.Debug("Could not determine Revit Product from version \"{0}\"", regVersion);
                            // try to get product key from binary version
                            if (binaryFilePath != null)
                            {
                                try {
                                    var prodInfo = RevitProductData.GetBinaryProductInfo(binaryFilePath);
                                    logger.Debug("Read build number \"{0}\" from binary at \"{1}\"", prodInfo.build, binaryFilePath);
                                    revitProduct = LookupRevitProduct(prodInfo.build);
                                    if (revitProduct is null)
                                    {
                                        // revit info might not be available specially if it is new
                                        // lets build a RevitProduct with whatever info we could collect
                                        revitProduct = new RevitProduct(prodInfo);
                                    }
                                }
                                catch {
                                    logger.Debug("Failed reading product info from binary at \"{0}\"", binaryFilePath);
                                }
                            }
                        }

                        if (revitProduct != null)
                        {
                            logger.Debug("Revit Product is : {0}", revitProduct);
                            // grab the registery name if it doesn't have a name
                            if (revitProduct.Name is null || revitProduct.Name == string.Empty)
                            {
                                revitProduct.Name = regName;
                            }

                            // build from a registry version if it doesn't already have one
                            if (revitProduct.Version is null && (regVersion != null && regVersion != string.Empty))
                            {
                                try {
                                    revitProduct.Version = new Version(regVersion);
                                } catch {}
                            }

                            // update install path from registry if it can't find one
                            if (regInstallPath != null && regInstallPath != string.Empty)
                            {
                                if (CommonUtils.VerifyFile(binaryFilePath))
                                {
                                    revitProduct.InstallLocation = regInstallPath;
                                }
                            }

                            // this can only come from registrys
                            revitProduct.LanguageCode = regLangCode;

                            // add to list now
                            installedRevits.Add(revitProduct);
                        }
                        else
                        {
                            logger.Debug("Can not determine Revit product.");
                        }
                    }
                    catch (Exception rpEx) {
                        logger.Error("Error determining installed Revit Product from: {0} | {1} | {2}",
                                     appName, rpEx.Message, rpEx.InnerException.Message);
                    }
                }
            }

            return(installedRevits.ToList());
        }
Example #5
0
        private void ProcessBasicFileInfo(IEnumerable <string> basicInfoDataLines)
        {
            foreach (string line in basicInfoDataLines)
            {
                logger.Debug("Parsing info from BasicFileInfo: \"{0}\"", line);
                // Worksharing: Not enabled
                var match = buildFieldRegex("Worksharing: ", "workshared").Match(line);
                if (match.Success)
                {
                    var workshared = match.Groups["workshared"].Value;
                    logger.Debug("IsWorkshared: {0}", workshared);
                    if (!workshared.Contains("Not"))
                    {
                        IsWorkshared = true;
                    }
                }

                // Username:

                // Central Model Path:
                match = buildFieldRegex("Central Model Path: ", "centralpath").Match(line);
                if (match.Success)
                {
                    var path = match.Groups["centralpath"].Value;
                    logger.Debug("Central Model Path: {0}", path);
                    CentralModelPath = path;
                }

                // Format: 2019

                // Build: 20180806_1515(x64)
                match = buildFieldRegex("Build: ", "build").Match(line);
                if (match.Success)
                {
                    var revitProduct = RevitProduct.LookupRevitProduct(line);
                    if (revitProduct != null)
                    {
                        RevitProduct = revitProduct;
                    }
                }

                // Last Save Path: C:\Users\eirannejad\Desktop\Project1.rvt
                match = buildFieldRegex("Last Save Path: ", "lastpath").Match(line);
                if (match.Success)
                {
                    var path = match.Groups["lastpath"].Value;
                    logger.Debug("Last Saved Path: {0}", path);
                    LastSavedPath = path;
                }

                // Open Workset Default: 3
                match = buildFieldRegex("Open Workset Default: ", "openws").Match(line);
                if (match.Success)
                {
                    var owconfig = match.Groups["openws"].Value;
                    logger.Debug("Open Workset Default: {0}", owconfig);
                    OpenWorksetConfig = (RevitModelFileOpenWorksetConfig)Enum.ToObject(
                        typeof(RevitModelFileOpenWorksetConfig), int.Parse(owconfig)
                        );
                }

                // Project Spark File: 0

                // Central Model Identity: 00000000-0000-0000-0000-000000000000

                // Locale when saved: ENU

                // All Local Changes Saved To Central: 0

                // Central model's version number corresponding to the last reload latest: 4

                // Central model's episode GUID corresponding to the last reload latest: 2ecc6fa1-2960-4473-9fd9-0abce22022fc
                if (line.Contains("Central model's episode GUID corresponding to the last reload latest: "))
                {
                    var guid = line.ExtractGuid();
                    logger.Debug("Extracted Last Reload Latest GUID: {0}", guid);
                    LastReloadLatestUniqueId = guid;
                }

                // Unique Document GUID: 2ecc6fa1-2960-4473-9fd9-0abce22022fc
                if (line.Contains("Unique Document GUID: "))
                {
                    var guid = line.ExtractGuid();
                    logger.Debug("Extracted GUID: {0}", guid);
                    UniqueId = guid;
                }

                // Unique Document Increments: 4
                match = buildFieldRegex("Unique Document Increments: ", "increment").Match(line);
                if (match.Success)
                {
                    var docincrement = match.Groups["increment"].Value;
                    logger.Debug("Unique Document Increments: {0}", docincrement);
                    DocumentIncrement = int.Parse(docincrement);
                }

                // Model Identity: 00000000-0000-0000-0000-000000000000

                // IsSingleUserCloudModel: 慆獬e

                // Author: Autodesk Revit
            }
        }