예제 #1
0
        public static ClonedType CloneType(this IBHoMObject sourceRevitObject, string newName)
        {
            if (sourceRevitObject == null)
            {
                BH.Engine.Reflection.Compute.RecordError("It is impossible to clone a null Revit object.");
                return null;
            }

            RevitIdentifiers identifiers = sourceRevitObject.FindFragment<RevitIdentifiers>();
            if (identifiers == null)
            {
                BH.Engine.Reflection.Compute.RecordError("The input object is not a valid pulled Revit element.");
                return null;
            }

            ClonedType result = new ClonedType { SourceTypeId = identifiers.FamilyTypeId, Name = newName };
            if (identifiers.ElementId == identifiers.FamilyTypeId)
            {
                RevitParametersToPush parametersToPush = sourceRevitObject.FindFragment<RevitParametersToPush>();
                if (parametersToPush != null)
                {
                    BH.Engine.Reflection.Compute.RecordWarning("Parameters to push have been cloned from the source Revit type object.");
                    result.AddFragment(parametersToPush.DeepClone());
                }
            }
            else
                BH.Engine.Reflection.Compute.RecordWarning("The input object is a pulled Revit element, its type has been cloned.");

            return result;
        }
예제 #2
0
        public static Family Family(this RevitFilePreview revitFilePreview, IEnumerable <string> familyTypeNames)
        {
            if (revitFilePreview == null)
            {
                return(null);
            }

            string familyName = revitFilePreview.FamilyName();

            if (string.IsNullOrEmpty(familyName))
            {
                return(null);
            }

            string categoryName = revitFilePreview.CategoryName();

            List <oM.Adapters.Revit.Properties.InstanceProperties> instanceProperties = new List <oM.Adapters.Revit.Properties.InstanceProperties>();

            List <string> familyTypeNameList = revitFilePreview.FamilyTypeNames();

            if (familyTypeNameList != null)
            {
                foreach (string familyTypeName in familyTypeNameList)
                {
                    if (familyTypeNames != null && !familyTypeNames.Contains(familyTypeName))
                    {
                        continue;
                    }

                    oM.Adapters.Revit.Properties.InstanceProperties instanceProps = Create.InstanceProperties(familyName, familyTypeName);
                    instanceProps.CategoryName = categoryName;
                    instanceProperties.Add(instanceProps);
                }
            }

            Family family = new Family {
                PropertiesList = instanceProperties
            };

            RevitIdentifiers identifiers = new RevitIdentifiers("", -1, categoryName, familyName);

            family.Fragments.AddOrReplace(identifiers);

            return(family);
        }
예제 #3
0
        public static int ElementId(this IBHoMObject bHoMObject)
        {
            if (bHoMObject == null)
            {
                return(-1);
            }

            RevitIdentifiers identifiers = bHoMObject.GetRevitIdentifiers();

            if (identifiers != null)
            {
                return(identifiers.ElementId);
            }
            else
            {
                return(-1);
            }
        }
예제 #4
0
        public static int HostId(this IBHoMObject bHoMObject)
        {
            int id = -1;

            RevitIdentifiers identifiers = bHoMObject?.GetRevitIdentifiers();

            if (identifiers != null)
            {
                id = identifiers.HostId;
            }

            if (id != -1 && bHoMObject is ModelInstance && ((ModelInstance)bHoMObject).HostId != id)
            {
                BH.Engine.Reflection.Compute.RecordWarning("The object is a ModelInstance pulled from Revit with overwritten HostId property - the value of the latter is returned instead of the value from RevitIdentifiers.");
                id = ((ModelInstance)bHoMObject).HostId;
            }

            return(id);
        }
        public static object GetRevitParameterValue(this IBHoMObject bHoMObject, string parameterName)
        {
            if (bHoMObject == null)
            {
                return(null);
            }

            RevitParametersToPush pushFragment = bHoMObject.Fragments?.FirstOrDefault(x => x is RevitParametersToPush) as RevitParametersToPush;

            if (pushFragment?.Parameters != null)
            {
                RevitParameter param = pushFragment.Parameters.FirstOrDefault(x => x.Name == parameterName);
                if (param != null)
                {
                    return(param.Value);
                }
            }

            RevitPulledParameters pullFragment = bHoMObject.Fragments?.FirstOrDefault(x => x is RevitPulledParameters) as RevitPulledParameters;

            if (pullFragment?.Parameters != null)
            {
                RevitParameter param = pullFragment.Parameters.FirstOrDefault(x => x.Name == parameterName);
                if (param != null)
                {
                    return(param.Value);
                }
            }

            RevitIdentifiers identifierFragment = bHoMObject.Fragments?.FirstOrDefault(x => x is RevitIdentifiers) as RevitIdentifiers;

            if (identifierFragment != null)
            {
                string paramName = string.Concat(parameterName.Where(c => !char.IsWhiteSpace(c)));
                if (Reflection.Query.PropertyNames(identifierFragment).Contains(paramName))
                {
                    return(Reflection.Query.PropertyValue(identifierFragment, paramName));
                }
            }

            Dictionary <string, object> bHoMPropDic = Reflection.Query.PropertyDictionary(bHoMObject);

            foreach (KeyValuePair <string, object> bHoMPropEntry in bHoMPropDic)
            {
                IBHoMObject bHoMProp = bHoMPropEntry.Value as IBHoMObject;
                if (bHoMProp != null)
                {
                    RevitPulledParameters typePullFragment = bHoMProp.Fragments?.FirstOrDefault(x => x is RevitPulledParameters) as RevitPulledParameters;
                    if (typePullFragment?.Parameters != null)
                    {
                        RevitParameter param = typePullFragment.Parameters.FirstOrDefault(x => x.Name == parameterName);
                        if (param != null)
                        {
                            Engine.Reflection.Compute.RecordWarning("The value for parameter " + parameterName + " for the object with BHoM_Guid " + bHoMObject.BHoM_Guid + " has been retrieved from its property " + bHoMPropEntry.Key + ".");
                            return(param.Value);
                        }
                    }
                }
            }

            return(null);
        }