示例#1
0
        Stream(ArrayList data, FamilyInstanceCreationData famInstData)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(FamilyInstanceCreationData)));

            data.Add(new Snoop.Data.Object("Axis", famInstData.Axis));
            data.Add(new Snoop.Data.Double("Rotate angle", famInstData.RotateAngle));
        }
        private void Stream(ArrayList data, FamilyInstanceCreationData famInstData)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(FamilyInstanceCreationData)));

            data.Add(new Snoop.Data.Object("Axis", famInstData.Axis));
            data.Add(new Snoop.Data.Double("Rotate angle", famInstData.RotateAngle));
        }
示例#3
0
        CollectEvent(object sender, CollectorEventArgs e)
        {
            // cast the sender object to the SnoopCollector we are expecting
            Collector snoopCollector = sender as Collector;

            if (snoopCollector == null)
            {
                Debug.Assert(false);    // why did someone else send us the message?
                return;
            }

            Application app = e.ObjToSnoop as Application;

            if (app != null)
            {
                Stream(snoopCollector.Data(), app);
                return;
            }

            FamilyInstanceCreationData famInstData = e.ObjToSnoop as FamilyInstanceCreationData;

            if (famInstData != null)
            {
                Stream(snoopCollector.Data(), famInstData);
                return;
            }

            ItemFactoryBase itemFactBase = e.ObjToSnoop as ItemFactoryBase;

            if (itemFactBase != null)
            {
                Stream(snoopCollector.Data(), itemFactBase);
                return;
            }
        }
        private void btnEjemplares_Click(object sender, EventArgs e)
        {
            // Verificaciones de las selecciones del usuario
            if (this.cmbCategorias.SelectedItem == null)
            {
                TaskDialog.Show("Revit", "Debe seleccionar una Categoría");
                return;
            }
            if (this.cmbFamilias.SelectedItem == null)
            {
                TaskDialog.Show("Revit", "Debe seleccionar un Tipo de Familia");
                return;
            }
            if (this.cmbNiveles.SelectedItem == null)
            {
                TaskDialog.Show("Revit", "Debe seleccionar un Nivel");
                return;
            }
            if (this.dgvCoordenadas.Rows.Count <= 1)
            {
                TaskDialog.Show("Revit", "Debe ingresar valores de coordenadas");
                return;
            }
            // Todo Ok, procesar elementos
            // Obtener la lista de Puntos
            List <XYZ> listaPuntos = ConvertirPuntos();

            // Obtener el FamilySymbol
            string       nombreFamilia = this.cmbFamilias.SelectedItem.ToString();
            FamilySymbol familia       = Tools.ObtenerFamilySymbolPorNombre(_doc, nombreFamilia);

            // Obtener el Nivel seleccionado
            string nombreNivel = this.cmbNiveles.SelectedItem.ToString();
            Level  nivel       = Tools.ObtenerNivelPorNombre(_doc, nombreNivel);

            // Structural Type
            StructuralType tipoEstructural = StructuralType.NonStructural;

            // Crear la lista de FamilyInstanceCreationData
            List <FamilyInstanceCreationData> listaData = new List <FamilyInstanceCreationData>();

            // Recorrer los puntos XYZ
            foreach (XYZ punto in listaPuntos)
            {
                FamilyInstanceCreationData data = new FamilyInstanceCreationData(punto, familia, nivel, tipoEstructural);
                listaData.Add(data);
            }

            // Iniciar la Transaccion y crear los elementos
            Transaction t = new Transaction(_doc, "Crear elementos");

            t.Start();
            _doc.Create.NewFamilyInstances2(listaData);
            t.Commit();
            TaskDialog.Show("Revit", "Los elementos se crearon con éxito");
        }
        private ICollection <ElementId> BatchCreateColumns(Autodesk.Revit.DB.Document document, Level level)
        {
            List <FamilyInstanceCreationData> fiCreationDatas = new List <FamilyInstanceCreationData>();

            ICollection <ElementId> elementSet = null;

            //Try to get a FamilySymbol
            FamilySymbol             familySymbol = null;
            FilteredElementCollector collector    = new FilteredElementCollector(document);
            ICollection <Element>    collection   = collector.OfClass(typeof(FamilySymbol)).ToElements();

            foreach (Element e in collection)
            {
                familySymbol = e as FamilySymbol;
                if (null != familySymbol.Category)
                {
                    if ("結構柱" == familySymbol.Category.Name)
                    {
                        break;
                    }
                }
            }

            if (null != familySymbol)
            {
                //Create 10 FamilyInstanceCreationData items for batch creation
                for (int i = 1; i < 11; i++)
                {
                    XYZ location = new XYZ(i * 10, 100, 0);
                    FamilyInstanceCreationData fiCreationData =
                        new FamilyInstanceCreationData(location, familySymbol, level, StructuralType.Column);

                    if (null != fiCreationData)
                    {
                        fiCreationDatas.Add(fiCreationData);
                    }
                }

                if (fiCreationDatas.Count > 0)
                {
                    // Create Columns
                    elementSet = document.Create.NewFamilyInstances2(fiCreationDatas);
                }
                else
                {
                    throw new Exception("Batch creation failed.");
                }
            }
            else
            {
                throw new Exception("No column types found.");
            }

            return(elementSet);
        }
        private void btnColocar_Click(object sender, EventArgs e)
        {
            // Verificar selecciones
            if (this.cmbCategorias.SelectedItem == null)
            {
                TaskDialog.Show("Revit", "Debe seleccionar una Categoría");
                return;
            }
            if (this.cmbFamilias.SelectedItem == null)
            {
                TaskDialog.Show("Revit", "Debe seleccionar una Familia");
                return;
            }
            if (this.cmbNiveles.SelectedItem == null)
            {
                TaskDialog.Show("Revit", "Debe seleccionar un Nivel");
                return;
            }
            if (this.dgvPuntos.Rows.Count <= 1)
            {
                TaskDialog.Show("Revit", "Debe ingresar coordenadas en la Lista de Puntos");
                return;
            }
            // Todo OK, proceder
            // Obtener Lista de Puntos
            List <XYZ> puntos = ObtenerListaPuntos();

            // Obtener elementos seleccionados
            FamilySymbol family = Tools.GetFamilySymbolByName(_doc, this.cmbFamilias.SelectedItem.ToString());
            Level        lvl    = Tools.GetLevelByName(_doc, this.cmbNiveles.SelectedItem.ToString());
            List <FamilyInstanceCreationData> lstData = new List <FamilyInstanceCreationData>();

            // Crear Transaccion
            Transaction t = new Transaction(_doc, "Crear ejemplares");

            t.Start();
            // Procesar los Puntos y crear una Lista de Data
            foreach (XYZ punto in puntos)
            {
                // Crear objeto FamilyInstanceCreationData
                FamilyInstanceCreationData fiData = new FamilyInstanceCreationData(punto, family, StructuralType.NonStructural);
                lstData.Add(fiData);
            }
            // Colocar ejemplares
            _doc.Create.NewFamilyInstances2(lstData);
            t.Commit();
            TaskDialog.Show("Revit", "Elementos colocados correctamente");
            this.Close();
        }
        public override Value Evaluate(FSharpList<Value> args)
        {
            var xyzs = ((Value.List)args[0]).Item;
            var symbol = (FamilySymbol) ((Value.Container) args[1]).Item;

            var instData = new List<FamilyInstanceCreationData>();
            var updated = new HashSet<ElementId>();

            int count = 0;

            #region batch creation data

            var sw = new Stopwatch();
            sw.Start();
            foreach (var pts in xyzs)
            {
                FamilyInstance instance = null;
                if (Elements.Count > count)
                {
                    if (dynUtils.TryGetElement(this.Elements[count], out instance))
                    {
                        //if we've found an instance, change its symbol if it needs
                        //changing
                        if (instance.Symbol != symbol)
                            instance.Symbol = symbol;

                        //update the placement points and add the
                        //id to the list of updated acs
                        UpdatePlacementPoints(instance, xyzs, count);
                        updated.Add(Elements[count]);
                    }
                    else
                    {
                        var instanceData = new FamilyInstanceCreationData(XYZ.Zero, symbol, StructuralType.NonStructural);
                        instData.Add(instanceData);
                    }
                }
                else
                {
                    var instanceData = new FamilyInstanceCreationData(XYZ.Zero, symbol, StructuralType.NonStructural);
                    instData.Add(instanceData);
                }

                count++;
            }
            sw.Stop();
            Debug.WriteLine(string.Format("{0} elapsed for updating existing or generating family creation data.", sw.Elapsed));
            sw.Reset();

            #endregion

            //trim the elements collection
            foreach (var e in this.Elements.Skip(count))
            {
                DeleteElement(e);
            }

            FSharpList<Value> results = FSharpList<Value>.Empty;

            sw.Start();
            if (instData.Any())
            {
                ICollection<ElementId> ids;
                if (dynRevitSettings.Doc.Document.IsFamilyDocument)
                {
                    ids = dynRevitSettings.Doc.Document.FamilyCreate.NewFamilyInstances2(instData);
                }
                else
                {
                    ids = dynRevitSettings.Doc.Document.Create.NewFamilyInstances2(instData);
                }

                //add our batch-created instances ids'
                //to the elements collection
                ids.ToList().ForEach(x => Elements.Add(x));
            }
            sw.Stop();
            Debug.WriteLine(string.Format("{0} elapsed for creating instances from creation data.", sw.Elapsed));
            sw.Reset();

            sw.Start();
            //make sure the ids list and the XYZ sets list
            //have the same length
            if (count != xyzs.Count())
            {
                throw new Exception("There are more adaptive component instances than there are points to adjust.");
            }

            for (var j = 0; j < Elements.Count; j++)
            {
                if (updated.Contains(Elements[j]))
                {
                    continue;
                }

                FamilyInstance ac;
                if (!dynUtils.TryGetElement(Elements[j], out ac))
                {
                    continue;
                }

                UpdatePlacementPoints(ac, xyzs, j);
            }
            sw.Stop();
            Debug.WriteLine(string.Format("{0} elapsed for updating remaining instance locations.", sw.Elapsed));

            //add all of the instances
            results = Elements.Aggregate(results,
                (current, id) =>
                    FSharpList<Value>.Cons(Value.NewContainer(dynRevitSettings.Doc.Document.GetElement(id)), current));
            results.Reverse();

            return Value.NewList(results);
        }
示例#8
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var symbol = (FamilySymbol)((Value.Container)args[0]).Item;
            var curves = ((Value.List) args[1]).Item;

            IEnumerable<Tuple<Curve, XYZ>> data;
            if (args[2].IsList)
            {
                var targets = ((Value.List)args[2]).Item;

                if (curves.Count() != targets.Count())
                    throw new Exception("The number of curves and the number of up vectors must be the same.");

                //if we get a list of up vectors, then pair each
                //curve with a corresponding up vector
                data = curves.Zip(targets,
                    (first, second) =>
                        new Tuple<Curve, XYZ>((Curve) ((Value.Container) first).Item,
                            (XYZ) ((Value.Container) second).Item));
            }
            else
            {
                //if we get a single up vector, then pair each
                //curve with that up vector
                data = curves.Select(x=>new Tuple<Curve, XYZ>((Curve)((Value.Container)x).Item,
                            (XYZ)((Value.Container)args[2]).Item));
            }

            var instData = new List<FamilyInstanceCreationData>();

            int count = 0;

            foreach (var pair in data)
            {
                var curve = pair.Item1;
                var target = pair.Item2;

                //calculate the desired rotation
                //we do this by finding the angle between the z axis
                //and vector between the start of the beam and the target point
                //both projected onto the start plane of the beam.

                XYZ zAxis = new XYZ(0, 0, 1);
                XYZ yAxis = new XYZ(0, 1, 0);

                //flatten the beam line onto the XZ plane
                //using the start's z coordinate
                XYZ start = curve.get_EndPoint(0);
                XYZ end = curve.get_EndPoint(1);
                XYZ newEnd = new XYZ(end.X, end.Y, start.Z); //drop end point to plane

                ////use the x axis of the curve's transform
                ////as the normal of the start plane
                //XYZ planeNormal = (curve.get_EndPoint(0) - curve.get_EndPoint(1)).Normalize();

                //catch the case where the end is directly above
                //the start, creating a normal with zero length
                //in that case, use the Z axis
                XYZ planeNormal = newEnd.IsAlmostEqualTo(start) ? zAxis : (newEnd - start).Normalize();

                XYZ target_project = target - target.DotProduct(planeNormal)*planeNormal;
                XYZ z_project = zAxis - zAxis.DotProduct(planeNormal)*planeNormal;

                //double gamma = target_project.AngleTo(z_project);
                double gamma = target.AngleOnPlaneTo(zAxis.IsAlmostEqualTo(planeNormal) ? yAxis : zAxis, planeNormal);

                FamilyInstance instance = null;
                if (this.Elements.Count > count)
                {
                    if (dynUtils.TryGetElement(this.Elements[count], out instance))
                    {
                        if (instance.Symbol != symbol)
                            instance.Symbol = symbol;

                        //update the curve
                        var locCurve = instance.Location as LocationCurve;
                        locCurve.Curve = curve;
                    }
                    else
                    {
                        var beamData = new FamilyInstanceCreationData(curve, symbol, dynRevitSettings.DefaultLevel, StructuralType.Beam)
                            {
                                RotateAngle = gamma
                            };
                        instData.Add(beamData);
                    }
                }
                else
                {
                    var beamData = new FamilyInstanceCreationData(curve, symbol, dynRevitSettings.DefaultLevel, StructuralType.Beam)
                        {
                            RotateAngle = gamma
                        };
                    instData.Add(beamData);
                }

                count++;
            }

            //trim the elements collection
            foreach (var e in this.Elements.Skip(count))
            {
                this.DeleteElement(e);
            }

            FSharpList<Value> results = FSharpList<Value>.Empty;

            if (instData.Any())
            {
                var ids = dynRevitSettings.Doc.Document.Create.NewFamilyInstances2(instData);

                //add our batch-created instances ids'
                //to the elements collection
                ids.ToList().ForEach(x=>Elements.Add(x));
            }

            //add all of the instances
            results = Elements.Aggregate(results, (current, id) => FSharpList<Value>.Cons(Value.NewContainer(dynRevitSettings.Doc.Document.GetElement(id)), current));
            results.Reverse();

            return Value.NewList(results);
        }
示例#9
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var symbol  = (FamilySymbol)((Value.Container)args[0]).Item;
            var curves  = ((Value.List)args[1]).Item;
            var targets = ((Value.List)args[2]).Item;

            if (curves.Count() != targets.Count())
            {
                throw new Exception("The number of curves and the number of up vectors must be the same.");
            }

            var data = curves.Zip(targets, (first, second) => new Tuple <Curve, XYZ>((Curve)((Value.Container)first).Item, (XYZ)((Value.Container)second).Item));

            var instData = new List <FamilyInstanceCreationData>();

            int count = 0;

            foreach (var pair in data)
            {
                var curve  = pair.Item1;
                var target = pair.Item2;

                //calculate the desired rotation
                //we do this by finding the angle between the z axis
                //and vector between the start of the beam and the target point
                //both projected onto the start plane of the beam.

                XYZ zAxis = new XYZ(0, 0, 1);
                XYZ yAxis = new XYZ(0, 1, 0);

                //flatten the beam line onto the XZ plane
                //using the start's z coordinate
                XYZ start  = curve.get_EndPoint(0);
                XYZ end    = curve.get_EndPoint(1);
                XYZ newEnd = new XYZ(end.X, end.Y, start.Z); //drop end point to plane

                ////use the x axis of the curve's transform
                ////as the normal of the start plane
                //XYZ planeNormal = (curve.get_EndPoint(0) - curve.get_EndPoint(1)).Normalize();

                //catch the case where the end is directly above
                //the start, creating a normal with zero length
                //in that case, use the Z axis
                XYZ planeNormal = newEnd.IsAlmostEqualTo(start) ? zAxis : (newEnd - start).Normalize();

                XYZ target_project = target - target.DotProduct(planeNormal) * planeNormal;
                XYZ z_project      = zAxis - zAxis.DotProduct(planeNormal) * planeNormal;

                //double gamma = target_project.AngleTo(z_project);
                double gamma = target.AngleOnPlaneTo(zAxis.IsAlmostEqualTo(planeNormal) ? yAxis : zAxis, planeNormal);

                FamilyInstance instance = null;
                if (this.Elements.Count > count)
                {
                    if (dynUtils.TryGetElement(this.Elements[count], out instance))
                    {
                        if (instance.Symbol != symbol)
                        {
                            instance.Symbol = symbol;
                        }

                        //update the curve
                        var locCurve = instance.Location as LocationCurve;
                        locCurve.Curve = curve;
                    }
                    else
                    {
                        var beamData = new FamilyInstanceCreationData(curve, symbol, dynRevitSettings.DefaultLevel, StructuralType.Beam)
                        {
                            RotateAngle = gamma
                        };
                        instData.Add(beamData);
                    }
                }
                else
                {
                    var beamData = new FamilyInstanceCreationData(curve, symbol, dynRevitSettings.DefaultLevel, StructuralType.Beam)
                    {
                        RotateAngle = gamma
                    };
                    instData.Add(beamData);
                }

                count++;
            }

            //trim the elements collection
            foreach (var e in this.Elements.Skip(count))
            {
                this.DeleteElement(e);
            }

            FSharpList <Value> results = FSharpList <Value> .Empty;

            if (instData.Any())
            {
                var ids = dynRevitSettings.Doc.Document.Create.NewFamilyInstances2(instData);

                //add our batch-created instances ids'
                //to the elements collection
                ids.ToList().ForEach(x => Elements.Add(x));
            }

            //add all of the instances
            results = Elements.Aggregate(results, (current, id) => FSharpList <Value> .Cons(Value.NewContainer(dynRevitSettings.Doc.Document.GetElement(id)), current));
            results.Reverse();

            return(Value.NewList(results));
        }
示例#10
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var xyzs   = ((Value.List)args[0]).Item;
            var symbol = (FamilySymbol)((Value.Container)args[1]).Item;

            var instData = new List <FamilyInstanceCreationData>();
            var updated  = new HashSet <ElementId>();

            int count = 0;

            #region batch creation data

            var sw = new Stopwatch();
            sw.Start();
            foreach (var pts in xyzs)
            {
                FamilyInstance instance = null;
                if (Elements.Count > count)
                {
                    if (dynUtils.TryGetElement(this.Elements[count], out instance))
                    {
                        //if we've found an instance, change its symbol if it needs
                        //changing
                        if (instance.Symbol.Id != symbol.Id)
                        {
                            instance.Symbol = symbol;
                        }

                        //update the placement points and add the
                        //id to the list of updated acs
                        UpdatePlacementPoints(instance, xyzs, count);
                        updated.Add(Elements[count]);
                    }
                    else
                    {
                        var instanceData = new FamilyInstanceCreationData(XYZ.Zero, symbol, StructuralType.NonStructural);
                        instData.Add(instanceData);
                    }
                }
                else
                {
                    var instanceData = new FamilyInstanceCreationData(XYZ.Zero, symbol, StructuralType.NonStructural);
                    instData.Add(instanceData);
                }

                count++;
            }
            sw.Stop();
            Debug.WriteLine(string.Format("{0} elapsed for updating existing or generating family creation data.", sw.Elapsed));
            sw.Reset();

            #endregion

            //trim the elements collection
            foreach (var e in this.Elements.Skip(count))
            {
                DeleteElement(e);
            }

            FSharpList <Value> results = FSharpList <Value> .Empty;

            sw.Start();

            ICollection <ElementId> ids = new List <ElementId>();

            if (instData.Any())
            {
                if (dynRevitSettings.Doc.Document.IsFamilyDocument)
                {
                    ids = dynRevitSettings.Doc.Document.FamilyCreate.NewFamilyInstances2(instData);
                }
                else
                {
                    ids = dynRevitSettings.Doc.Document.Create.NewFamilyInstances2(instData);
                }
                if (ids.Count > 0)
                {
                    //hack to force regeneration. There should be a better way!!
                    XYZ moveVec = new XYZ(0.0, 0.0, 0.0);
                    ElementTransformUtils.MoveElement(this.UIDocument.Document, ids.ElementAt(0), moveVec);
                }

                //add our batch-created instances ids'
                //to the elements collection
                ids.ToList().ForEach(x => Elements.Add(x));
            }
            sw.Stop();
            Debug.WriteLine(string.Format("{0} elapsed for creating instances from creation data.", sw.Elapsed));
            sw.Reset();

            sw.Start();

            //make sure the ids list and the XYZ sets list
            //have the same length
            if (count != xyzs.Count())
            {
                foreach (var eId in ids)
                {
                    DeleteElement(eId);
                }
                throw new Exception("There are more adaptive component instances than there are points to adjust.");
            }
            try
            {
                for (var j = 0; j < Elements.Count; j++)
                {
                    if (updated.Contains(Elements[j]))
                    {
                        continue;
                    }

                    FamilyInstance ac;
                    if (!dynUtils.TryGetElement(Elements[j], out ac))
                    {
                        continue;
                    }

                    UpdatePlacementPoints(ac, xyzs, j);
                }
            }
            catch (Exception ex)
            {
                foreach (var eId in ids)
                {
                    DeleteElement(eId);
                }
                throw ex;
            }
            sw.Stop();
            Debug.WriteLine(string.Format("{0} elapsed for updating remaining instance locations.", sw.Elapsed));

            //add all of the instances
            results = Elements.Aggregate(results,
                                         (current, id) =>
                                         FSharpList <Value> .Cons(Value.NewContainer(dynRevitSettings.Doc.Document.GetElement(id)), current));
            results.Reverse();

            return(Value.NewList(results));
        }