/***************************************************/ public static IEnumerable <IBHoMObject> FromRevit(this RoofBase roofBase, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { IEnumerable <IElement2D> result = null; switch (discipline) { case Discipline.Environmental: result = roofBase.EnvironmentPanelsFromRevit(settings, refObjects); break; case Discipline.Structural: result = roofBase.StructuralPanelsFromRevit(settings, refObjects); break; case Discipline.Facade: case Discipline.Architecture: case Discipline.Physical: result = new List <IElement2D> { roofBase.RoofFromRevit(settings, refObjects) }; break; } if (result != null && transform?.IsIdentity == false) { TransformMatrix bHoMTransform = transform.FromRevit(); result = result.Select(x => x.ITransform(bHoMTransform)); } return(result?.Cast <IBHoMObject>().ToList()); }
/// <summary> /// Exports a roof element to the appropriate IFC entity. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="roof">The roof element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, RoofBase roof, ref GeometryElement geometryElement, ProductWrapper productWrapper) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { // export parts or not bool exportParts = PartExporter.CanExportParts(roof); bool exportAsCurtainRoof = CurtainSystemExporter.IsCurtainSystem(roof); // if there is only a single part that we can get from the roof geometry, we will not create the aggregation with IfcSlab, but directly export the IfcRoof bool exportAsSingleGeometry = false; if (productWrapper != null && !ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4) { exportAsSingleGeometry = IFCAnyHandleUtil.IsNullOrHasNoValue(productWrapper.GetAnElement()); } if (exportParts) { if (!PartExporter.CanExportElementInPartExport(roof, roof.LevelId, false)) { return; } ExportRoofAsParts(exporterIFC, roof, geometryElement, productWrapper); // Right now, only flat roof could have parts. } else if (exportAsCurtainRoof) { CurtainSystemExporter.ExportCurtainRoof(exporterIFC, roof, productWrapper); } else { string ifcEnumType; IFCExportInfoPair roofExportType = ExporterUtil.GetProductExportType(exporterIFC, roof, out ifcEnumType); if (roofExportType.ExportInstance != IFCEntityType.IfcRoof) { ExportRoof(exporterIFC, roof, ref geometryElement, productWrapper, exportAsSingleGeometry); } else { IFCAnyHandle roofHnd = ExportRoofOrFloorAsContainer(exporterIFC, roof, geometryElement, productWrapper); if (IFCAnyHandleUtil.IsNullOrHasNoValue(roofHnd)) { ExportRoof(exporterIFC, roof, ref geometryElement, productWrapper, exportAsSingleGeometry); } } // call for host objects; curtain roofs excused from call (no material information) if (!ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { HostObjectExporter.ExportHostObjectMaterials(exporterIFC, roof, productWrapper.GetAnElement(), geometryElement, productWrapper, ElementId.InvalidElementId, IFCLayerSetDirection.Axis3, null, null); } } tr.Commit(); } }
/// <summary> /// Exports a roof to IfcRoof. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="roof">The roof element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The IFCProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, RoofBase roof, GeometryElement geometryElement, IFCProductWrapper productWrapper) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { // export parts or not bool exportParts = PartExporter.CanExportParts(roof); bool exportAsExtrusionCurtainRoof = false; bool exportAsFootprintCurtainRoof = false; if (roof is ExtrusionRoof) { ExtrusionRoof extrusionRoof = roof as ExtrusionRoof; exportAsExtrusionCurtainRoof = ((extrusionRoof.CurtainGrids != null) && (extrusionRoof.CurtainGrids.Size != 0)); } else if (roof is FootPrintRoof) { FootPrintRoof footprintRoof = roof as FootPrintRoof; exportAsFootprintCurtainRoof = ((footprintRoof.CurtainGrids != null) && (footprintRoof.CurtainGrids.Size != 0)); } if (exportParts) { if (!PartExporter.CanExportElementInPartExport(roof, roof.Level.Id, false)) { return; } ExportRoofAsParts(exporterIFC, roof, geometryElement, productWrapper); // Right now, only flat roof could have parts. } else if (exportAsExtrusionCurtainRoof) { CurtainSystemExporter.ExportExtrusionRoof(exporterIFC, roof as ExtrusionRoof, productWrapper); } else if (exportAsFootprintCurtainRoof) { CurtainSystemExporter.ExportFootPrintRoof(exporterIFC, roof as FootPrintRoof, productWrapper); } else { string ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, roof); IFCAnyHandle roofHnd = ExporterIFCUtils.ExportRoofAsContainer(exporterIFC, ifcEnumType, roof, geometryElement, productWrapper); if (IFCAnyHandleUtil.IsNullOrHasNoValue(roofHnd)) { ExportRoof(exporterIFC, ifcEnumType, roof, geometryElement, productWrapper); } PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, roof, productWrapper); // call for host objects; curtain roofs excused from call (no material information) HostObjectExporter.ExportHostObjectMaterials(exporterIFC, roof, productWrapper.GetAnElement(), geometryElement, productWrapper, ElementId.InvalidElementId, IFCLayerSetDirection.Axis3); } tr.Commit(); } }
internal static void UpdateTag(ElementId modifiedElmId, Autodesk.Revit.DB.Document doc) { StringBuilder strBld = new StringBuilder(); int rows = 0; int shelfLength = 0; Element modifiedElm = doc.GetElement(modifiedElmId); switch (modifiedElm.Category.Name) { case "Walls": Wall wl = modifiedElm as Wall; WallType wlType = wl.WallType; CompoundStructure cmpStr_wl = wlType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_wl, doc, out shelfLength); rows = wlType.GetCompoundStructure().LayerCount; break; case "Floors": Floor fl = modifiedElm as Floor; FloorType flType = fl.FloorType; CompoundStructure cmpStr_fl = flType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_fl, doc, out shelfLength); rows = flType.GetCompoundStructure().LayerCount; break; case "Ceilings": Ceiling cl = modifiedElm as Ceiling; CeilingType clType = doc.GetElement(cl.GetTypeId()) as CeilingType; CompoundStructure cmpStr_cl = clType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_cl, doc, out shelfLength); rows = clType.GetCompoundStructure().LayerCount; break; case "Roofs": RoofBase rf = modifiedElm as RoofBase; RoofType rfType = rf.RoofType; CompoundStructure cmpStr_rf = rfType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_rf, doc, out shelfLength); rows = rfType.GetCompoundStructure().LayerCount; break; } FamilyInstance tag = doc.GetElement(new ElementId(modifiedElm.LookupParameter("LinkedTag").AsInteger())) as FamilyInstance; try { tag.LookupParameter("multilineText").Set(strBld.ToString()); tag.LookupParameter("# of Rows").Set(rows); tag.LookupParameter("Shelf Length").Set(ToFt(shelfLength)); } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } }
/***************************************************/ private static oM.Physical.Elements.Roof CurtainRoofFromRevit(this RoofBase roof, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { List <BH.oM.Physical.Elements.IOpening> openings = new List <oM.Physical.Elements.IOpening>(); List <CurtainGrid> curtainGrids = roof.ICurtainGrids(); bool partFailed = false; foreach (CurtainGrid cg in curtainGrids) { List <BH.oM.Physical.Elements.IOpening> curtainPanels = cg.CurtainPanels(roof.Document, settings, refObjects); if (curtainPanels == null) { partFailed = true; } else { openings.AddRange(curtainPanels); } } ISurface location = null; if (openings == null || openings.Count == 0) { BH.Engine.Reflection.Compute.RecordError(String.Format("Processing of panels of Revit curtain roof failed. BHoM roof without location has been returned. Revit ElementId: {0}", roof.Id.IntegerValue)); } else { if (partFailed) { BH.Engine.Reflection.Compute.RecordError(String.Format("Processing of panels of a Revit curtain roof failed. Parts of the geometry of the BHoM roof may be missing. Revit ElementId: {0}", roof.Id.IntegerValue)); } if (openings.Count == 1) { location = openings[0].Location; } else { location = new PolySurface { Surfaces = openings.Select(x => x.Location).ToList() } }; } return(new oM.Physical.Elements.Roof { Location = location, Openings = openings }); } /***************************************************/ }
/***************************************************/ public static List <Face> LinkPanelFaces(this RoofBase roof, RevitSettings settings) { List <Face> result = new List <Face>(); foreach (Reference reference in HostObjectUtils.GetTopFaces(roof)) { PlanarFace pf = roof.GetGeometryObjectFromReference(reference) as PlanarFace; if (pf != null) { result.Add(pf); } } return(result); }
/***************************************************/ public static List <Plane> PanelPlanes(this RoofBase roof) { List <Plane> result = new List <Plane>(); foreach (Reference reference in HostObjectUtils.GetTopFaces(roof)) { PlanarFace pf = roof.GetGeometryObjectFromReference(reference) as PlanarFace; if (pf != null) { result.Add(Plane.CreateByNormalAndOrigin(pf.FaceNormal, pf.Origin)); } } return(result); }
private static List <Face3D> Profiles_RoofBase(this RoofBase roofBase) { List <Face3D> face3Ds = TopProfiles(roofBase); IEnumerable <ElementId> elementIds = roofBase.GetDependentElements(new ElementCategoryFilter(BuiltInCategory.OST_Windows)); if (elementIds == null || elementIds.Count() == 0) { return(face3Ds); } foreach (ElementId elementId in elementIds) { Element element = roofBase.Document.GetElement(elementId); if (element == null) { continue; } BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(null); Point3D point3D = ((boundingBoxXYZ.Max + boundingBoxXYZ.Min) / 2).ToSAM(); foreach (Face3D face3D in face3Ds) { List <Planar.IClosed2D> internalEdges = face3D.InternalEdge2Ds; if (internalEdges == null || internalEdges.Count == 0) { continue; } Spatial.Plane plane = face3D.GetPlane(); Point3D point3D_Projected = plane.Project(point3D); Planar.Point2D point2D = plane.Convert(point3D_Projected); for (int i = 0; i < internalEdges.Count; i++) { Planar.IClosed2D internalEdge = internalEdges[i]; if (internalEdge.Inside(point2D)) { face3D.RemoveInternalEdge(i); break; } } } } return(face3Ds); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static oM.Physical.Elements.Roof RoofFromRevit(this RoofBase roof, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { if (roof == null) { return(null); } settings = settings.DefaultIfNull(); oM.Physical.Elements.Roof bHoMRoof = refObjects.GetValue <oM.Physical.Elements.Roof>(roof.Id); if (bHoMRoof != null) { return(bHoMRoof); } List <CurtainGrid> curtainGrids = roof.ICurtainGrids(); if (curtainGrids.Count != 0) { bHoMRoof = roof.CurtainRoofFromRevit(settings, refObjects); } else { bHoMRoof = roof.SolidRoofFromRevit(settings, refObjects); } if (bHoMRoof == null) { return(null); } HostObjAttributes hostObjAttributes = roof.Document.GetElement(roof.GetTypeId()) as HostObjAttributes; string materialGrade = roof.MaterialGrade(settings); oM.Physical.Constructions.Construction construction = hostObjAttributes.ConstructionFromRevit(materialGrade, settings, refObjects); bHoMRoof.Construction = construction; bHoMRoof.Name = roof.FamilyTypeFullName(); //Set identifiers, parameters & custom data bHoMRoof.SetIdentifiers(roof); bHoMRoof.CopyParameters(roof, settings.ParameterSettings); bHoMRoof.SetProperties(roof, settings.ParameterSettings); refObjects.AddOrReplace(roof.Id, bHoMRoof); return(bHoMRoof); }
/// <summary> /// The construct of the RoofEditorForm class. /// </summary> /// <param name="roofsManager">A reference to the roofs manager</param> /// <param name="roof">The roof which will be edited.</param> public RoofEditorForm(RoofsManager.CS.RoofsManager roofsManager, RoofBase roof) { m_roofsManager = roofsManager; m_roof = roof; InitializeComponent(); m_footPrintRoofWrapper = null; m_extrusionRoofWrapper = null; if (m_roof is FootPrintRoof) { m_footPrintRoofWrapper = new FootPrintRoofWrapper(m_roof as FootPrintRoof); } else { m_extrusionRoofWrapper = new ExtrusionRoofWrapper(m_roof as ExtrusionRoof); } }
/// <summary> /// /// </summary> /// <param name="element"></param> /// <param name="outPutSolids"></param> /// <param name="parasiteObjects"></param> /// <param name="OP"></param> public static void GeometryDataFromRoof(Element element, List <DynamoSolid> outPutSolids, List <ParasiteObject> parasiteObjects, Options OP) { if (element is RoofBase) { RoofBase roofBase = element as RoofBase; GeometryElement geometryElement = roofBase.get_Geometry(OP); // Skip if null if (geometryElement != null) { P_Parameter paramChildLayer = new P_Parameter(P_ParameterType.ChildLayer, roofBase.RoofType.Name, P_StorageType.String); P_Parameter paramLayer = new P_Parameter(P_ParameterType.Layer, element.Category.Name, P_StorageType.String); DynamoParasiteFactory.CreateParasiteObjectFromGeometryElement(geometryElement, new P_Parameter[] { paramChildLayer, paramLayer }, outPutSolids, parasiteObjects); } } }
public static bool Recognization(RoofBase roof) { Level level = (Level)_doc.GetElement(roof.get_Parameter(BuiltInParameter.ROOF_BASE_LEVEL_PARAM).AsElementId()); double offset = roof.get_Parameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM).AsDouble(); bool isFound; _floor = _myLevel.GetFloor(out isFound, level, offset); --_floor; if (MyLevel.GetLevelNum() - 2 < _floor || _floor < 0) { _abandonWriter.WriteAbandonment(roof, AbandonmentTable.LevelNotFound); return(false); } CompoundStructure cs = roof.RoofType.GetCompoundStructure(); try { IList <CompoundStructureLayer> layers = cs.GetLayers(); Material matl = (Material)_doc.GetElement(layers.First().MaterialId); if (matl.MaterialCategory == _addiInfo.materialTypes[(byte)PGMaterialType.ConcreteTile]) { _matlIndex = 1; } else if (matl.MaterialCategory == _addiInfo.materialTypes[(byte)PGMaterialType.ClayTile]) { _matlIndex = 2; } else { _abandonWriter.WriteAbandonment(roof, AbandonmentTable.Roof_MatlOOR); return(false); } } catch { _abandonWriter.WriteAbandonment(roof, AbandonmentTable.Roof_MatlOOR); return(false); } _area = roof.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble(); return(true); }
/***************************************************/ public static IEnumerable <IBHoMObject> FromRevit(this RoofBase roofBase, Discipline discipline, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { switch (discipline) { case Discipline.Environmental: return(roofBase.EnvironmentPanelsFromRevit(settings, refObjects)); case Discipline.Structural: return(roofBase.StructuralPanelsFromRevit(settings, refObjects)); case Discipline.Architecture: case Discipline.Physical: return(new List <IBHoMObject> { roofBase.RoofFromRevit(settings, refObjects) }); default: return(null); } }
/// <summary> /// Exports a roof element to the appropriate IFC entity. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="roof">The roof element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, RoofBase roof, GeometryElement geometryElement, ProductWrapper productWrapper) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { // export parts or not bool exportParts = PartExporter.CanExportParts(roof); bool exportAsCurtainRoof = CurtainSystemExporter.IsCurtainSystem(roof); if (exportParts) { if (!PartExporter.CanExportElementInPartExport(roof, roof.LevelId, false)) { return; } ExportRoofAsParts(exporterIFC, roof, geometryElement, productWrapper); // Right now, only flat roof could have parts. } else if (exportAsCurtainRoof) { CurtainSystemExporter.ExportCurtainRoof(exporterIFC, roof, productWrapper); } else { IFCAnyHandle roofHnd = ExportRoofOrFloorAsContainer(exporterIFC, roof, geometryElement, productWrapper); if (IFCAnyHandleUtil.IsNullOrHasNoValue(roofHnd)) { ExportRoof(exporterIFC, roof, geometryElement, productWrapper); } // call for host objects; curtain roofs excused from call (no material information) if (!ExporterCacheManager.ExportOptionsCache.ExportAs4ReferenceView) { HostObjectExporter.ExportHostObjectMaterials(exporterIFC, roof, productWrapper.GetAnElement(), geometryElement, productWrapper, ElementId.InvalidElementId, IFCLayerSetDirection.Axis3, null, null); } } tr.Commit(); } }
/// <summary> /// Exports a curtain roof to IFC curtain wall. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="hostElement">The host object element to be exported.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void ExportCurtainRoof(ExporterIFC exporterIFC, RoofBase hostElement, ProductWrapper productWrapper) { ExportBaseWithGrids(exporterIFC, hostElement, productWrapper); }
private void Stream( ArrayList data, RoofBase roofBase ) { data.Add( new Snoop.Data.ClassSeparator( typeof( RoofBase ) ) ); data.Add( new Snoop.Data.String( "Eave cuts", roofBase.EaveCuts.ToString() ) ); try { data.Add( new Snoop.Data.Double( "Fascia depth", roofBase.FasciaDepth ) ); } catch( Exception ex ) { data.Add( new Snoop.Data.Exception( "Fascia depth", ex ) ); } data.Add( new Snoop.Data.Object( "Roof type", roofBase.RoofType ) ); data.Add( new Snoop.Data.Object( "Slab shape editor", roofBase.SlabShapeEditor ) ); FootPrintRoof footPrintRoof = roofBase as FootPrintRoof; if( footPrintRoof != null ) { Stream( data, footPrintRoof ); return; } ExtrusionRoof extrRoof = roofBase as ExtrusionRoof; if( extrRoof != null ) { Stream( data, extrRoof ); return; } }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private static oM.Physical.Elements.Roof SolidRoofFromRevit(this RoofBase roof, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { ISurface location = null; List <BH.oM.Physical.Elements.IOpening> openings = new List <oM.Physical.Elements.IOpening>(); Dictionary <PlanarSurface, List <PlanarSurface> > surfaces = null; BoundingBoxXYZ bbox = roof.get_BoundingBox(null); if (bbox != null) { BoundingBoxIntersectsFilter bbif = new BoundingBoxIntersectsFilter(new Outline(bbox.Min, bbox.Max)); IList <ElementId> insertIds = (roof as HostObject).FindInserts(true, true, true, true); List <Element> inserts; if (insertIds.Count == 0) { inserts = new List <Element>(); } else { inserts = new FilteredElementCollector(roof.Document, insertIds).WherePasses(bbif).ToList(); } List <FamilyInstance> windows = inserts.Where(x => x is FamilyInstance && x.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Windows).Cast <FamilyInstance>().ToList(); List <FamilyInstance> doors = inserts.Where(x => x is FamilyInstance && x.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Doors).Cast <FamilyInstance>().ToList(); surfaces = roof.PanelSurfaces(windows.Union(doors).Select(x => x.Id), settings); if (surfaces != null) { List <ISurface> locations = new List <ISurface>(surfaces.Keys); if (locations.Count == 1) { location = locations[0]; } else { location = new PolySurface { Surfaces = locations } }; foreach (List <PlanarSurface> ps in surfaces.Values) { openings.AddRange(ps.Select(x => new BH.oM.Physical.Elements.Void { Location = x })); } foreach (FamilyInstance window in windows) { BH.oM.Physical.Elements.Window bHoMWindow = window.WindowFromRevit(roof, settings, refObjects); if (bHoMWindow != null) { openings.Add(bHoMWindow); } } foreach (FamilyInstance door in doors) { BH.oM.Physical.Elements.Door bHoMDoor = door.DoorFromRevit(roof, settings, refObjects); if (bHoMDoor != null) { openings.Add(bHoMDoor); } } } } if (surfaces == null || surfaces.Count == 0) { roof.NoPanelLocationError(); } return(new oM.Physical.Elements.Roof { Location = location, Openings = openings }); }
private static List <Face3D> Profiles_RoofBase(this RoofBase roofBase) { #if Revit2017 return(null); #else List <Face3D> face3Ds = TopProfiles(roofBase); IEnumerable <ElementId> elementIds = roofBase.GetDependentElements(new ElementCategoryFilter(BuiltInCategory.OST_Windows)); if (elementIds == null || elementIds.Count() == 0) { return(face3Ds); } List <Tuple <BoundingBox3D, Face3D> > tuples = face3Ds.ConvertAll(x => new Tuple <BoundingBox3D, Face3D>(x.GetBoundingBox(), x)); foreach (ElementId elementId in elementIds) { Element element = roofBase.Document.GetElement(elementId); if (element == null) { continue; } BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(null); Point3D point3D = ((boundingBoxXYZ.Max + boundingBoxXYZ.Min) / 2).ToSAM(); List <Face3D> face3Ds_Temp = tuples.FindAll(x => x.Item1.InRange(point3D)).ConvertAll(x => x.Item2); foreach (Face3D face3D in face3Ds_Temp) { List <IClosed2D> internalEdges = face3D.InternalEdge2Ds; if (internalEdges == null || internalEdges.Count == 0) { continue; } Spatial.Plane plane = face3D.GetPlane(); Point3D point3D_Projected = plane.Project(point3D); Point2D point2D = plane.Convert(point3D_Projected); bool @break = false; for (int i = 0; i < internalEdges.Count; i++) { IClosed2D internalEdge = internalEdges[i]; if (internalEdge.Inside(point2D)) { face3D.RemoveInternalEdge(i); @break = true; break; } } if (@break) { break; } } } return(face3Ds); #endif }
public static HostObject ToRevit(this Panel panel, Document document, Core.Revit.ConvertSettings convertSettings) { Geometry.Spatial.Face3D face3D = panel?.GetFace3D(); if (face3D == null) { return(null); } HostObject result = convertSettings?.GetObject <HostObject>(panel.Guid); if (result != null) { return(result); } PanelType panelType = panel.PanelType; Geometry.Spatial.Vector3D normal = panel.Normal; HostObjAttributes hostObjAttributes = panel.Construction.ToRevit(document, panelType, normal, convertSettings); if (hostObjAttributes == null) { hostObjAttributes = Analytical.Query.DefaultConstruction(panelType)?.ToRevit(document, panelType, normal, convertSettings); //Default Construction } BuiltInParameter[] builtInParameters = null; if (hostObjAttributes is Autodesk.Revit.DB.WallType) { double lowElevation = panel.LowElevation(); Level level = document.LowLevel(lowElevation); Autodesk.Revit.DB.Wall wall = ToRevit_Wall(face3D, document, (Autodesk.Revit.DB.WallType)hostObjAttributes, level); if (wall == null) { return(result); } //List<Curve> curveList = new List<Curve>(); //foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D in face3D.GetEdge3Ds()) //{ // if (Geometry.Spatial.Query.Clockwise(closedPlanar3D)) // closedPlanar3D.Reverse(); // List<Line> lines = closedPlanar3D.ToRevit(); // if (lines == null) // continue; // curveList.AddRange(lines); //} //if (curveList == null || curveList.Count == 0) // return null; //double lowElevation = panel.LowElevation(); //Level level = document.LowLevel(lowElevation); //if (level == null) // return null; //Wall wall = Wall.Create(document, curveList, hostObjAttributes.Id, level.Id, false, panel.Normal.ToRevit(false)); Parameter parameter = null; parameter = wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE); if (parameter != null) { parameter.Set(ElementId.InvalidElementId); } parameter = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM); if (parameter != null) { #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double height = UnitUtils.ConvertToInternalUnits((panel.HighElevation() - lowElevation), DisplayUnitType.DUT_METERS); #else double height = UnitUtils.ConvertToInternalUnits((panel.HighElevation() - lowElevation), UnitTypeId.Meters); #endif parameter.Set(height); } #if Revit2017 || Revit2018 || Revit2019 || Revit2020 double levelElevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, DisplayUnitType.DUT_METERS); #else double levelElevation = UnitUtils.ConvertFromInternalUnits(level.Elevation, UnitTypeId.Meters); #endif if (Math.Abs(lowElevation - levelElevation) > Core.Tolerance.MacroDistance) { parameter = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); if (parameter != null) { #if Revit2017 || Revit2018 || Revit2019 || Revit2020 parameter.Set(UnitUtils.ConvertToInternalUnits(lowElevation - levelElevation, DisplayUnitType.DUT_METERS)); #else parameter.Set(UnitUtils.ConvertToInternalUnits(lowElevation - levelElevation, UnitTypeId.Meters)); #endif } } builtInParameters = new BuiltInParameter[] { BuiltInParameter.WALL_BASE_CONSTRAINT, BuiltInParameter.WALL_BASE_OFFSET, BuiltInParameter.WALL_HEIGHT_TYPE, BuiltInParameter.WALL_USER_HEIGHT_PARAM, BuiltInParameter.WALL_KEY_REF_PARAM }; result = wall; } else if (hostObjAttributes is Autodesk.Revit.DB.FloorType) { Geometry.Spatial.IClosedPlanar3D closedPlanar3D_External = face3D.GetExternalEdge3D(); if (!(closedPlanar3D_External is Geometry.Spatial.ICurvable3D)) { return(null); } double elevation = panel.LowElevation(); Level level = document.HighLevel(elevation); Geometry.Spatial.Plane plane = new Geometry.Spatial.Plane(new Geometry.Spatial.Point3D(0, 0, elevation), Geometry.Spatial.Vector3D.WorldZ); CurveArray curveArray_Sloped = new CurveArray(); CurveArray curveArray_Plane = new CurveArray(); Geometry.Spatial.IClosedPlanar3D closedPlanar3D = face3D.GetExternalEdge3D(); if (!(closedPlanar3D is Geometry.Spatial.ICurvable3D)) { return(null); } List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Query.Segment3Ds(closedPlanar3D); if (segment3Ds == null || segment3Ds.Count == 0) { return(null); } foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds) { curveArray_Sloped.Append(segment3D.ToRevit_Line()); Geometry.Spatial.Segment3D segment3D_Temp = Geometry.Spatial.Query.Project(plane, segment3D); if (segment3D_Temp == null) { continue; } curveArray_Plane.Append(segment3D_Temp.ToRevit_Line()); } #if Revit2017 || Revit2018 || Revit2019 || Revit2020 || Revit2021 Autodesk.Revit.DB.Floor floor = document.Create.NewFloor(curveArray_Plane, hostObjAttributes as Autodesk.Revit.DB.FloorType, level, false); #else CurveLoop curveLoop = new CurveLoop(); foreach (Curve curve in curveArray_Plane) { curveLoop.Append(curve); } Autodesk.Revit.DB.Floor floor = Autodesk.Revit.DB.Floor.Create(document, new CurveLoop[] { curveLoop }, hostObjAttributes.Id, level.Id); #endif if (floor != null) { floor.ChangeTypeId(hostObjAttributes.Id); List <Geometry.Spatial.IClosedPlanar3D> closedPlanar3Ds_Internal = face3D.GetInternalEdge3Ds(); if (closedPlanar3Ds_Internal != null && closedPlanar3Ds_Internal.Count > 0) { //Requires to be regenerated before inserting openings //https://thebuildingcoder.typepad.com/blog/2013/07/create-a-floor-with-an-opening-or-complex-boundary.html document.Regenerate(); foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D_Internal in face3D.GetInternalEdge3Ds()) { List <Geometry.Spatial.Segment3D> segment3Ds_Internal = Geometry.Revit.Query.Segment3Ds(closedPlanar3D_Internal); if (segment3Ds_Internal == null || segment3Ds_Internal.Count == 0) { continue; } curveArray_Plane = new CurveArray(); //foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds) foreach (Geometry.Spatial.Segment3D segment3D in segment3Ds_Internal) { curveArray_Sloped.Append(segment3D.ToRevit_Line()); Geometry.Spatial.Segment3D segment3D_Temp = Geometry.Spatial.Query.Project(plane, segment3D); if (segment3D_Temp == null) { continue; } curveArray_Plane.Append(segment3D_Temp.ToRevit_Line()); } Opening opening = document.Create.NewOpening(floor, curveArray_Plane, true); } } } if (floor != null) { document.Regenerate(); SlabShapeEditor slabShapeEditor = floor.SlabShapeEditor; if (slabShapeEditor != null) { slabShapeEditor.ResetSlabShape(); foreach (Curve curve in curveArray_Sloped) { XYZ xYZ = curve.GetEndPoint(0); slabShapeEditor.DrawPoint(xYZ); } } } builtInParameters = new BuiltInParameter[] { BuiltInParameter.LEVEL_PARAM }; result = floor; } else if (hostObjAttributes is Autodesk.Revit.DB.RoofType) { CurveArray curveArray = new CurveArray(); foreach (Geometry.Spatial.IClosedPlanar3D closedPlanar3D in face3D.GetEdge3Ds()) { List <Geometry.Spatial.Segment3D> segment3Ds = Geometry.Revit.Query.Segment3Ds(closedPlanar3D); if (segment3Ds == null || segment3Ds.Count == 0) { return(null); } segment3Ds.ForEach(x => curveArray.Append(x.ToRevit_Line())); } Level level = document.HighLevel(panel.LowElevation()); double levelElevation = level.Elevation; ModelCurveArray modelCurveArray = new ModelCurveArray(); RoofBase roofBase = document.Create.NewFootPrintRoof(curveArray, level, hostObjAttributes as Autodesk.Revit.DB.RoofType, out modelCurveArray); Parameter parameter = roofBase.get_Parameter(BuiltInParameter.ROOF_UPTO_LEVEL_PARAM); if (parameter != null) { parameter.Set(ElementId.InvalidElementId); } SlabShapeEditor slabShapeEditor = roofBase.SlabShapeEditor; if (slabShapeEditor != null) { slabShapeEditor.ResetSlabShape(); foreach (Curve curve in curveArray) { XYZ xYZ = curve.GetEndPoint(0); //if (Math.Abs(xYZ.Z - levelElevation) > Core.Tolerance.MicroDistance) slabShapeEditor.DrawPoint(xYZ); } } builtInParameters = new BuiltInParameter[] { BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM, BuiltInParameter.ROOF_BASE_LEVEL_PARAM, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM }; result = roofBase; } if (result == null) { return(null); } List <Aperture> apertures = panel.Apertures; if (apertures != null) { if (result is Autodesk.Revit.DB.Wall && ((Autodesk.Revit.DB.Wall)result).WallType.Kind == WallKind.Curtain) { } else { foreach (Aperture aperture in apertures) { Geometry.Spatial.Plane plane_Aperture = aperture?.PlanarBoundary3D?.Plane; if (plane_Aperture == null) { continue; } //bool flipHand = !plane_Panel.AxisX.SameHalf(plane_Aperture.AxisX); //bool flipFacing = !plane_Panel.Normal.SameHalf(plane_Aperture.Normal); FamilyInstance failyInstance_Aperture = aperture.ToRevit(document, result, convertSettings); } } } if (convertSettings.ConvertParameters) { Core.Revit.Modify.SetValues(result, panel, builtInParameters); Core.Revit.Modify.SetValues(result, panel, ActiveSetting.Setting); Core.Revit.Modify.SetJson(result, panel.ToJObject()?.ToString()); } //TODO: Implement proper log //System.IO.File.AppendAllText(@"C:\Users\DengusiakM\Desktop\SAM\2020-04-16 floorbug\LOG.txt", string.Format("{0}\t{1}\t{2}\n", DateTime.Now.ToString(), panel.Guid, panel.Name)); convertSettings?.Add(panel.Guid, result); return(result); }
public static List <oM.Structure.Elements.Panel> StructuralPanelsFromRevit(this RoofBase roofBase, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { return((roofBase as HostObject).StructuralPanelsFromRevit(settings, refObjects)); }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static RoofBase ToRevitRoofBase(this oM.Physical.Elements.Roof roof, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null) { if (roof == null || roof.Location == null || document == null) { return(null); } PlanarSurface planarSurface = roof.Location as PlanarSurface; if (planarSurface == null) { return(null); } RoofBase roofBase = refObjects.GetValue <RoofBase>(document, roof.BHoM_Guid); if (roofBase != null) { return(roofBase); } settings = settings.DefaultIfNull(); RoofType roofType = roof.Construction?.ToRevitElementType(document, new List <BuiltInCategory> { BuiltInCategory.OST_Roofs }, settings, refObjects) as RoofType; if (roofType == null) { roofType = roof.ElementType(document, settings); } if (roofType == null) { Compute.ElementTypeNotFoundWarning(roof); return(null); } Level level = document.LevelBelow(roof.Location, settings); if (level == null) { return(null); } double elevation = level.Elevation.ToSI(UnitType.UT_Length); oM.Geometry.Plane plane = BH.Engine.Geometry.Create.Plane(BH.Engine.Geometry.Create.Point(0, 0, elevation), BH.Engine.Geometry.Create.Vector(0, 0, 1)); ICurve curve = planarSurface.ExternalBoundary.IProject(plane); CurveArray curveArray = Create.CurveArray(curve.IToRevitCurves()); ModelCurveArray modelCurveArray = new ModelCurveArray(); roofBase = document.Create.NewFootPrintRoof(curveArray, level, roofType, out modelCurveArray); if (roofBase != null) { Parameter parameter = roofBase.get_Parameter(BuiltInParameter.ROOF_UPTO_LEVEL_PARAM); if (parameter != null) { parameter.Set(ElementId.InvalidElementId); } List <oM.Geometry.Point> controlPoints = planarSurface.ExternalBoundary.IControlPoints(); if (controlPoints != null && controlPoints.Count > 2) { SlabShapeEditor slabShapeEditor = roofBase.SlabShapeEditor; slabShapeEditor.ResetSlabShape(); foreach (oM.Geometry.Point point in controlPoints) { if (Math.Abs(point.Z - plane.Origin.Z) > settings.DistanceTolerance) { XYZ xyz = point.ToRevit(); slabShapeEditor.DrawPoint(xyz); } } } } roofBase.CheckIfNullPush(roof); if (roofBase == null) { return(null); } // Copy parameters from BHoM object to Revit element roofBase.CopyParameters(roof, settings); // Update the offset in case the level had been overwritten. double offset = 0; if (roofBase.LevelId.IntegerValue != level.Id.IntegerValue) { Level newLevel = document.GetElement(roofBase.LevelId) as Level; offset += (level.ProjectElevation - newLevel.ProjectElevation).ToSI(UnitType.UT_Length); } roofBase.SetParameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM, offset); refObjects.AddOrReplace(roof, roofBase); return(roofBase); }
/// <summary> /// Exports a roof to IfcRoof. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="roof">The roof element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, RoofBase roof, GeometryElement geometryElement, ProductWrapper productWrapper) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { // export parts or not bool exportParts = PartExporter.CanExportParts(roof); bool exportAsCurtainRoof = CurtainSystemExporter.IsCurtainSystem(roof); if (exportParts) { if (!PartExporter.CanExportElementInPartExport(roof, roof.Level.Id, false)) return; ExportRoofAsParts(exporterIFC, roof, geometryElement, productWrapper); // Right now, only flat roof could have parts. } else if (exportAsCurtainRoof) { CurtainSystemExporter.ExportCurtainRoof(exporterIFC, roof, productWrapper); } else { string ifcEnumType = ExporterUtil.GetIFCTypeFromExportTable(exporterIFC, roof); IFCAnyHandle roofHnd = ExporterIFCUtils.ExportRoofAsContainer(exporterIFC, ifcEnumType, roof, geometryElement, productWrapper.ToNative()); if (IFCAnyHandleUtil.IsNullOrHasNoValue(roofHnd)) ExportRoof(exporterIFC, ifcEnumType, roof, geometryElement, productWrapper); // call for host objects; curtain roofs excused from call (no material information) HostObjectExporter.ExportHostObjectMaterials(exporterIFC, roof, productWrapper.GetAnElement(), geometryElement, productWrapper, ElementId.InvalidElementId, IFCLayerSetDirection.Axis3, null); } tr.Commit(); } }
/// <summary> /// Exports a roof to IfcRoof. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="roof">The roof element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The IFCProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, RoofBase roof, GeometryElement geometryElement, IFCProductWrapper productWrapper) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { // export parts or not bool exportParts = PartExporter.CanExportParts(roof); bool exportAsExtrusionCurtainRoof = false; bool exportAsFootprintCurtainRoof = false; if (roof is ExtrusionRoof) { ExtrusionRoof extrusionRoof = roof as ExtrusionRoof; exportAsExtrusionCurtainRoof = ((extrusionRoof.CurtainGrids != null) && (extrusionRoof.CurtainGrids.Size != 0)); } else if (roof is FootPrintRoof) { FootPrintRoof footprintRoof = roof as FootPrintRoof; exportAsFootprintCurtainRoof = ((footprintRoof.CurtainGrids != null) && (footprintRoof.CurtainGrids.Size != 0)); } if (exportParts) { if (!PartExporter.CanExportElementInPartExport(roof, roof.Level.Id, false)) return; ExportRoofAsParts(exporterIFC, roof, geometryElement, productWrapper); // Right now, only flat roof could have parts. } else if (exportAsExtrusionCurtainRoof) { CurtainSystemExporter.ExportExtrusionRoof(exporterIFC, roof as ExtrusionRoof, productWrapper); } else if (exportAsFootprintCurtainRoof) { CurtainSystemExporter.ExportFootPrintRoof(exporterIFC, roof as FootPrintRoof, productWrapper); } else { string ifcEnumType = CategoryUtil.GetIFCEnumTypeName(exporterIFC, roof); IFCAnyHandle roofHnd = ExporterIFCUtils.ExportRoofAsContainer(exporterIFC, ifcEnumType, roof, geometryElement, productWrapper); if (IFCAnyHandleUtil.IsNullOrHasNoValue(roofHnd)) ExportRoof(exporterIFC, ifcEnumType, roof, geometryElement, productWrapper); PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, roof, productWrapper); // call for host objects; curtain roofs excused from call (no material information) HostObjectExporter.ExportHostObjectMaterials(exporterIFC, roof, productWrapper.GetAnElement(), geometryElement, productWrapper, ElementId.InvalidElementId, IFCLayerSetDirection.Axis3); } tr.Commit(); } }
private List <RunCollection> FindExisting() { // Find existing elements with a matching GUID from the GH component. List <RunCollection> collectedRuns = new List <RunCollection>(); Schema instanceSchema = Schema.Lookup(instanceSchemaGUID); if (instanceSchema == null) { return(collectedRuns); } ElementIsElementTypeFilter filter = new ElementIsElementTypeFilter(false); FilteredElementCollector fiCollector = new FilteredElementCollector(doc); fiCollector.OfClass(typeof(FamilyInstance)); fiCollector.ToElements(); FilteredElementCollector wallCollector = new FilteredElementCollector(doc); wallCollector.OfCategory(BuiltInCategory.OST_Walls); wallCollector.OfClass(typeof(Wall)); wallCollector.ToElements(); FilteredElementCollector floorCollector = new FilteredElementCollector(doc); floorCollector.OfCategory(BuiltInCategory.OST_Floors); floorCollector.OfClass(typeof(Floor)); floorCollector.ToElements(); FilteredElementCollector roofCollector = new FilteredElementCollector(doc); roofCollector.OfCategory(BuiltInCategory.OST_Roofs); roofCollector.OfClass(typeof(RoofBase)); roofCollector.ToElements(); List <Element> elemCollector = new List <Element>(); foreach (Element e in fiCollector) { elemCollector.Add(e); } foreach (Element e in wallCollector) { elemCollector.Add(e); } foreach (Element e in floorCollector) { elemCollector.Add(e); } foreach (Element e in roofCollector) { elemCollector.Add(e); } //FilteredElementCollector elemCollector = new FilteredElementCollector(doc); //elemCollector.WherePasses(filter).ToElements(); // First, find all of the unique componentGUID's that are in the Revit file. List <string> instanceIds = new List <string>(); foreach (Element e in elemCollector) { if (e.Category.Id.IntegerValue == -2000011) { try { Wall w = e as Wall; if (w != null) { Entity entity = w.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (!instanceIds.Contains(tempId)) { instanceIds.Add(tempId); } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } else if (e.Category.Id.IntegerValue == -2000032) { try { Floor flr = e as Floor; if (flr != null) { Entity entity = flr.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (!instanceIds.Contains(tempId)) { instanceIds.Add(tempId); } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } else if (e.Category.Id.IntegerValue == -2000035) { try { RoofBase r = e as RoofBase; if (r != null) { Entity entity = r.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (!instanceIds.Contains(tempId)) { instanceIds.Add(tempId); } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } else { try { FamilyInstance fi = e as FamilyInstance; if (fi != null) { Entity entity = fi.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (!instanceIds.Contains(tempId)) { instanceIds.Add(tempId); } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } } // Create a runCollection for each guid foreach (string id in instanceIds) { RunCollection rc = new RunCollection(); List <Runs> tempRuns = new List <Runs>(); // Find the number of runs per instanceId List <int> runIds = new List <int>(); foreach (Element e in elemCollector) { if (e.Category.Id.IntegerValue == -2000011) { // Walls try { Wall w = e as Wall; if (w != null) { Entity entity = w.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (tempId == id) { f = instanceSchema.GetField("NickName"); string nickName = entity.Get <string>(f); rc.ComponentGuid = new Guid(tempId); rc.NickName = nickName; f = instanceSchema.GetField("RunID"); int tempRunId = entity.Get <int>(f); if (!runIds.Contains(tempRunId)) { runIds.Add(tempRunId); } } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } else if (e.Category.Id.IntegerValue == -2000032) { // Floors try { Floor flr = e as Floor; if (flr != null) { Entity entity = flr.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (tempId == id) { f = instanceSchema.GetField("NickName"); string nickName = entity.Get <string>(f); rc.ComponentGuid = new Guid(tempId); rc.NickName = nickName; f = instanceSchema.GetField("RunID"); int tempRunId = entity.Get <int>(f); if (!runIds.Contains(tempRunId)) { runIds.Add(tempRunId); } } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } else if (e.Category.Id.IntegerValue == -2000035) { // Roofs try { RoofBase r = e as RoofBase; if (r != null) { Entity entity = r.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (tempId == id) { f = instanceSchema.GetField("NickName"); string nickName = entity.Get <string>(f); rc.ComponentGuid = new Guid(tempId); rc.NickName = nickName; f = instanceSchema.GetField("RunID"); int tempRunId = entity.Get <int>(f); if (!runIds.Contains(tempRunId)) { runIds.Add(tempRunId); } } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } else { // Other non-system families try { FamilyInstance fi = e as FamilyInstance; if (fi != null) { Entity entity = fi.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (tempId == id) { f = instanceSchema.GetField("NickName"); string nickName = entity.Get <string>(f); rc.ComponentGuid = new Guid(tempId); rc.NickName = nickName; f = instanceSchema.GetField("RunID"); int tempRunId = entity.Get <int>(f); if (!runIds.Contains(tempRunId)) { runIds.Add(tempRunId); } } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } } foreach (int i in runIds) { List <int> runElemIds = new List <int>(); Runs run = new Runs(); foreach (Element e in elemCollector) { try { if (e.Category.Id.IntegerValue == -2000011) { // Walls try { Wall w = e as Wall; if (w != null) { Entity entity = w.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (tempId == id) { f = instanceSchema.GetField("RunID"); int tempRunId = entity.Get <int>(f); if (tempRunId == i) { if (run.RunName == null || run.RunName == string.Empty) { run.RunId = tempRunId; run.RunName = "Run" + tempRunId.ToString(); run.FamilyType = w.Category.Name + " : " + w.WallType.Name; } runElemIds.Add(w.Id.IntegerValue); } } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } else if (e.Category.Id.IntegerValue == -2000032) { // Floors try { Floor flr = e as Floor; if (flr != null) { Entity entity = flr.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (tempId == id) { f = instanceSchema.GetField("RunID"); int tempRunId = entity.Get <int>(f); if (tempRunId == i) { if (run.RunName == null || run.RunName == string.Empty) { run.RunId = tempRunId; run.RunName = "Run" + tempRunId.ToString(); run.FamilyType = flr.Category.Name + " : " + flr.FloorType.Name; } runElemIds.Add(flr.Id.IntegerValue); } } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } else if (e.Category.Id.IntegerValue == -2000035) { // Roofs try { RoofBase r = e as RoofBase; if (r != null) { Entity entity = r.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (tempId == id) { f = instanceSchema.GetField("RunID"); int tempRunId = entity.Get <int>(f); if (tempRunId == i) { if (run.RunName == null || run.RunName == string.Empty) { run.RunId = tempRunId; run.RunName = "Run" + tempRunId.ToString(); run.FamilyType = r.Category.Name + " : " + r.RoofType.Name; } runElemIds.Add(r.Id.IntegerValue); } } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } else { // Other non-system families try { FamilyInstance fi = e as FamilyInstance; if (fi != null) { Entity entity = fi.GetEntity(instanceSchema); if (entity.IsValid()) { Field f = instanceSchema.GetField("InstanceID"); string tempId = entity.Get <string>(f); if (tempId == id) { f = instanceSchema.GetField("RunID"); int tempRunId = entity.Get <int>(f); if (tempRunId == i) { if (run.RunName == null || run.RunName == string.Empty) { run.RunId = tempRunId; run.RunName = "Run" + tempRunId.ToString(); run.FamilyType = fi.Symbol.Family.Name + " : " + fi.Symbol.Name; } runElemIds.Add(fi.Id.IntegerValue); } } } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } } catch (Exception ex) { Debug.WriteLine("Error", ex.Message); } } run.ElementIds = runElemIds; tempRuns.Add(run); } rc.Runs = tempRuns; collectedRuns.Add(rc); } return(collectedRuns); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { #region Get access to the current document and aplication. UIApplication uiapp = commandData.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application; Autodesk.Revit.DB.Document doc = commandData.Application.ActiveUIDocument.Document; #endregion // Try to create a project parameter. try { Category walls = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Walls); Category floors = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Floors); Category ceilings = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Ceilings); Category roofs = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Roofs); CategorySet catSet = new CategorySet(); catSet.Insert(walls); catSet.Insert(floors); catSet.Insert(ceilings); catSet.Insert(roofs); using (Transaction t = new Transaction(doc, "Add project parameter")) { t.Start(); CreateProjectParam(app, "LinkedTag", ParameterType.Integer, false, catSet, BuiltInParameterGroup.INVALID, true); if (t.Commit() == TransactionStatus.Committed) { } else { t.RollBack(); } } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } if (Schema.Lookup(new Guid("2B195204-1C04-4538-8881-AD22FA697B41")) == null) { BuildNewSchema(doc); } // Retrieving a specific family from the database. try { // Create a new FilteredElementCollector FilteredElementCollector collector = new FilteredElementCollector(doc); // Define and apply one or more filters to it. ElementCategoryFilter categoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericAnnotation); ParameterValueProvider pvp_1 = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_FAMILY_NAME)); ParameterValueProvider pvp_2 = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME)); FilterStringEquals equals = new FilterStringEquals(); string familyName = "Z-M2-MultilayerMaterialTag-LOD1"; string typeName = "2.5mm"; FilterRule fRule_1 = new FilterStringRule(pvp_1, equals, familyName, false); FilterRule fRule_2 = new FilterStringRule(pvp_2, equals, typeName, false); IList <FilterRule> fRules = new List <FilterRule> { fRule_1, fRule_2 }; ElementParameterFilter filters = new ElementParameterFilter(fRules); // Collect the familySymbol's id ICollection <ElementId> id = collector.WherePasses(categoryFilter).WherePasses(filters).ToElementIds(); if (id.Count == 0) { message = "No FamilyType has been detected."; return(Result.Failed); } AnnotationSymbolType materialTag = doc.GetElement(id.First()) as AnnotationSymbolType; if (CreateWorkPlane(doc) != true) { return(Result.Failed); } // Prompt the user to select select the element to be tagged. Reference pickedRef = null; pickedRef = uidoc.Selection.PickObject(ObjectType.Element, new MultilayerStrFilter(), "Please select a multilayer element."); Element selectedElm = doc.GetElement(pickedRef.ElementId); XYZ point = uidoc.Selection.PickPoint("Please pick a point to place the family"); StringBuilder strBld = new StringBuilder(); int rows; int shelfLength; switch (selectedElm.Category.Name) { case "Walls": Wall wl = selectedElm as Wall; WallType wlType = wl.WallType; CompoundStructure cmpStr_wl = wlType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_wl, doc, out shelfLength); rows = wlType.GetCompoundStructure().LayerCount; break; case "Floors": Floor fl = selectedElm as Floor; FloorType flType = fl.FloorType; CompoundStructure cmpStr_fl = flType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_fl, doc, out shelfLength); rows = flType.GetCompoundStructure().LayerCount; break; case "Ceilings": Ceiling cl = selectedElm as Ceiling; CeilingType clType = doc.GetElement(cl.GetTypeId()) as CeilingType; CompoundStructure cmpStr_cl = clType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_cl, doc, out shelfLength); rows = clType.GetCompoundStructure().LayerCount; break; case "Roofs": RoofBase rf = selectedElm as RoofBase; RoofType rfType = rf.RoofType; CompoundStructure cmpStr_rf = rfType.GetCompoundStructure(); strBld = LayersAsString(cmpStr_rf, doc, out shelfLength); rows = rfType.GetCompoundStructure().LayerCount; break; default: TaskDialog.Show("Warning!", "This category is not supported."); return(Result.Failed); } using (Transaction trn_1 = new Transaction(doc, "Materials Mark")) { FamilyInstance createdElm = null; if (trn_1.Start() == TransactionStatus.Started) { createdElm = doc.Create.NewFamilyInstance(point, materialTag, doc.ActiveView); selectedElm.LookupParameter("LinkedTag").Set(createdElm.Id.IntegerValue); if (trn_1.Commit() == TransactionStatus.Committed) { Transaction trn_2 = new Transaction(doc, "Set parameters"); try { trn_2.Start(); createdElm.LookupParameter("multilineText").Set(strBld.ToString()); createdElm.LookupParameter("# of Rows").Set(rows); createdElm.LookupParameter("Shelf Length").Set(ToFt(shelfLength)); XYZ vec; if (selectedElm.Category.Name != "Walls") { vec = new XYZ(0, 0, createdElm.LookupParameter("Arrow Length").AsDouble() * doc.ActiveView.Scale); createdElm.LookupParameter("Down Arrow Direction").Set(1); } else { vec = new XYZ(-createdElm.LookupParameter("Arrow Length").AsDouble() * doc.ActiveView.Scale, 0, 0); createdElm.LookupParameter("Down Arrow Direction").Set(0); } ElementTransformUtils.MoveElement(doc, createdElm.Id, vec); trn_2.Commit(); AddElementToSchema(Schema.Lookup(new Guid("2B195204-1C04-4538-8881-AD22FA697B41")), createdElm, selectedElm.Id); } finally { if (trn_2 != null) { trn_2.Dispose(); } } } else { trn_1.RollBack(); return(Result.Failed); } } else { trn_1.RollBack(); return(Result.Failed); } return(Result.Succeeded); } } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool"); m_Revit = commandData.Application; try { transaction.Start(); Autodesk.Revit.ApplicationServices.Application aPPlication = commandData.Application.Application; Autodesk.Revit.UI.UIApplication reVit = commandData.Application; Document dOcument = commandData.Application.ActiveUIDocument.Document; Autodesk.Revit.DB.View view; view = dOcument.ActiveView; # region FindingFloorslabs //Filter out the roofbase elements (roofs slabs) FilteredElementIterator iter = (new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document)) .OfClass(typeof(RoofBase)).GetElementIterator(); iter.Reset(); while (iter.MoveNext()) { Object obj = iter.Current; //Check whether the object is slab if (obj is RoofBase) { RoofBase slabFloor = obj as RoofBase; string level, elementID; slabFloor = (RoofBase)iter.Current; level = slabFloor.Level.Name; elementID = slabFloor.Id.IntegerValue.ToString(); MessageBox.Show("Select the Walls and Railings along the boundary of the Slab at " + level); IList <Reference> reFs = null; List <ElementId> ids = null; try { Selection seLect = commandData.Application.ActiveUIDocument.Selection; reFs = seLect.PickObjects(ObjectType.Element, "Select the Walls and Railings along the boundary of the Slab"); ids = new List <ElementId>(reFs.Select <Reference, ElementId>(r => r.ElementId)); reFs = null; object oBJect; foreach (ElementId iD in ids) { oBJect = (object)dOcument.GetElement(iD); //Calls shared parameter routines bool successAddParameter = SetNewParameter(); SetValueElementInfoParameter(oBJect, elementID, "Slab"); //end of code to call shared parameter routines } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } } } # endregion FindingFloorslabs # region FindingOpenings
/***************************************************/ public static List <oM.Environment.Elements.Panel> EnvironmentPanelsFromRevit(this RoofBase roofBase, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); List <oM.Environment.Elements.Panel> panels = refObjects.GetValues <oM.Environment.Elements.Panel>(roofBase.Id); if (panels != null && panels.Count > 0) { return(panels); } Dictionary <PlanarSurface, List <PlanarSurface> > surfaces = roofBase.PanelSurfaces(roofBase.FindInserts(true, true, true, true), settings); if (surfaces == null) { return(panels); } BH.oM.Physical.Constructions.Construction construction = roofBase.RoofType.ConstructionFromRevit(null, settings, refObjects); panels = new List <oM.Environment.Elements.Panel>(); foreach (PlanarSurface surface in surfaces.Keys) { //Create the BuildingElement oM.Environment.Elements.Panel panel = new oM.Environment.Elements.Panel() { ExternalEdges = surface.ExternalBoundary.ToEdges(), Name = roofBase.FamilyTypeFullName(), }; //Set ExtendedProperties OriginContextFragment originContext = new OriginContextFragment() { ElementID = roofBase.Id.IntegerValue.ToString(), TypeName = roofBase.FamilyTypeFullName() }; originContext.SetProperties(roofBase.RoofType, settings.ParameterSettings); originContext.SetProperties(roofBase, settings.ParameterSettings); panel.AddFragment(originContext); PanelAnalyticalFragment panelAnalytical = new PanelAnalyticalFragment(); panelAnalytical.SetProperties(roofBase.RoofType, settings.ParameterSettings); panelAnalytical.SetProperties(roofBase, settings.ParameterSettings); panel.AddFragment(panelAnalytical); PanelContextFragment panelContext = new PanelContextFragment(); panelContext.SetProperties(roofBase.RoofType, settings.ParameterSettings); panelContext.SetProperties(roofBase, settings.ParameterSettings); panel.AddFragment(panelContext); BuildingResultFragment buildingResults = new BuildingResultFragment(); buildingResults.SetProperties(roofBase.RoofType, settings.ParameterSettings); buildingResults.SetProperties(roofBase, settings.ParameterSettings); panel.AddFragment(buildingResults); panel.Construction = construction; panel.Type = oM.Environment.Elements.PanelType.Roof; //Set identifiers, parameters & custom data panel.SetIdentifiers(roofBase); panel.CopyParameters(roofBase, settings.ParameterSettings); panel.SetProperties(roofBase, settings.ParameterSettings); refObjects.AddOrReplace(roofBase.Id, panel); panels.Add(panel); } return(panels); }