Example #1
0
        /// <summary>
        ///     Creates a revit link.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="linkPath"></param>
        /// <returns></returns>
        public static void AddRevitLink(this Document doc, string linkPath)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (linkPath == null)
            {
                throw new ArgumentNullException(nameof(linkPath));
            }

            var filePathl  = new FilePath(linkPath);
            var linkOption = new RevitLinkOptions(false);

            doc.AutoTransaction(() =>
            {
                var result   = RevitLinkType.Create(doc, filePathl, linkOption);
                var instance = RevitLinkInstance.Create(doc, result.ElementId);

                if (!(doc.GetElement(instance.GetTypeId()) is RevitLinkType type))
                {
                    return;
                }

                type.AttachmentType = AttachmentType.Attachment;
                type.PathType       = PathType.Relative;
            });
        }
Example #2
0
        /// <summary>
        /// Creates an instance for the Revit file selected
        /// </summary>
        /// <param name="doc">Document to which the link should be added</param>
        /// <param name="revitFilePath">the full path of the Revit link to be added</param>
        private static void InstanceMaker(Document doc, string revitFilePath)
        {
            try
            {
                using (Transaction tr = new Transaction(doc))
                {
                    tr.Start("Revit files are being linked...");

                    // Cycle through the list
                    // Set the standard options and behavior for the links
                    FilePath         fp  = new FilePath(revitFilePath);
                    RevitLinkOptions rlo = new RevitLinkOptions(false);

                    // Create new revit link and store the path to the file as either absolute or relative
                    RevitLinkLoadResult result = RevitLinkType.Create(doc, fp, rlo);
                    ElementId           linkId = result.ElementId;

                    // Create the Revit Link Instance (this also automatically sets the link Origin-to-Origin)
                    // Pin the Revit link as well
                    RevitLinkInstance linkInstance = RevitLinkInstance.Create(doc, linkId);
                    linkInstance.Pinned = true;

                    tr.Commit();
                }
            }

            catch (Exception)
            {
                // not sure what exceptions may occur
                // make sure that whatever happens is logged for future troubleshooting
            }
        }
Example #3
0
        public void Load_Form(UIApplication uiapp, Document doc)
        {
            try
            {
                data_revit_link item = (data_revit_link)link_file.SelectedItem;
                doc.Delete(item.type.Id);

                ModelPath        mp  = ModelPathUtils.ConvertUserVisiblePathToModelPath(path);
                RevitLinkOptions rlo = new RevitLinkOptions(false);
                var linkType         = RevitLinkType.Create(doc, mp, rlo);
                var instance         = RevitLinkInstance.Create(doc, linkType.ElementId);

                List <Document> docs = new List <Document>();
                foreach (Document d in uiapp.Application.Documents)
                {
                    docs.Add(d);
                }
                item.document = docs.First(y => y.Title + ".rvt" == item.name);
                item.type     = doc.GetElement(linkType.ElementId) as RevitLinkType;
                link_file.Items.Refresh();
                MessageBox.Show(item.document.PathName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                link_file.SelectedItem = null;
            }
        }
        public ElementId CreateRevitLink(Document doc, string pathName)
        {
            FilePath         path    = new FilePath(pathName);
            RevitLinkOptions options = new RevitLinkOptions(false);
            // Create new revit link storing absolute path to file
            LinkLoadResult result = RevitLinkType.Create(doc, path, options);

            return(result.ElementId);
        }
Example #5
0
 public void Link_File(Document doc)
 {
     try
     {
         ModelPath        mp  = ModelPathUtils.ConvertUserVisiblePathToModelPath(path);
         RevitLinkOptions rlo = new RevitLinkOptions(false);
         var linkType         = RevitLinkType.Create(doc, mp, rlo);
         var instance         = RevitLinkInstance.Create(doc, linkType.ElementId);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #6
0
        public void Execute(UIApplication app)
        {
            GetLogs.SetNewLog(null, "--", ProjectDto.Id);
            var stp_watch = new Stopwatch();

            stp_watch.Start();

            Document doc = app.ActiveUIDocument.Document;

            foreach (ModelDto model in ModelList)
            {
                using (Transaction loadDoc = new Transaction(doc, "Load Link Documents"))
                {
                    loadDoc.Start();
                    RevitLinkOptions rvtLinkOptions = new RevitLinkOptions(false);


                    ModelPath         modelPath      = ModelPathUtils.ConvertUserVisiblePathToModelPath(model.ModelPath);
                    LinkLoadResult    linkType       = RevitLinkType.Create(doc, modelPath, rvtLinkOptions);
                    RevitLinkInstance openedDocument = RevitLinkInstance.Create(doc, linkType.ElementId);


                    Document docLink = openedDocument.GetLinkDocument();
                    stp_watch.Stop();
                    GetLogs.SetNewLog(stp_watch.Elapsed.ToString(), "Добавление модели: " + model.ModelName, ProjectDto.Id);
                    stp_watch.Restart();
                    stp_watch.Start();
                    /* Получить все экземплярый и записать их в бд */
                    List <Element> instances = FindElements(docLink, GetCategoryFilter(), true).Where(x => x != null).ToList();
                    dataBaseFamilies.AddFamilies(instances.Select(x => new FamilyDto()
                    {
                        Categoty     = x.Category.Name,
                        FamilyInstId = x.Id.IntegerValue,
                        FamilyTypeId = x.GetTypeId().IntegerValue,
                        ModelId      = model.Id
                    }).ToList());

                    stp_watch.Stop();
                    GetLogs.SetNewLog(stp_watch.Elapsed.ToString(), "Создание нового списка семейств и запись в БД. Количество семейств: " + instances.Count, ProjectDto.Id);

                    stp_watch.Restart();
                    stp_watch.Start();
                    var FamlistFroDb = dataBaseFamilies.GetFamilyInstances(model);
                    List <ParameterInstanceDto> ParamsInstList = new List <ParameterInstanceDto>();
                    List <ParameterTypeDto>     ParamsTypeList = new List <ParameterTypeDto>();
                    foreach (Element elem in instances)
                    {
                        var famId = FamlistFroDb.Where(x => x.FamilyInstId == elem.Id.IntegerValue).FirstOrDefault().Id;

                        ParamsInstList.AddRange(elem.Parameters.ToList().Select(x => new ParameterInstanceDto()
                        {
                            Name     = x.Definition.Name,
                            FamilyId = famId
                        }).ToList());
                    }
                    stp_watch.Stop();
                    GetLogs.SetNewLog(stp_watch.Elapsed.ToString(), "Создание списка параметров экземпляров. Количество параметров: " + ParamsInstList.Count, ProjectDto.Id);
                    stp_watch.Restart();
                    stp_watch.Start();

                    foreach (Element elem in instances)
                    {
                        var famId = FamlistFroDb.Where(x => x.FamilyInstId == elem.Id.IntegerValue).FirstOrDefault().Id;

                        var elemType = docLink.GetElement(elem.GetTypeId());

                        if (elemType != null)
                        {
                            ParamsTypeList.AddRange((elemType.Parameters.ToList().Select(x => new ParameterTypeDto()
                            {
                                Name = x.Definition.Name,
                                FamilyId = famId
                            }).ToList()));
                        }
                    }

                    stp_watch.Stop();
                    GetLogs.SetNewLog(stp_watch.Elapsed.ToString(), "Создание списка параметров типов. Количество параметров: " + ParamsTypeList.Count, ProjectDto.Id);
                    stp_watch.Restart();
                    stp_watch.Start();

                    dataBaseParameters.AddParameterInstances(ParamsInstList);

                    stp_watch.Stop();
                    GetLogs.SetNewLog(stp_watch.Elapsed.ToString(), "Выгрузка параметров экземпляров в БД", ProjectDto.Id);
                    stp_watch.Restart();
                    stp_watch.Start();

                    dataBaseParameters.AddParameterTypes(ParamsTypeList);
                    stp_watch.Stop();
                    GetLogs.SetNewLog(stp_watch.Elapsed.ToString(), "Выгрузка параметров типов в БД", ProjectDto.Id);


                    loadDoc.RollBack();
                }
            }
            stp_watch.Stop();

            //GetLogs.SetNewLog(stp_watch.Elapsed.TotalMinutes.ToString(), "Выгрузка параметров", ProjectDto.Id);
            //TaskDialog.Show("Время выгрузки", upload_link_model.ToString());
        }