Exemplo n.º 1
0
        public static void CreateSched(Document doc)
        {
            var schedCollector = new FilteredElementCollector(doc).OfClass(typeof(ViewSchedule)).ToList();

            if (!schedCollector.Any(x => x.Name == "FINISH LEGEND"))
            {
                using (Transaction t = new Transaction(doc, "Add Material Schedule"))
                {
                    t.Start();
                    var sched = ViewSchedule.CreateMaterialTakeoff(doc, ElementId.InvalidElementId);
                    sched.Name = "FINISH LEGEND";

                    var Mark = sched.Definition.GetSchedulableFields()
                               .Where(x => x.FieldType == ScheduleFieldType.Material)
                               .FirstOrDefault(x => (BuiltInParameter)x.ParameterId.IntegerValue == BuiltInParameter.ALL_MODEL_MARK);
                    if (Mark != null)
                    {
                        sched.Definition.AddField(Mark);
                    }

                    foreach (var sd in MatPars)
                    {
                        var Field = sched.Definition.GetSchedulableFields().
                                    Where(x => x.FieldType == ScheduleFieldType.Material).
                                    FirstOrDefault(x => IsSharedParameterSchedulableField(doc, x.ParameterId, sd));

                        if (Field != null)
                        {
                            sched.Definition.AddField(Field);
                        }
                    }

                    t.Commit();
                }
            }
            else
            {
                TaskDialog.Show("Error", "The Schedule Already Exists");
            }
        }
Exemplo n.º 2
0
        public void createMaterialTakeOffSchedule(String name, ElementId elementId)
        {
            //Get UIDocument
            UIDocument uidoc = _cachedCmdData.Application.ActiveUIDocument;
            //Get Document
            Document doc = uidoc.Document;

            ViewSchedule schedule = new FilteredElementCollector(CachedDoc).OfClass(typeof(ViewSchedule)).Where(x => x.Name == name + " Schedule").FirstOrDefault() as ViewSchedule;

            if (schedule == null)
            {
                Transaction tSchedule = new Transaction(CachedDoc, "Create Schedule");
                tSchedule.Start();

                //Create an empty view schedule for doors.
                schedule      = ViewSchedule.CreateMaterialTakeoff(CachedDoc, elementId);
                schedule.Name = name + " Schedule";

                ElementId volumeId = new ElementId(BuiltInParameter.MATERIAL_VOLUME);
                ElementId areaId   = new ElementId(BuiltInParameter.MATERIAL_AREA);
                //Iterate all the schedulable fields gotten from the doors view schedule.
                foreach (SchedulableField schedulableField in schedule.Definition.GetSchedulableFields())
                {
                    //See if the FieldType is ScheduleFieldType.Instance.
                    if (schedulableField.ParameterId == volumeId || schedulableField.ParameterId == areaId || schedulableField.GetName(doc).Equals("Material: Keynote"))
                    {
                        //Get ParameterId of SchedulableField.
                        ElementId parameterId = schedulableField.ParameterId;

                        //Add a new schedule field to the view schedule by using the SchedulableField as argument of AddField method of Autodesk.Revit.DB.ScheduleDefinition class.
                        ScheduleField field = schedule.Definition.AddField(schedulableField);

                        //See if the parameterId is a BuiltInParameter.
                        if (Enum.IsDefined(typeof(BuiltInParameter), parameterId.IntegerValue))
                        {
                            BuiltInParameter bip = (BuiltInParameter)parameterId.IntegerValue;
                            //Get the StorageType of BuiltInParameter.
                            Autodesk.Revit.DB.StorageType st = CachedDoc.get_TypeOfStorage(bip);
                            //if StorageType is String or ElementId, set GridColumnWidth of schedule field to three times of current GridColumnWidth.
                            //And set HorizontalAlignment property to left.
                            if (st == Autodesk.Revit.DB.StorageType.String || st == Autodesk.Revit.DB.StorageType.ElementId)
                            {
                                field.GridColumnWidth     = 3 * field.GridColumnWidth;
                                field.HorizontalAlignment = ScheduleHorizontalAlignment.Left;
                            }
                            //For other StorageTypes, set HorizontalAlignment property to center.
                            else
                            {
                                field.HorizontalAlignment = ScheduleHorizontalAlignment.Center;
                            }
                        }

                        if (schedulableField.GetName(doc).Equals("Material: Keynote"))
                        {
                            ScheduleSortGroupField sortGroupField = new ScheduleSortGroupField(field.FieldId);
                            schedule.Definition.AddSortGroupField(sortGroupField);
                            schedule.Definition.IsItemized = false;
                        }

                        if (field.ParameterId == volumeId)
                        {
                            FormatOptions formatOpt = new FormatOptions(DisplayUnitType.DUT_CUBIC_FEET, UnitSymbolType.UST_CF, 0.01);
                            formatOpt.UseDefault = false;
                            field.SetFormatOptions(formatOpt);
                            field.DisplayType = ScheduleFieldDisplayType.Totals;
                        }

                        if (field.ParameterId == areaId)
                        {
                            FormatOptions formatOpt = new FormatOptions(DisplayUnitType.DUT_SQUARE_FEET, UnitSymbolType.UST_SF, 0.01);
                            formatOpt.UseDefault = false;
                            field.SetFormatOptions(formatOpt);
                            field.DisplayType = ScheduleFieldDisplayType.Totals;
                        }
                    }
                }


                tSchedule.Commit();
                tSchedule.Dispose();
            }
            else
            {
                schedule.RefreshData();
            }

            ViewScheduleExportOptions opt = new ViewScheduleExportOptions();

            opt.FieldDelimiter = ",";
            opt.Title          = false;

            string path = _export_folder_name;


            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }


            string file = System.IO.Path.GetFileNameWithoutExtension(name) + ".csv";

            schedule.Export(path, file, opt);
        }
Exemplo n.º 3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            _itemizar    = false;
            _linked      = false;
            _numerar     = true;
            _prefijo     = "-";
            _sufijo      = "";
            _marca       = false;
            _comentarios = false;
            _descripcion = true;
            _modelo      = false;
            _marcaTipo   = false;

            System.Windows.Forms.DialogResult resultado = (new frmCrearTablas(uidoc.Document)).ShowDialog();

            if (resultado == System.Windows.Forms.DialogResult.OK)
            {
                List <ViewSchedule> tablas = new List <ViewSchedule>();

                // Creamos y abrimos una transacción
                using (Transaction t = new Transaction(doc, "Crear Tablas"))
                {
                    t.Start();
                    // Ordenar Categorias
                    Tools.categorias = Tools.categorias.OrderBy(x => x.Name).ToList();

                    int count     = 1;
                    int countMats = 1;
                    try
                    {
                        // Crear una Tabla para cada Categoría
                        foreach (Category cat in Tools._selectedCategories)
                        {
                            string nombre = "";
                            if (_numerar)
                            {
                                nombre += count.ToString();
                            }
                            if (_prefijo != "")
                            {
                                nombre += _prefijo;
                            }
                            nombre += " " + cat.Name;
                            if (_sufijo != "")
                            {
                                nombre += _sufijo;
                            }

                            ViewSchedule tabla = ViewSchedule.CreateSchedule(doc, cat.Id);
                            tabla.Name = nombre;
                            count++;
                            // ver 1.4 MEP
                            bool mep        = false;
                            bool pipeSystem = false;
                            bool ductSystem = false;
                            if (cat.Id.IntegerValue == -2008044) //Pipes
                            {
                                mep        = true;
                                pipeSystem = true;
                            }
                            if (cat.Id.IntegerValue == -2008049) //PipeFittings
                            {
                                mep        = true;
                                pipeSystem = true;
                            }
                            if (cat.Id.IntegerValue == -2008055) //Pipe Accesories
                            {
                                mep        = true;
                                pipeSystem = true;
                            }
                            if (cat.Id.IntegerValue == -2008050) //FlexPipe
                            {
                                //mep = true; // DEBE SER TAMAÑO TOTAL
                                pipeSystem = true;
                            }
                            if (cat.Id.IntegerValue == -2008000) // Duct
                            {
                                mep        = true;
                                ductSystem = true;
                            }
                            if (cat.Id.IntegerValue == -2008010) // DuctFitting
                            {
                                mep        = true;
                                ductSystem = true;
                            }
                            if (cat.Id.IntegerValue == -2008016) // Duct Accesories
                            {
                                mep        = true;
                                ductSystem = true;
                            }
                            if (cat.Id.IntegerValue == -2008020) // FlexDuct
                            {
                                //mep = true; // DEBE SER TAMAÑO TOTAL
                                ductSystem = true;
                            }
                            if (cat.Id.IntegerValue == -2008132) // Conduit
                            {
                                mep = true;
                            }
                            if (cat.Id.IntegerValue == -2008128) // ConduitFitting
                            {
                                mep = true;
                            }
                            if (cat.Id.IntegerValue == -2008130) // CableTray
                            {
                                mep = true;
                            }
                            if (cat.Id.IntegerValue == -2008126) // CableTrayFittings
                            {
                                mep = true;
                            }
                            Tools.FillSchedule(tabla, _itemizar, _linked, mep, pipeSystem, ductSystem);
                            // Phase Filter
                            Parameter tablaFilter = tabla.get_Parameter(BuiltInParameter.VIEW_PHASE_FILTER);
                            tablaFilter.Set(new ElementId(-1));
                            tablas.Add(tabla);
                        }
                        // Create Material Schedules
                        foreach (Category cat in Tools._selectedMatCategories)
                        {
                            int createMat = 0;

                            if (cat.HasMaterialQuantities)// && cat.Material != null)
                            {
                                if (cat.Id == new ElementId(BuiltInCategory.OST_Walls))
                                {
                                    createMat = 1;
                                }
                                if (cat.Id == new ElementId(BuiltInCategory.OST_Floors))
                                {
                                    createMat = 1;
                                }
                                if (cat.Id == new ElementId(BuiltInCategory.OST_Roofs))
                                {
                                    createMat = 1;
                                }
                                if (cat.Id == new ElementId(BuiltInCategory.OST_Ceilings))
                                {
                                    createMat = 1;
                                }
                                if (cat.Id == new ElementId(BuiltInCategory.OST_BuildingPad))
                                {
                                    createMat = 1;
                                }

                                if (createMat == 1)
                                {
                                    string nombre = "M";
                                    if (_numerar)
                                    {
                                        nombre += countMats.ToString();
                                    }
                                    if (_prefijo != "")
                                    {
                                        nombre += _prefijo;
                                    }
                                    nombre += " " + cat.Name;
                                    if (_sufijo != "")
                                    {
                                        nombre += _sufijo;
                                    }

                                    ViewSchedule tablaMat = ViewSchedule.CreateMaterialTakeoff(doc, cat.Id);
                                    tablaMat.Name = nombre + " (Materiales)";
                                    // Phase Filter
                                    Parameter tablaFilter = tablaMat.get_Parameter(BuiltInParameter.VIEW_PHASE_FILTER);
                                    tablaFilter.Set(new ElementId(-1));
                                    countMats++;
                                    Tools.FillScheduleMaterial(tablaMat, _itemizar, _linked);
                                    tablas.Add(tablaMat);
                                }
                            }
                        }
                        t.Commit();
                    }
                    catch (Exception ex)
                    {
                        TaskDialog.Show("Universo BIM", "Error: " + ex.Message);
                        t.RollBack();
                    }
                }
                TaskDialog.Show("Universo BIM", "Se han creado " + tablas.Count + " Tablas");
            }

            return(Result.Succeeded);
        }