Пример #1
0
        public bool Clear(Autodesk.Revit.DB.Element element)
        {
            if (element == null)
            {
                return(false);
            }

            Schema schema = GetSchema();

            if (schema == null)
            {
                return(false);
            }

            Entity entity = new Entity(schema);

            if (entity == null)
            {
                return(false);
            }

            Field field = schema.GetField(FieldName);

            if (field == null)
            {
                return(false);
            }

            entity.Clear(field);
            return(true);
        }
Пример #2
0
        public ElementEntry(Autodesk.Revit.DB.Element revitElement)
        {
            string elementDescription;

            Autodesk.Revit.DB.BuiltInCategory cat = (Autodesk.Revit.DB.BuiltInCategory)revitElement.Category.Id.IntegerValue;
            switch (cat)
            {
            case Autodesk.Revit.DB.BuiltInCategory.OST_StructuralColumns:
                elementDescription = "Column: ";
                break;

            case Autodesk.Revit.DB.BuiltInCategory.OST_StructuralFraming:
                elementDescription = "Beam: ";
                break;

            case Autodesk.Revit.DB.BuiltInCategory.OST_Floors:
                elementDescription = "Slab: ";
                break;

            default:
                elementDescription = "UnKnown: ";
                break;
            }

            elementDescription += "( " + revitElement.Id.ToString() + " )";

            if (revitElement.Name.Length > 0)
            {
                elementDescription += "  ";
                elementDescription += revitElement.Name;
            }
            this.name = elementDescription;
        }
Пример #3
0
        public static Autodesk.Revit.DB.Solid GetSingleSolid(this Autodesk.Revit.DB.Element element)
        {
            var geoElem = element.get_Geometry(new Autodesk.Revit.DB.Options());

            return(geoElem.GetSingleSolid());

            //Autodesk.Revit.DB.Solid solid = null;
            //foreach (Autodesk.Revit.DB.GeometryObject item in geoElem)
            //{
            //    if(item is Autodesk.Revit.DB.GeometryInstance)
            //    {
            //        var geoIns = item as Autodesk.Revit.DB.GeometryInstance;
            //        foreach (var item2 in geoIns.GetInstanceGeometry())
            //        {
            //            var s = item2 as Autodesk.Revit.DB.Solid;
            //            if(s != null && s.Faces.Size != 0 && s.Edges.Size != 0)
            //            {
            //                return s;
            //            }

            //        }
            //    }
            //    if(item is Autodesk.Revit.DB.Solid)
            //    {
            //        var s = solid as Autodesk.Revit.DB.Solid;
            //        if (s != null && s.Faces.Size != 0 && s.Edges.Size != 0)
            //        {
            //            return s;
            //        }
            //    }
            //}
            return(null);
        }
Пример #4
0
        ObjToLabelStr(System.Object obj)
        {
            if (obj == null)
            {
                return("< null >");
            }

            Autodesk.Revit.DB.Element elem = obj as Autodesk.Revit.DB.Element;
            if (elem != null)
            {
                // TBD: Exceptions are thrown in certain cases when accessing the Name property.
                // Eg. for the RoomTag object. So we will catch the exception and display the exception message
                // arj - 1/23/07
                try
                {
                    string nameStr = (elem.Name == string.Empty) ? "???" : elem.Name;           // use "???" if no name is set
                    return(string.Format("< {0}  {1} >", nameStr, elem.Id.IntegerValue.ToString()));
                }
                catch (System.InvalidOperationException ex)
                {
                    return(string.Format("< {0}  {1} >", null, ex.Message));
                }
            }
            return(string.Format("< {0} >", obj.GetType().Name));
        }
Пример #5
0
        public static Autodesk.Revit.DB.Solid GetOriginalSolid(this Autodesk.Revit.DB.Element elem)
        {
            if (elem is Autodesk.Revit.DB.FamilyInstance)
            {
                var fi = elem as Autodesk.Revit.DB.FamilyInstance;
                var originalGeoElem = fi.GetOriginalGeometry(new Autodesk.Revit.DB.Options());
                var originalSolid   = GetSingleSolid(originalGeoElem);

                var tsElem = fi.GetTransform();
                return(Autodesk.Revit.DB.SolidUtils.CreateTransformed(originalSolid, tsElem));
            }
            if (elem is Autodesk.Revit.DB.Floor)
            {
                var floor      = elem as Autodesk.Revit.DB.Floor;
                var botFaceRef = Autodesk.Revit.DB.HostObjectUtils.GetBottomFaces(floor).First();
                var botFace    = elem.GetGeometryObjectFromReference(botFaceRef) as Autodesk.Revit.DB.PlanarFace;
                return(Autodesk.Revit.DB.GeometryCreationUtilities.CreateExtrusionGeometry(botFace.GetEdgesAsCurveLoops()
                                                                                           , -botFace.FaceNormal, floor.GetProximityHeight())); // FaceNormal là vector pháp tuyến
            }
            if (elem is Autodesk.Revit.DB.Wall)
            {
                var wall        = elem as Autodesk.Revit.DB.Wall;
                var sideFaceRef = Autodesk.Revit.DB.HostObjectUtils.GetSideFaces(wall as Autodesk.Revit.DB.HostObject
                                                                                 , Autodesk.Revit.DB.ShellLayerType.Exterior).First();
                var sideFace = wall.GetGeometryObjectFromReference(sideFaceRef) as Autodesk.Revit.DB.PlanarFace;
                return(Autodesk.Revit.DB.GeometryCreationUtilities.CreateExtrusionGeometry(sideFace.GetEdgesAsCurveLoops()
                                                                                           , -sideFace.FaceNormal, wall.Width));
            }
            throw new Model.Exception.CaseNotCheckException();
        }
Пример #6
0
        /// <summary>
        /// Wrap an element.  By default, this element is owned by Revit.  You must
        /// set this value manually if that's not what you want.
        /// </summary>
        /// <param name="element"></param>
        internal static UnknownElement FromExisting(Autodesk.Revit.DB.Element element, bool isRevitOwned)
        {
            var el = new UnknownElement(element)
            {
                IsRevitOwned = isRevitOwned
            };

            return(el);
        }
Пример #7
0
 public override void OnRun()
 {
     Autodesk.Revit.DB.Element element = null;
     foreach (Autodesk.Revit.DB.Element e in ThisExtension.Revit.ActiveUIDocument.Selection.Elements)
     {
         element = e;
         break;
     }
     ThisMainExtension.SubControlRef.SetData();
     ThisExtension.Revit.Parameters.SaveToHost(element);
 }
Пример #8
0
        public T GetIJSAMObject <T>(Autodesk.Revit.DB.Element element) where T : IJSAMObject
        {
            List <T> jSAMObjects = GetIJSAMObjects <T>(element);

            if (jSAMObjects == null || jSAMObjects.Count == 0)
            {
                return(default(T));
            }

            return(jSAMObjects[0]);
        }
Пример #9
0
 /// <summary>
 /// This method does most of the work of the IPerformanceAdviserRule implementation.
 /// It is called by PerformanceAdviser.
 /// It examines the element passed to it (which was previously filtered by the filter
 /// returned by GetElementFilter() (see below)).  After checking to make sure that the
 /// element is an instance, it checks the FacingFlipped property of the element.
 ///
 /// If it is flipped, it adds the instance to a list to be used later.
 /// </summary>
 /// <param name="document">The active document</param>
 /// <param name="element">The current element being checked</param>
 public void ExecuteElementCheck(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.Element element)
 {
     if ((element is Autodesk.Revit.DB.FamilyInstance))
     {
         Autodesk.Revit.DB.FamilyInstance doorCurrent = element as Autodesk.Revit.DB.FamilyInstance;
         if (doorCurrent.FacingFlipped)
         {
             m_FlippedDoors.Add(doorCurrent.Id);
         }
     }
 }
Пример #10
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            Autodesk.Revit.DB.Element element = null;
            if (!DA.GetData("Element", ref element))
            {
                return;
            }

            DA.SetData("Category", element?.Category);
            DA.SetData("Type", element?.Document.GetElement(element.GetTypeId()));
            DA.SetData("Name", element?.Name);
        }
Пример #11
0
 ElementSet(string label, ICollection<Autodesk.Revit.DB.ElementId> val, Autodesk.Revit.DB.Document doc)
 : base(label)
 {
     m_val = new Autodesk.Revit.DB.ElementSet();
     foreach(Autodesk.Revit.DB.ElementId elemId in val)
     {
         if(Autodesk.Revit.DB.ElementId.InvalidElementId == elemId)
             continue;
         Autodesk.Revit.DB.Element elem = doc.GetElement(elemId);
         if(null != elem)
             m_val.Insert(elem);
     }
 }
Пример #12
0
        internal void AddTriggerForUpdater(Document doc)
        {
            ElementParameterFilter familyNameFilter =
                new ElementParameterFilter(ParameterFilterRuleFactory
                                           .CreateEqualsRule(new ElementId
                                                                 (BuiltInParameter.ALL_MODEL_FAMILY_NAME), GetFamilyName, false));

            UpdaterRegistry.AddTrigger(m_updaterId, doc, familyNameFilter,
                                       Element.GetChangeTypeElementAddition());

            UpdaterRegistry.AddTrigger(m_updaterId, doc, familyNameFilter,
                                       Element.GetChangeTypeAny());
        }
Пример #13
0
 public static bool CheckNeedsRoundSmallDimension(Autodesk.Revit.DB.Element elem)
 {
     Autodesk.Revit.DB.Parameter classParam = elem.LookupParameter("Арм.КлассЧисло");
     if (classParam != null && classParam.HasValue)
     {
         double rebarClass = classParam.AsDouble();
         if (rebarClass < 0)
         {
             return(false);
         }
     }
     return(true);
 }
Пример #14
0
        /// <summary>
        /// Get the Unique ID in encoded on IFC Format (base 64)
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static string IfcGUID(this Autodesk.Revit.DB.Element element)
        {
            string a            = element.UniqueId;
            Guid   episodeId    = new Guid(a.Substring(0, 36));
            int    elementId    = int.Parse(a.Substring(37), NumberStyles.AllowHexSpecifier);
            int    last_32_bits = int.Parse(a.Substring(28, 8), NumberStyles.AllowHexSpecifier);
            int    xor          = last_32_bits ^ elementId;

            a = a.Substring(0, 28) + xor.ToString("x8");
            Guid guid = new Guid(a);

            return(ToIfcGuid(guid));
        }
Пример #15
0
 public override void OnRun()
 {
     Autodesk.Revit.DB.Element element = null;
     foreach (Autodesk.Revit.DB.ElementId id in ThisExtension.Revit.ActiveUIDocument.Selection.GetElementIds())
     {
         Autodesk.Revit.DB.Element e = ThisExtension.Revit.ActiveUIDocument.Document.GetElement(id);
         if (e != null)
         {
             element = e;
             break;
         }
     }
     ThisMainExtension.SubControlRef.SetData();
     ThisExtension.Revit.Parameters.SaveToHost(element);
 }
Пример #16
0
        public override void OnCreateLayout()
        {
            Autodesk.Revit.DB.Element  element = null;
            Autodesk.Revit.DB.Document doc     = ThisExtension.Revit.ActiveUIDocument.Document;
            foreach (Autodesk.Revit.DB.Element e in ThisExtension.Revit.ActiveUIDocument.Selection.Elements)
            {
                element = e;
                break;
            }


            if (ThisExtension.Revit.Parameters.LoadFromHost(element))
            {
                ThisMainExtension.SubControlRef.SetDialog();
            }
        }
Пример #17
0
        public bool SetIJSAMObject(Autodesk.Revit.DB.Element element, IJSAMObject jSAMObject)
        {
            if (element == null || jSAMObject == null || string.IsNullOrEmpty(fieldName))
            {
                return(false);
            }

            JObject jObject = jSAMObject.ToJObject();

            if (jObject == null)
            {
                return(false);
            }

            return(Modify.SetJObject(this, element, jObject));
        }
Пример #18
0
        ObjToTypeStr(System.Object obj)
        {
            if (obj == null)
            {
                return("< null >");
            }

            Autodesk.Revit.DB.Element elem = obj as Autodesk.Revit.DB.Element;
            if (elem != null)
            {
                string nameStr = (elem.Name == string.Empty) ? "???" : elem.Name;       // use "???" if no name is set
                return(string.Format("< {0}  {1}  {2,4} >", obj.GetType().Name, nameStr, elem.Id.IntegerValue.ToString()));
            }

            return(string.Format("< {0} >", obj.GetType().Name));
        }
Пример #19
0
 public void Show()
 {
     if (manager.CurrentCandidate != null)
     {
         var uiapp = new Autodesk.Revit.UI.UIApplication(manager.Document.Application);
         Autodesk.Revit.DB.Element e = manager.Document.GetElement(manager.CurrentCandidate.ParentElementId);
         if (e is Autodesk.Revit.DB.View)
         {
             uiapp.ActiveUIDocument.ActiveView = (Autodesk.Revit.DB.View)e;
         }
         else
         {
             uiapp.ActiveUIDocument.ShowElements(e.Id);
         }
     }
 }
Пример #20
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Autodesk.Revit.DB.Element element = null;
            if (!DA.GetData("Element", ref element))
            {
                return;
            }

            var inverted = false;

            if (!DA.GetData("Inverted", ref inverted))
            {
                return;
            }

            DA.SetData("Filter", new Autodesk.Revit.DB.ElementIntersectsElementFilter(element, inverted));
        }
Пример #21
0
        private void SelectCurve_Click(object sender, EventArgs e)
        {
            try
            {
                Autodesk.Revit.DB.Reference  eleR  = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
                Autodesk.Revit.DB.Element    ele   = doc.GetElement(eleR);
                Autodesk.Revit.DB.ModelCurve curve = ele as Autodesk.Revit.DB.ModelCurve;
                crv          = curve.GeometryCurve;
                CurveID.Text = string.Format("Curve: {0}", curve.Id.ToString());
                this.BringToFront();
            }

            catch
            {
                TaskDialog.Show("Error", "Must select a model curve");
                this.BringToFront();
            }
        }
Пример #22
0
        public static bool SetJson(this Autodesk.Revit.DB.Element element, string json)
        {
            if (element == null)
            {
                return(false);
            }

            Setting setting = ActiveSetting.Setting;

            string name;

            if (!setting.TryGetValue(ActiveSetting.Name.ParameterName_Json, out name))
            {
                return(false);
            }

            return(SetValue(element.LookupParameter(name), json));
        }
Пример #23
0
        public static bool SetSimplified(this Autodesk.Revit.DB.Element element, bool simplified)
        {
            if (element == null)
            {
                return(false);
            }

            Setting setting = ActiveSetting.Setting;

            string name;

            if (!setting.TryGetValue(ActiveSetting.Name.ParameterName_Simplified, out name))
            {
                return(false);
            }

            return(SetValue(element.LookupParameter(name), simplified));
        }
Пример #24
0
        public List <T> RemoveIJSAMObjects <T>(Autodesk.Revit.DB.Element element) where T : IJSAMObject
        {
            if (element == null)
            {
                return(null);
            }

            List <IJSAMObject> jSAMObjects = GetIJSAMObjects <IJSAMObject>(element);

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

            List <T> result = new List <T>();

            if (jSAMObjects.Count == 0)
            {
                return(result);
            }

            List <IJSAMObject> jSAMObjects_Temp = new List <IJSAMObject>();

            foreach (IJSAMObject jSAMObject in jSAMObjects)
            {
                if (jSAMObject == null)
                {
                    continue;
                }

                if (jSAMObject is T)
                {
                    result.Add((T)jSAMObject);
                    continue;
                }

                jSAMObjects_Temp.Add(jSAMObject);
            }

            SetIJSAMObjects(element, jSAMObjects_Temp);
            return(result);
        }
        private List <ParameterWrapper> GetParameters(Autodesk.Revit.DB.Element e, string prefix)
        {
            var items = new List <ParameterWrapper>();

            foreach (Autodesk.Revit.DB.Parameter p in e.Parameters)
            {
                if (p.StorageType != Autodesk.Revit.DB.StorageType.None)
                {
                    var idef = p.Definition as Autodesk.Revit.DB.InternalDefinition;
                    if (idef == null)
                    {
                        continue;
                    }

                    var bipName = idef.BuiltInParameter.ToString();
                    items.Add(new ParameterWrapper {
                        Name = prefix + " | " + p.Definition.Name, BipName = bipName
                    });
                }
            }
            return(items);
        }
        private Autodesk.Revit.DB.Element GetInputElement()
        {
            Autodesk.Revit.DB.Element e = null;
            if (!HasConnectedInput(0))
            {
                return(null);
            }

            var owner  = InPorts[0].Connectors[0].Start.Owner;
            var index  = InPorts[0].Connectors[0].Start.Index;
            var name   = owner.GetAstIdentifierForOutputIndex(index).Name;
            var mirror = EngineController.GetMirror(name);

            if (!mirror.GetData().IsCollection)
            {
                var element = (Revit.Elements.Element)mirror.GetData().Data;
                if (element != null)
                {
                    e = element.InternalElement;
                }
            }
            return(e);
        }
Пример #27
0
        public List <bool> AppendIJSAMObjects(Autodesk.Revit.DB.Element element, IEnumerable <IJSAMObject> jSAMObjects)
        {
            if (element == null || jSAMObjects == null)
            {
                return(null);
            }

            if (jSAMObjects.Count() == 0)
            {
                return(new List <bool>());
            }

            List <IJSAMObject> iJSAMObjects = GetIJSAMObjects <IJSAMObject>(element);

            if (iJSAMObjects == null)
            {
                iJSAMObjects = new List <IJSAMObject>();
            }

            iJSAMObjects.AddRange(jSAMObjects);

            return(SetIJSAMObjects(element, iJSAMObjects));
        }
Пример #28
0
        public List <T> GetIJSAMObjects <T>(Autodesk.Revit.DB.Element element) where T : IJSAMObject
        {
            if (element == null || Guid == Guid.Empty || string.IsNullOrEmpty(fieldName))
            {
                return(null);
            }

            Schema schema = GetSchema();

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

            Entity entity = element.GetEntity(schema);

            if (entity.Schema == null)
            {
                return(null);
            }

            string json = entity.Get <string>(fieldName);

            if (string.IsNullOrWhiteSpace(json))
            {
                return(null);
            }

            JArray jArray = Core.Query.JArray(json);

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

            return(Core.Create.IJSAMObjects <T>(jArray));
        }
Пример #29
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Autodesk.Revit.DB.Element element = null;
            if (!DA.GetData("Element", ref element))
            {
                return;
            }

            var materialIds = new List <Autodesk.Revit.DB.ElementId>();

            if (DA.GetDataList("Materials", materialIds))
            {
                DA.SetDataList("Volume", materialIds.Select(x => (element?.GetMaterialVolume(x)).GetValueOrDefault() * Math.Pow(Revit.ModelUnits, 3.0)));
                DA.SetDataList("Area", materialIds.Select(x => (element?.GetMaterialArea(x, false)).GetValueOrDefault() * Math.Pow(Revit.ModelUnits, 2.0)));
            }

            var paintIds = new List <Autodesk.Revit.DB.ElementId>();

            if (DA.GetDataList("Paint", paintIds))
            {
                try { DA.SetDataList("Painting", paintIds.Select(x => (element?.GetMaterialArea(x, true)).GetValueOrDefault() * Math.Pow(Revit.ModelUnits, 2.0))); }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, e.Message); }
            }
        }
Пример #30
0
        public List <bool> SetIJSAMObjects(Autodesk.Revit.DB.Element element, IEnumerable <IJSAMObject> jSAMObjects)
        {
            if (element == null || jSAMObjects == null)
            {
                return(null);
            }

            List <bool> result = new List <bool>();
            JArray      jArray = new JArray();

            foreach (IJSAMObject iJSAMObject in jSAMObjects)
            {
                if (iJSAMObject == null)
                {
                    result.Add(false);
                    continue;
                }

                JObject jObject = iJSAMObject.ToJObject();
                if (jObject == null)
                {
                    result.Add(false);
                    continue;
                }

                jArray.Add(jObject);
                result.Add(true);
            }

            if (!Modify.SetJArray(this, element, jArray))
            {
                return(new List <bool>());
            }

            return(result);
        }
Пример #31
0
 private void InternalSetElement(Autodesk.Revit.DB.Element e)
 {
     _element = e;
     InternalElementId = _element.Id;
     InternalUniqueId = _element.UniqueId;
 }