Ejemplo n.º 1
0
        public static IntegerId IntegerId(this Element element)
        {
            if (element == null)
            {
                return(null);
            }

            IntegerId integerId = Convert.ToSAM(element.Id);

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

            string fullName = FullName(element);

            if (!string.IsNullOrEmpty(fullName))
            {
                integerId.SetValue(RevitIdParameter.FullName, fullName);
            }

            Category category = element is Family ? ((Family)element).FamilyCategory : element.Category;

            if (category != null)
            {
                integerId.SetValue(RevitIdParameter.CategoryName, category.Name);
                integerId.SetValue(RevitIdParameter.CategoryId, category.Id.IntegerValue);
            }

            integerId.SetValue(RevitIdParameter.UniqueId, element.UniqueId);

            return(integerId);
        }
Ejemplo n.º 2
0
        public static T Find <T>(Document document, IntegerId integerId, double min = Tolerance.Distance, double max = Tolerance.MacroDistance) where T : Element
        {
            if (document == null || integerId == null)
            {
                return(null);
            }

            T result = Core.Revit.Query.Element <T>(document, integerId);

            if (result != null)
            {
                return(result);
            }

            if (!integerId.TryGetValue(RevitIdParameter.Location, out ISAMGeometry3D sAMGeometry))
            {
                return(null);
            }

            List <Element> elements = null;

            if (integerId.TryGetValue(Core.Revit.RevitIdParameter.CategoryId, out int categoryId) && categoryId != -1)
            {
                BuiltInCategory builtInCategory = (BuiltInCategory)categoryId;

                elements = new FilteredElementCollector(document).OfCategory(builtInCategory).ToList();
            }

            return(Find <T>(elements, sAMGeometry, min, max));
        }
Ejemplo n.º 3
0
        public override bool FromJObject(JObject jObject)
        {
            if (!base.FromJObject(jObject))
            {
                return(false);
            }

            if (jObject.ContainsKey("Location"))
            {
                location = new Planar.Point2D(jObject.Value <JObject>("Location"));
            }

            if (jObject.ContainsKey("Elbow"))
            {
                elbow = new Planar.Point2D(jObject.Value <JObject>("Elbow"));
            }

            if (jObject.ContainsKey("End"))
            {
                end = new Planar.Point2D(jObject.Value <JObject>("End"));
            }

            if (jObject.ContainsKey("ReferenceId"))
            {
                referenceId = new IntegerId(jObject.Value <JObject>("ReferenceId"));
            }

            return(true);
        }
Ejemplo n.º 4
0
        public static IntegerId IntegerId(this Element element)
        {
            if (element == null)
            {
                return(null);
            }

            IntegerId integerId = Convert.ToSAM(element.Id);

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

            ParameterSet parameterSet = new ParameterSet(element.GetType()?.Assembly);

            parameterSet.Add("Name", Query.FullName(element));

            string categoryName = null;

            if (element is Family)
            {
                categoryName = ((Family)element).FamilyCategory?.Name;
            }
            else
            {
                categoryName = element.Category?.Name;
            }

            parameterSet.Add("Category Name", categoryName);

            integerId.Add(parameterSet);
            return(integerId);
        }
Ejemplo n.º 5
0
 public Tag(TagType tagType, IntegerId viewId, Planar.Point2D location, Planar.Point2D elbow, Planar.Point2D end, IntegerId referenceId)
     : base(tagType, viewId)
 {
     this.location    = location == null ? null : new Planar.Point2D(location);
     this.referenceId = referenceId == null ? null : new IntegerId(referenceId);
     this.elbow       = elbow == null ? null : new Planar.Point2D(elbow);
     this.end         = end == null ? null : new Planar.Point2D(end);
 }
Ejemplo n.º 6
0
        public static ElementId ToRevit(this IntegerId integerId)
        {
            if (integerId == null)
            {
                return(null);
            }

            return(new ElementId(integerId.Id));
        }
Ejemplo n.º 7
0
        public static T Element <T>(this Document document, IntegerId integerId, bool includeName = false) where T : Element
        {
            if (integerId == null || document == null)
            {
                return(null);
            }

            T result = null;

            ElementId elementId = integerId.ElementId();

            if (elementId != null && elementId != Autodesk.Revit.DB.ElementId.InvalidElementId)
            {
                result = document.GetElement(elementId) as T;
            }

            if (result == null)
            {
                string uniqueId = integerId.UniqueId();
                if (!string.IsNullOrWhiteSpace(uniqueId))
                {
                    result = document.GetElement(uniqueId) as T;
                }
            }

            if (result == null && includeName)
            {
                if (integerId.TryGetValue(RevitIdParameter.FullName, out string fullName) && !string.IsNullOrWhiteSpace(fullName))
                {
                    BuiltInCategory?builtInCategory = integerId.BuiltInCategory();
                    if (builtInCategory != null && builtInCategory.HasValue && builtInCategory.Value != Autodesk.Revit.DB.BuiltInCategory.INVALID)
                    {
                        List <Element> elements = new FilteredElementCollector(document).OfCategory(builtInCategory.Value).ToList();
                        if (elements != null)
                        {
                            foreach (Element element in elements)
                            {
                                T t = element as T;
                                if (t == null)
                                {
                                    continue;
                                }

                                string fullName_Element = FullName(t);
                                if (fullName.Equals(fullName_Element))
                                {
                                    return(t);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
        public static string UniqueId(this IntegerId integerId)
        {
            if (integerId == null)
            {
                return(null);
            }

            if (!integerId.TryGetValue(RevitIdParameter.UniqueId, out string result))
            {
                return(null);
            }

            return(result);
        }
Ejemplo n.º 9
0
        public override bool FromJObject(JObject jObject)
        {
            if (!base.FromJObject(jObject))
            {
                return(false);
            }

            if (jObject.ContainsKey("ViewId"))
            {
                viewId = new IntegerId(jObject.Value <JObject>("ViewId"));
            }

            return(true);
        }
Ejemplo n.º 10
0
        public static IntegerId IntegerId(this Element element)
        {
            if (element == null)
            {
                return(null);
            }

            IntegerId result = Core.Revit.Query.IntegerId(element);

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

            ISAMGeometry sAMGeometry = Location(element);

            if (sAMGeometry != null)
            {
                result.SetValue(RevitIdParameter.Location, sAMGeometry);
            }

            return(result);
        }
Ejemplo n.º 11
0
 public FilledRegion(FilledRegionType filledRegionType, IntegerId viewId, IEnumerable <Face2D> face2Ds)
     : base(filledRegionType, viewId)
 {
     this.viewId = viewId == null ? null : new IntegerId(viewId);
     face2Ds     = face2Ds?.ToList().FindAll(x => x != null).ConvertAll(x => new Face2D(x));
 }
Ejemplo n.º 12
0
        public static FilledRegion ToSAM(this Autodesk.Revit.DB.FilledRegion filledRegion, ConvertSettings convertSettings)
        {
            if (filledRegion == null || !filledRegion.IsValidObject)
            {
                return(null);
            }

            FilledRegion result = convertSettings?.GetObject <FilledRegion>(filledRegion.Id);

            if (result != null)
            {
                return(result);
            }

            Document document = filledRegion.Document;

            if (document == null)
            {
                return(result);
            }

            Autodesk.Revit.DB.FilledRegionType filledRegionType_Revit = document.GetElement(filledRegion.GetTypeId()) as Autodesk.Revit.DB.FilledRegionType;
            if (filledRegionType_Revit == null)
            {
                return(null);
            }

            View view = filledRegion.Document.GetElement(filledRegion.OwnerViewId) as View;

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

            Spatial.Plane plane = view.Plane();
            if (plane == null)
            {
                return(null);
            }

            List <Face3D> face3Ds = filledRegion.Face3Ds();

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

            FilledRegionType     filledRegionType = filledRegionType_Revit.ToSAM(convertSettings);
            List <Planar.Face2D> face2Ds          = face3Ds.ConvertAll(x => Spatial.Query.Convert(plane, x));
            IntegerId            integerId        = Query.IntegerId(view);

            result = new FilledRegion(filledRegionType, integerId, face2Ds);

            if (result != null)
            {
                result.UpdateParameterSets(filledRegion, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));
                convertSettings?.Add(filledRegion.Id, result);
            }

            return(result);
        }
Ejemplo n.º 13
0
        public static Tag ToSAM(this IndependentTag independentTag, ConvertSettings convertSettings)
        {
            if (independentTag == null)
            {
                return(null);
            }

            Document document = independentTag.Document;

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

            Tag result = convertSettings?.GetObject <Tag>(independentTag.Id);

            if (result != null)
            {
                return(result);
            }

            TagType tagType = ToSAM_TagType(document.GetElement(independentTag.GetTypeId()) as FamilySymbol, convertSettings);

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

            ElementId elementId = independentTag.OwnerViewId;

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

            View view = document.GetElement(elementId) as View;

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

            IntegerId viewId = Query.IntegerId(view);

#if Revit2017
            IntegerId referenceId = null;
#else
            IntegerId referenceId = Query.IntegerId(document.GetElement(independentTag.GetTaggedReference()));
#endif

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

            Spatial.Point3D location = ToSAM(independentTag.TagHeadPosition);
            if (location == null)
            {
                return(null);
            }

            Planar.Point2D elbow = null;
            Planar.Point2D end   = null;
            if (independentTag.HasLeader)
            {
#if Revit2017
#else
                if (independentTag.HasElbow)
                {
                    Spatial.Point3D elbow3D = ToSAM(independentTag.LeaderElbow);
                    if (elbow3D != null)
                    {
                        elbow = new Planar.Point2D(elbow3D.X, elbow3D.Y);
                    }
                }
#endif

                if (independentTag.LeaderEndCondition == LeaderEndCondition.Free)
                {
                    Spatial.Point3D end3D = ToSAM(independentTag.LeaderEnd);
                    if (end3D != null)
                    {
                        end = new Planar.Point2D(end3D.X, end3D.Y);
                    }
                }
            }

            result = new Tag(tagType, viewId, new Planar.Point2D(location.X, location.Y), elbow, end, referenceId);
            if (result != null)
            {
                result.SetValue(ElementParameter.RevitId, Query.IntegerId(independentTag));
                result.SetValue(TagParameter.Leader, independentTag.HasLeader);
                result.SetValue(TagParameter.Orientation, independentTag.TagOrientation.ToString());

                Core.Revit.Modify.SetValues(independentTag, result);

                convertSettings?.Add(independentTag.Id, result);
            }

            return(result);
        }
Ejemplo n.º 14
0
        public static void UpdateParameterSets(this SAMObject sAMObject, Type type, IEnumerable <Parameter> parameters, TypeMap typeMap, bool includeGenericParameters = true)
        {
            if (sAMObject == null || type == null || parameters == null)
            {
                return;
            }

            Assembly assembly = type.Assembly;

            if (assembly == null)
            {
                return;
            }

            ParameterSet parameterSet = null;

            if (includeGenericParameters)
            {
                parameterSet = sAMObject.GetParameterSet(assembly);
                if (parameterSet == null)
                {
                    parameterSet = new ParameterSet(assembly);
                    sAMObject.Add(parameterSet);
                }
            }

            Type type_SAMObject = sAMObject.GetType();

            List <Enum> enums = ActiveManager.GetParameterEnums(sAMObject);

            foreach (Parameter parameter in parameters)
            {
                string parameterName_Element = parameter?.Definition?.Name;
                if (parameterName_Element == null)
                {
                    continue;
                }

                if (!parameter.HasValue)
                {
                    continue;
                }

                object value = null;
                switch (parameter.StorageType)
                {
                case StorageType.Double:
                    value = Units.Revit.Convert.ToSI(parameter.AsDouble(), parameter.Definition.UnitType);
                    break;

                case StorageType.Integer:
                    value = parameter.AsInteger();
                    break;

                case StorageType.String:
                    value = parameter.AsString();
                    break;

                case StorageType.ElementId:
                    value = Convert.ToSAM(parameter.AsElementId());
                    break;
                }

                string parametrName_SAMObject = parameterName_Element;

                if (typeMap != null)
                {
                    parametrName_SAMObject = typeMap.GetName(type_SAMObject, type, parameterName_Element, 1);
                    if (string.IsNullOrWhiteSpace(parametrName_SAMObject))
                    {
                        parametrName_SAMObject = parameterName_Element;
                    }
                }

                if (!string.IsNullOrWhiteSpace(parametrName_SAMObject))
                {
                    List <Enum> enums_Temp = enums.FindAll(x => x.Name().Equals(parametrName_SAMObject) || x.Name().Equals(parameterName_Element));
                    if (enums_Temp != null && enums_Temp.Count != 0)
                    {
                        foreach (Enum @enum in enums_Temp)
                        {
                            sAMObject.SetValue(@enum, value);
                        }

                        continue;
                    }
                }

                if (parameterSet != null)
                {
                    if (value == null)
                    {
                        switch (parameter.StorageType)
                        {
                        case StorageType.ElementId:
                            IntegerId integerId = null;
                            parameterSet.Add(parameterName_Element, integerId);
                            continue;

                        default:
                            string @string = null;
                            parameterSet.Add(parameterName_Element, @string);
                            continue;
                        }
                    }

                    parameterSet.Add(parameterName_Element, value as dynamic);
                }
            }
        }
Ejemplo n.º 15
0
 public ViewSpecificRevitInstance(T revitType, IntegerId viewId)
     : base(revitType)
 {
     this.viewId = viewId == null ? null : new IntegerId(viewId);
 }