/***************************************************/ private static Element ToRevitElement(this ModelInstance modelInstance, WallType wallType, RevitSettings settings) { if (wallType == null || modelInstance == null) { return(null); } if (!(modelInstance.Location is ICurve)) { Compute.InvalidFamilyPlacementTypeError(modelInstance, wallType); return(null); } Document document = wallType.Document; ICurve curve = (ICurve)modelInstance.Location; Level level = document.LevelBelow(curve, settings); if (level == null) { return(null); } Curve revitCurve = curve.IToRevit(); return(Wall.Create(document, revitCurve, level.Id, false)); }
/***************************************************/ private static Element ToRevitElement(this ModelInstance modelInstance, MEPCurveType mEPType, RevitSettings settings) { if (mEPType == null || modelInstance == null) { return(null); } if (!(modelInstance.Location is ICurve)) { Compute.InvalidFamilyPlacementTypeError(modelInstance, mEPType); return(null); } Document document = mEPType.Document; BH.oM.Geometry.Line line = modelInstance.Location as BH.oM.Geometry.Line; Level level = document.LevelBelow(line, settings); if (level == null) { return(null); } Autodesk.Revit.DB.Line revitLine = line.ToRevit(); if (revitLine == null) { return(null); } XYZ startPoint = revitLine.GetEndPoint(0); XYZ endPoint = revitLine.GetEndPoint(1); if (mEPType is Autodesk.Revit.DB.Electrical.CableTrayType) { return(Autodesk.Revit.DB.Electrical.CableTray.Create(document, mEPType.Id, startPoint, endPoint, level.Id)); } else if (mEPType is Autodesk.Revit.DB.Electrical.ConduitType) { return(Autodesk.Revit.DB.Electrical.Conduit.Create(document, mEPType.Id, startPoint, endPoint, level.Id)); } else if (mEPType is Autodesk.Revit.DB.Plumbing.PipeType) { Autodesk.Revit.DB.Plumbing.PipingSystemType pst = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Plumbing.PipingSystemType)).OfType <Autodesk.Revit.DB.Plumbing.PipingSystemType>().FirstOrDefault(); return(Autodesk.Revit.DB.Plumbing.Pipe.Create(document, pst.Id, mEPType.Id, level.Id, startPoint, endPoint)); } else if (mEPType is Autodesk.Revit.DB.Mechanical.DuctType) { Autodesk.Revit.DB.Mechanical.MechanicalSystemType mst = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Mechanical.MechanicalSystemType)).OfType <Autodesk.Revit.DB.Mechanical.MechanicalSystemType>().FirstOrDefault(); return(Autodesk.Revit.DB.Mechanical.Duct.Create(document, mst.Id, mEPType.Id, level.Id, startPoint, endPoint)); } else { return(null); } }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static FamilyInstance ToRevitFamilyInstance(this Column framingElement, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { if (framingElement == null || document == null) { return(null); } FamilyInstance familyInstance = refObjects.GetValue <FamilyInstance>(document, framingElement.BHoM_Guid); if (familyInstance != null) { return(familyInstance); } settings = settings.DefaultIfNull(); if (framingElement.Location == null) { BH.Engine.Reflection.Compute.RecordError(String.Format("Revit element could not be created because the driving curve of a BHoM object is null. BHoM_Guid: {0}", framingElement.BHoM_Guid)); return(null); } if (framingElement.Location as BH.oM.Geometry.Line == null) { BH.Engine.Reflection.Compute.RecordError(string.Format("Revit does only support line-based columns. Try pushing your element as a beam instead. BHoM_Guid: {0}", framingElement.BHoM_Guid)); return(null); } if (((BH.oM.Geometry.Line)framingElement.Location).Start.Z >= ((BH.oM.Geometry.Line)framingElement.Location).End.Z) { BH.Engine.Reflection.Compute.RecordError(string.Format("Start point of Revit columns need to have lower elevation than the end point. Have a look at flipping your location curves. BHoM_Guid: {0}", framingElement.BHoM_Guid)); return(null); } Level level = document.LevelBelow(framingElement.Location, settings); if (level == null) { return(null); } Line columnLine = framingElement.Location.IToRevit() as Line; FamilySymbol familySymbol = framingElement.Property.ToRevitElementType(document, framingElement.BuiltInCategories(document), settings, refObjects); if (familySymbol == null) { familySymbol = framingElement.ElementType(document, settings) as FamilySymbol; } if (familySymbol == null) { Compute.ElementTypeNotFoundWarning(framingElement); return(null); } FamilyPlacementType familyPlacementType = familySymbol.Family.FamilyPlacementType; if (familyPlacementType != FamilyPlacementType.CurveBased && familyPlacementType != FamilyPlacementType.CurveBasedDetail && familyPlacementType != FamilyPlacementType.CurveDrivenStructural && familyPlacementType != FamilyPlacementType.TwoLevelsBased) { Compute.InvalidFamilyPlacementTypeError(framingElement, familySymbol); return(null); } familyInstance = document.Create.NewFamilyInstance(columnLine, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Column); document.Regenerate(); familyInstance.CheckIfNullPush(framingElement); if (familyInstance == null) { return(null); } oM.Physical.FramingProperties.ConstantFramingProperty barProperty = framingElement.Property as oM.Physical.FramingProperties.ConstantFramingProperty; if (barProperty != null) { //TODO: if the material does not get assigned an error should be thrown? if (barProperty.Material != null) { Autodesk.Revit.DB.Material material = document.GetElement(new ElementId(BH.Engine.Adapters.Revit.Query.ElementId(barProperty.Material))) as Autodesk.Revit.DB.Material; if (material != null) { Parameter param = familyInstance.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM); if (param != null && param.HasValue && !param.IsReadOnly) { familyInstance.StructuralMaterialId = material.Id; } else { BH.Engine.Reflection.Compute.RecordWarning(string.Format("The BHoM material has been correctly converted, but the property could not be assigned to the Revit element. ElementId: {0}", familyInstance.Id)); } } } } // Make sure the top is above base, otherwise Revit will complain for no reason. familyInstance.get_Parameter((BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM)).Set(-1e+3); familyInstance.get_Parameter((BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM)).Set(1e+3); familyInstance.CopyParameters(framingElement, settings); familyInstance.SetLocation(framingElement, settings); refObjects.AddOrReplace(framingElement, familyInstance); return(familyInstance); }
/***************************************************/ public static FamilyInstance ToRevitFamilyInstance(this IFramingElement framingElement, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { if (framingElement == null || document == null) { return(null); } FamilyInstance familyInstance = refObjects.GetValue <FamilyInstance>(document, framingElement.BHoM_Guid); if (familyInstance != null) { return(familyInstance); } settings = settings.DefaultIfNull(); if (framingElement.Location == null) { BH.Engine.Reflection.Compute.RecordError(String.Format("Revit element could not be created because the driving curve of a BHoM object is null. BHoM_Guid: {0}", framingElement.BHoM_Guid)); return(null); } if (!framingElement.Location.IIsPlanar()) { BH.Engine.Reflection.Compute.RecordError(string.Format("Revit framing does only support planar curves, element could not be created. BHoM_Guid: {0}", framingElement.BHoM_Guid)); return(null); } Curve revitCurve = framingElement.Location.IToRevit(); if (revitCurve == null) { BH.Engine.Reflection.Compute.RecordError(string.Format("Revit element could not be created because of curve conversion issues. BHoM_Guid: {0}", framingElement.BHoM_Guid)); return(null); } Level level = document.LevelBelow(framingElement.Location, settings); FamilySymbol familySymbol = framingElement.Property.ToRevitElementType(document, framingElement.BuiltInCategories(document), settings, refObjects); if (familySymbol == null) { familySymbol = framingElement.ElementType(document, settings) as FamilySymbol; } if (familySymbol == null) { Compute.ElementTypeNotFoundWarning(framingElement); return(null); } FamilyPlacementType familyPlacementType = familySymbol.Family.FamilyPlacementType; if (familyPlacementType != FamilyPlacementType.CurveBased && familyPlacementType != FamilyPlacementType.CurveBasedDetail && familyPlacementType != FamilyPlacementType.CurveDrivenStructural && familyPlacementType != FamilyPlacementType.TwoLevelsBased) { Compute.InvalidFamilyPlacementTypeError(framingElement, familySymbol); return(null); } if (framingElement is Beam) { familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Beam); } else if (framingElement is Bracing || framingElement is Cable) { familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Brace); } else { familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming); } document.Regenerate(); familyInstance.CheckIfNullPush(framingElement); if (familyInstance == null) { return(null); } oM.Physical.FramingProperties.ConstantFramingProperty barProperty = framingElement.Property as oM.Physical.FramingProperties.ConstantFramingProperty; if (barProperty != null) { //TODO: if the material does not get assigned an error should be thrown? if (barProperty.Material != null) { Material material = document.GetElement(new ElementId(BH.Engine.Adapters.Revit.Query.ElementId(barProperty.Material))) as Material; if (material != null) { Parameter param = familyInstance.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM); if (param != null && param.HasValue && !param.IsReadOnly) { familyInstance.StructuralMaterialId = material.Id; } else { BH.Engine.Reflection.Compute.RecordWarning(string.Format("The BHoM material has been correctly converted, but the property could not be assigned to the Revit element. ElementId: {0}", familyInstance.Id)); } } } } //Set the insertion point to centroid. Parameter zJustification = familyInstance.get_Parameter(BuiltInParameter.Z_JUSTIFICATION); if (zJustification != null && !zJustification.IsReadOnly) { zJustification.Set((int)Autodesk.Revit.DB.Structure.ZJustification.Origin); } familyInstance.CopyParameters(framingElement, settings); familyInstance.SetLocation(framingElement, settings); if (familyInstance.StructuralMaterialType != StructuralMaterialType.Concrete && familyInstance.StructuralMaterialType != StructuralMaterialType.PrecastConcrete) { StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 0); StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 1); } refObjects.AddOrReplace(framingElement, familyInstance); return(familyInstance); }