// Создание полей спецификации
        static List <SchedulableField> GetSchedulableFields(Document doc)
        {
            FilteredElementCollector collector = new FilteredElementCollector(doc);

            Element element = collector.OfClass(typeof(Wall)).First();

            List <SchedulableField> schedulableFields = new List <SchedulableField>();

            // Список параметров из которых будут сделаны поля спецификации
            List <BuiltInParameter> parametersList = new List <BuiltInParameter>()
            {
                BuiltInParameter.CURVE_ELEM_LENGTH,
                BuiltInParameter.HOST_AREA_COMPUTED,
                BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM,
            };

            foreach (BuiltInParameter parameter in parametersList)
            {
                SchedulableField schedulableField = new SchedulableField()
                {
                    ParameterId = element.get_Parameter(parameter).Id
                };
                schedulableFields.Add(schedulableField);
            }
            return(schedulableFields);
        }
Exemplo n.º 2
0
        internal ScheduleField AppendField(ViewSchedule _viewSchedule, string fieldName)
        {
            SchedulableField _schedulableField = _viewSchedule.Definition.GetSchedulableFields()
                                                 .FirstOrDefault(p => p.GetName(_doc).Equals(fieldName));

            if (_schedulableField == null)
            {
                return(null);
            }

            ScheduleField _scheduleField = _viewSchedule.Definition.AddField(_schedulableField);

            return(_scheduleField);
        }
Exemplo n.º 3
0
        static bool IsAlreadyAdded(ViewSchedule schedule, SchedulableField field)
        {
            var ids     = schedule.Definition.GetFieldOrder();
            var isAdded = false;

            foreach (var id in ids)
            {
                if (schedule.Definition.GetField(id).GetSchedulableField() == field)
                {
                    isAdded = true;
                    break;
                }
            }

            return(isAdded);
        }
Exemplo n.º 4
0
        private void CreateSchedule()
        {
            DirectoryInfo d = new DirectoryInfo(@"C:\Programming\Test");

            FileInfo[] files = d.GetFiles("*.txt");
            int        cnt   = 1;

            foreach (FileInfo file in files)
            {
                Transaction t = new Transaction(myRevitDoc, "Create Schedule");
                t.Start();

                string          scheduleName = "Equipment Schedule " + cnt;
                BuiltInCategory category     = BuiltInCategory.OST_MechanicalEquipment;

                List <ViewSchedule> schedules = new List <ViewSchedule>();
                List <string>       guids     = new List <string>();

                ViewSchedule schedule = ViewSchedule.CreateSchedule(myRevitDoc, new ElementId(category), ElementId.InvalidElementId);
                schedule.Name = scheduleName;
                schedules.Add(schedule);

                string   filePath = file.FullName;
                string[] readText = File.ReadAllLines(filePath);

                foreach (string s in readText)
                {
                    guids.Add(s);
                }

                foreach (string guid in guids)
                {
                    SchedulableField schedulableField = schedule.Definition.GetSchedulableFields().FirstOrDefault(x => IsSharedParameterSchedulableField(schedule.Document, x.ParameterId, new Guid(guid)));
                    if (schedulableField != null)
                    {
                        schedule.Definition.AddField(schedulableField);
                    }
                }

                t.Commit();
                cnt++;
            }
        }
        internal ScheduleField AppendField(ViewSchedule _viewSchedule, string fieldName)
        {
            SchedulableField _schedulableField = null;

            if (fieldName.Equals("Elevation", StringComparison.InvariantCultureIgnoreCase))
            {
                // BuiltInParameter.LEVEL_ELEV
            }
            else
            {
                _schedulableField = _viewSchedule.Definition.GetSchedulableFields()
                                    .FirstOrDefault(p => p.GetName(_doc).Equals(fieldName));
            }

            if (_schedulableField == null)
            {
                return(null);
            }

            ScheduleField _scheduleField = _viewSchedule.Definition.AddField(_schedulableField);

            return(_scheduleField);
        }
Exemplo n.º 6
0
        //private UIDocument _uiDoc;
        public Result CreateAllItemsSchedule(UIDocument uiDoc)
        {
            try
            {
                Document doc = uiDoc.Document;
                FilteredElementCollector sharedParameters = new FilteredElementCollector(doc);
                sharedParameters.OfClass(typeof(SharedParameterElement));

                #region Debug

                ////Debug
                //StringBuilder sbDev = new StringBuilder();
                //var list = new ParameterDefinition().ElementParametersAll;
                //int i = 0;

                //foreach (SharedParameterElement sp in sharedParameters)
                //{
                //    sbDev.Append(sp.GuidValue + "\n");
                //    sbDev.Append(list[i].Guid.ToString() + "\n");
                //    i++;
                //    if (i == list.Count) break;
                //}
                ////sbDev.Append( + "\n");
                //// Clear the output file
                //File.WriteAllBytes(InputVars.OutputDirectoryFilePath + "\\Dev.pcf", new byte[0]);

                //// Write to output file
                //using (StreamWriter w = File.AppendText(InputVars.OutputDirectoryFilePath + "\\Dev.pcf"))
                //{
                //    w.Write(sbDev);
                //    w.Close();
                //}

                #endregion

                Transaction t = new Transaction(doc, "Create items schedules");
                t.Start();

                #region Schedule ALL elements
                ViewSchedule schedAll = ViewSchedule.CreateSchedule(doc, ElementId.InvalidElementId,
                                                                    ElementId.InvalidElementId);
                schedAll.Name = "PCF - ALL Elements";
                schedAll.Definition.IsItemized = false;

                IList <SchedulableField> schFields = schedAll.Definition.GetSchedulableFields();

                foreach (SchedulableField schField in schFields)
                {
                    if (schField.GetName(doc) != "Family and Type")
                    {
                        continue;
                    }
                    ScheduleField          field          = schedAll.Definition.AddField(schField);
                    ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId);
                    schedAll.Definition.AddSortGroupField(sortGroupField);
                }

                string curUsage  = "U";
                string curDomain = "ELEM";
                var    query     = from p in new plst().LPAll where p.Usage == curUsage && p.Domain == curDomain select p;

                foreach (pdef pDef in query.ToList())
                {
                    SharedParameterElement parameter = (from SharedParameterElement param in sharedParameters
                                                        where param.GuidValue.CompareTo(pDef.Guid) == 0
                                                        select param).First();
                    SchedulableField queryField = (from fld in schFields where fld.ParameterId.IntegerValue == parameter.Id.IntegerValue select fld).First();

                    ScheduleField field = schedAll.Definition.AddField(queryField);
                    if (pDef.Name != "PCF_ELEM_TYPE")
                    {
                        continue;
                    }
                    ScheduleFilter filter = new ScheduleFilter(field.FieldId, ScheduleFilterType.HasParameter);
                    schedAll.Definition.AddFilter(filter);
                }
                #endregion

                #region Schedule FILTERED elements
                ViewSchedule schedFilter = ViewSchedule.CreateSchedule(doc, ElementId.InvalidElementId,
                                                                       ElementId.InvalidElementId);
                schedFilter.Name = "PCF - Filtered Elements";
                schedFilter.Definition.IsItemized = false;

                schFields = schedFilter.Definition.GetSchedulableFields();

                foreach (SchedulableField schField in schFields)
                {
                    if (schField.GetName(doc) != "Family and Type")
                    {
                        continue;
                    }
                    ScheduleField          field          = schedFilter.Definition.AddField(schField);
                    ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId);
                    schedFilter.Definition.AddSortGroupField(sortGroupField);
                }

                foreach (pdef pDef in query.ToList())
                {
                    SharedParameterElement parameter = (from SharedParameterElement param in sharedParameters
                                                        where param.GuidValue.CompareTo(pDef.Guid) == 0
                                                        select param).First();
                    SchedulableField queryField = (from fld in schFields where fld.ParameterId.IntegerValue == parameter.Id.IntegerValue select fld).First();

                    ScheduleField field = schedFilter.Definition.AddField(queryField);
                    if (pDef.Name != "PCF_ELEM_TYPE")
                    {
                        continue;
                    }
                    ScheduleFilter filter = new ScheduleFilter(field.FieldId, ScheduleFilterType.HasParameter);
                    schedFilter.Definition.AddFilter(filter);
                    filter = new ScheduleFilter(field.FieldId, ScheduleFilterType.NotEqual, "");
                    schedFilter.Definition.AddFilter(filter);
                }
                #endregion

                #region Schedule Pipelines
                ViewSchedule schedPipeline = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_PipingSystem), ElementId.InvalidElementId);
                schedPipeline.Name = "PCF - Pipelines";
                schedPipeline.Definition.IsItemized = false;

                schFields = schedPipeline.Definition.GetSchedulableFields();

                foreach (SchedulableField schField in schFields)
                {
                    if (schField.GetName(doc) != "Family and Type")
                    {
                        continue;
                    }
                    ScheduleField          field          = schedPipeline.Definition.AddField(schField);
                    ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId);
                    schedPipeline.Definition.AddSortGroupField(sortGroupField);
                }

                curDomain = "PIPL";
                foreach (pdef pDef in query.ToList())
                {
                    SharedParameterElement parameter = (from SharedParameterElement param in sharedParameters
                                                        where param.GuidValue.CompareTo(pDef.Guid) == 0
                                                        select param).First();
                    SchedulableField queryField = (from fld in schFields where fld.ParameterId.IntegerValue == parameter.Id.IntegerValue select fld).First();
                    schedPipeline.Definition.AddField(queryField);
                }
                #endregion

                t.Commit();

                sharedParameters.Dispose();

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                BuildingCoderUtilities.InfoMsg(e.Message);
                return(Result.Failed);
            }
        }
Exemplo n.º 7
0
        public static void AddScheduleField(Document document, ViewSchedule schedule, SchedulableField field)
        {
            if (IsAlreadyAdded(schedule, field))
            {
                return;
            }

            var transaction = new Transaction(document, "Add Field");

            transaction.Start();

            schedule.Definition.AddField(field);

            transaction.Commit();
        }