/// <summary> /// Convert a wall to an IfcWallStandardCase /// </summary> /// <param name="wall"></param> /// <param name="context"></param> /// <param name="doc"></param> /// <returns></returns> private static IfcWallStandardCase ToIfcWallStandardCase(this Wall wall, IfcRepresentationContext context, Document doc) { var sweptArea = wall.CenterLine.Thicken(wall.Thickness()).ToIfcArbitraryClosedProfileDef(doc); var extrudeDirection = Vector3.ZAxis.ToIfcDirection(); // We don't use the Wall's transform for positioning, because // our walls have a transform that lays the wall "flat". Just // use a identity transform. var position = new Transform().ToIfcAxis2Placement3D(doc); var repItem = new IfcExtrudedAreaSolid(sweptArea, position, extrudeDirection, new IfcPositiveLengthMeasure(wall.Height)); var rep = new IfcShapeRepresentation(context, "Body", "SweptSolid", new List <IfcRepresentationItem> { repItem }); var productRep = new IfcProductDefinitionShape(new List <IfcRepresentation> { rep }); var id = IfcGuid.ToIfcGuid(Guid.NewGuid()); var localPlacement = new Transform().ToIfcLocalPlacement(doc); var ifcWall = new IfcWallStandardCase(new IfcGloballyUniqueId(id), null, wall.Name, null, null, localPlacement, productRep, null); doc.AddEntity(sweptArea); doc.AddEntity(extrudeDirection); doc.AddEntity(position); doc.AddEntity(repItem); doc.AddEntity(rep); doc.AddEntity(localPlacement); doc.AddEntity(productRep); doc.AddEntity(ifcWall); return(ifcWall); }
internal static Column ToColumn(this IfcColumn column) { var elementTransform = column.ObjectPlacement.ToTransform(); var solid = column.RepresentationsOfType <IfcExtrudedAreaSolid>().FirstOrDefault(); foreach (var cis in column.ContainedInStructure) { cis.RelatingStructure.ObjectPlacement.ToTransform().Concatenate(elementTransform); } if (solid != null) { var solidTransform = solid.Position.ToTransform(); var c = solid.SweptArea.ToCurve(); var result = new Column(solidTransform.Origin, (IfcLengthMeasure)solid.Depth, new Profile((Polygon)c), BuiltInMaterials.Steel, elementTransform, 0.0, 0.0, 0.0, false, IfcGuid.FromIfcGUID(column.GlobalId), column.Name); return(result); } return(null); }
internal static Beam ToBeam(this IfcBeam beam) { var elementTransform = beam.ObjectPlacement.ToTransform(); var solid = beam.RepresentationsOfType <IfcExtrudedAreaSolid>().FirstOrDefault(); // foreach (var cis in beam.ContainedInStructure) // { // cis.RelatingStructure.ObjectPlacement.ToTransform().Concatenate(transform); // } if (solid != null) { var solidTransform = solid.Position.ToTransform(); var c = solid.SweptArea.ToCurve(); if (c is Polygon) { var cl = new Line(Vector3.Origin, solid.ExtrudedDirection.ToVector3(), (IfcLengthMeasure)solid.Depth); var result = new Beam(solidTransform.OfLine(cl), new Profile((Polygon)c), BuiltInMaterials.Steel, 0.0, 0.0, 0.0, elementTransform, false, IfcGuid.FromIfcGUID(beam.GlobalId), beam.Name); return(result); } } return(null); }
internal static Wall ToWall(this IfcWallStandardCase wall, IEnumerable <IfcOpeningElement> openings) { var transform = new Transform(); transform.Concatenate(wall.ObjectPlacement.ToTransform()); var os = openings.Select(o => o.ToOpening()); // An extruded face solid. var solid = wall.RepresentationsOfType <IfcExtrudedAreaSolid>().FirstOrDefault(); if (solid == null) { // It's possible that the rep is a boolean. var boolean = wall.RepresentationsOfType <IfcBooleanClippingResult>().FirstOrDefault(); if (boolean != null) { solid = boolean.FirstOperand.Choice as IfcExtrudedAreaSolid; if (solid == null) { solid = boolean.SecondOperand.Choice as IfcExtrudedAreaSolid; } } // if(solid == null) // { // throw new Exception("No usable solid was found when converting an IfcWallStandardCase to a Wall."); // } } // A centerline wall with material layers. // var axis = (Polyline)wall.RepresentationsOfType<IfcPolyline>().FirstOrDefault().ToICurve(false); foreach (var cis in wall.ContainedInStructure) { cis.RelatingStructure.ObjectPlacement.ToTransform().Concatenate(transform); } if (solid != null) { var c = solid.SweptArea.ToCurve(); if (c is Polygon) { transform.Concatenate(solid.Position.ToTransform()); var result = new Wall((Polygon)c, (IfcLengthMeasure)solid.Depth, null, transform, null, false, IfcGuid.FromIfcGUID(wall.GlobalId), wall.Name); result.Openings.AddRange(os); return(result); } } return(null); }
private static IfcColumn ToIfc(this Column column, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var ifcColumn = new IfcColumn(IfcGuid.ToIfcGuid(id), null, null, null, null, localPlacement, shape, null, IfcColumnTypeEnum.COLUMN); return(ifcColumn); }
private static IfcSlab ToIfc(this Floor floor, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var slab = new IfcSlab(IfcGuid.ToIfcGuid(id), null, null, null, null, localPlacement, shape, null, IfcSlabTypeEnum.FLOOR); return(slab); }
private static IfcMember ToIfc(this Brace column, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var member = new IfcMember(IfcGuid.ToIfcGuid(id), null, null, null, null, localPlacement, shape, null, IfcMemberTypeEnum.NOTDEFINED); return(member); }
private static IfcPlate ToIfc(this Panel panel, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var plate = new IfcPlate(IfcGuid.ToIfcGuid(id), null, null, null, null, localPlacement, shape, null, IfcPlateTypeEnum.NOTDEFINED); return(plate); }
private static IfcBuildingElementProxy ToIfc(this Mass mass, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var proxy = new IfcBuildingElementProxy(IfcGuid.ToIfcGuid(id), null, null, null, null, localPlacement, shape, null, IfcBuildingElementProxyTypeEnum.ELEMENT); return(proxy); }
private static IfcPlate ToIfc(this Panel panel, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var plate = new IfcPlate(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, null, null, null, localPlacement, shape, null); return(plate); }
private static IfcMember ToIfc(this Brace column, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var member = new IfcMember(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, null, null, null, localPlacement, shape, null); return(member); }
private static IfcColumn ToIfc(this Column column, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var ifcColumn = new IfcColumn(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, null, null, null, localPlacement, shape, null); return(ifcColumn); }
private static IfcBeam ToIfc(this Beam beam, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var ifcBeam = new IfcBeam(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, null, null, null, localPlacement, shape, null); return(ifcBeam); }
private static IfcWall ToIfc(this Wall wall, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var ifcWall = new IfcWall(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, wall.Name, null, null, localPlacement, shape, null); return(ifcWall); }
private static IfcBeam ToIfc(this Beam beam, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var ifcBeam = new IfcBeam(IfcGuid.ToIfcGuid(beam.Id), null, null, null, null, localPlacement, shape, null, IfcBeamTypeEnum.BEAM); return(ifcBeam); }
// TODO: There is a lot of duplicate code used to create products. // Can we make a generic method like ToIfc<TProduct>()? There are // exceptions for which this won't work like IfcSpace. private static IfcSpace ToIfc(this Space space, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var ifcSpace = new IfcSpace(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, null, null, null, localPlacement, shape, null, IfcElementCompositionEnum.ELEMENT, IfcInternalOrExternalEnum.NOTDEFINED, new IfcLengthMeasure(space.Transform.Origin.Z)); return(ifcSpace); }
private static IfcOpeningElement ToIfc(this Opening opening, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var ifcOpening = new IfcOpeningElement(IfcGuid.ToIfcGuid(id), null, null, null, null, localPlacement, shape, null, IfcOpeningElementTypeEnum.OPENING); return(ifcOpening); }
private static IfcBuildingElementProxy ToIfc(this GeometricElement element, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var proxy = new IfcBuildingElementProxy(IfcGuid.ToIfcGuid(id), null, element.Name, $"A {element.GetType().Name} created in Hypar.", $"{element.GetType().FullName}", localPlacement, shape, null, IfcBuildingElementProxyTypeEnum.ELEMENT); return(proxy); }
private static IfcWall ToIfc(this Wall wall, Guid id, IfcLocalPlacement localPlacement, IfcProductDefinitionShape shape) { var ifcWall = new IfcWall(IfcGuid.ToIfcGuid(id), null, wall.Name, null, null, localPlacement, shape, null, IfcWallTypeEnum.NOTDEFINED); return(ifcWall); }
/// <summary> /// Creates a map between revit element ids and their IFC GUIDs inside the given document. /// </summary> /// <param name="doc">A revit document</param> /// <param name="elements">A list of element ids</param> /// <returns>The map between IFC GUIDs and revit element ids.</returns> public static Dictionary <string, ElementId> GetIfcGuidElementIdMap(this Document doc, IEnumerable <ElementId> elements) { var map = new Dictionary <string, ElementId>(); foreach (ElementId element in elements) { var ifcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, element)); if (!map.ContainsKey(ifcGuid)) { map.Add(ifcGuid, element); } } return(map); }
internal static Opening ToOpening(this IfcOpeningElement opening) { var openingTransform = opening.ObjectPlacement.ToTransform(); var s = opening.RepresentationsOfType <IfcExtrudedAreaSolid>().FirstOrDefault(); if (s != null) { var solidTransform = s.Position.ToTransform(); solidTransform.Concatenate(openingTransform); var profile = (Polygon)s.SweptArea.ToCurve(); // Console.WriteLine($"Opening profile:\n{profile.ToString()}\n"); var newOpening = new Opening(profile, (IfcLengthMeasure)s.Depth, solidTransform, null, false, IfcGuid.FromIfcGUID(opening.GlobalId)); return(newOpening); } return(null); }
private static IfcBeam ToIfcBeam(this Beam beam, IfcRepresentationContext context, Document doc) { var sweptArea = beam.ElementType.Profile.Perimeter.ToIfcArbitraryClosedProfileDef(doc); var line = beam.Curve as Line; if (line == null) { throw new Exception("The beam could not be exported to IFC. Only linear beams are currently supported."); } // We use the Z extrude direction because the direction is // relative to the local placement, which is a transform at the // beam's end with the Z axis pointing along the direction. var extrudeDirection = Vector3.ZAxis.ToIfcDirection(); var position = new Transform().ToIfcAxis2Placement3D(doc); var repItem = new IfcExtrudedAreaSolid(sweptArea, position, extrudeDirection, new IfcPositiveLengthMeasure(beam.Curve.Length())); var localPlacement = beam.Curve.TransformAt(0.0).ToIfcLocalPlacement(doc); var rep = new IfcShapeRepresentation(context, "Body", "SweptSolid", new List <IfcRepresentationItem> { repItem }); var productRep = new IfcProductDefinitionShape(new List <IfcRepresentation> { rep }); var ifcBeam = new IfcBeam(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, null, null, null, localPlacement, productRep, null); doc.AddEntity(sweptArea); doc.AddEntity(extrudeDirection); doc.AddEntity(position); doc.AddEntity(repItem); doc.AddEntity(rep); doc.AddEntity(localPlacement); doc.AddEntity(productRep); doc.AddEntity(ifcBeam); return(ifcBeam); }
private static IfcOpeningElement ToIfcOpeningElement(this Opening opening, IfcRepresentationContext context, Document doc, IfcObjectPlacement parent) { // var sweptArea = opening.Profile.Perimeter.ToIfcArbitraryClosedProfileDef(doc); // We use the Z extrude direction because the direction is // relative to the local placement, which is a transform at the // beam's end with the Z axis pointing along the direction. // var extrudeDirection = opening.ExtrudeDirection.ToIfcDirection(); // var position = new Transform().ToIfcAxis2Placement3D(doc); // var solid = new IfcExtrudedAreaSolid(sweptArea, position, // extrudeDirection, new IfcPositiveLengthMeasure(opening.ExtrudeDepth)); var solid = opening.ToIfcExtrudedAreaSolid(new Transform(), doc); var localPlacement = new Transform().ToIfcLocalPlacement(doc, parent); var shape = new IfcShapeRepresentation(context, "Body", "SweptSolid", new List <IfcRepresentationItem> { solid }); var productRep = new IfcProductDefinitionShape(new List <IfcRepresentation> { shape }); var ifcOpening = new IfcOpeningElement(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, null, null, null, localPlacement, productRep, null); // doc.AddEntity(sweptArea); // doc.AddEntity(extrudeDirection); // doc.AddEntity(position); // doc.AddEntity(repItem); doc.AddEntity(solid); doc.AddEntity(localPlacement); doc.AddEntity(shape); doc.AddEntity(productRep); return(ifcOpening); }
/// <summary> /// Generate Viewpoint /// </summary> /// <param name="elemCheck"></param> /// <returns></returns> public VisualizationInfo generateViewpoint(int elemCheck) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; VisualizationInfo v = new VisualizationInfo(); XYZ centerIMP = new XYZ(); string type = ""; double zoomValue = 1; if (uidoc.ActiveView.ViewType != ViewType.ThreeD) //is a 2D view { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; v.SheetCamera = new SheetCamera(); v.SheetCamera.SheetID = uidoc.ActiveView.Id.IntegerValue; v.SheetCamera.TopLeft = new IssueTracker.Classes.BCF2.Point(TL.X, TL.Y, TL.Z); v.SheetCamera.BottomRight = new IssueTracker.Classes.BCF2.Point(BR.X, BR.Y, BR.Z); } else { View3D view3D = (View3D)uidoc.ActiveView; if (!view3D.IsPerspective) //IS ORTHO { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; double xO = (TL.X + BR.X) / 2; double yO = (TL.Y + BR.Y) / 2; double zO = (TL.Z + BR.Z) / 2; //converto to METERS centerIMP = new XYZ(xO, yO, zO); double dist = TL.DistanceTo(BR) / 2; //custom sectet value to get solibri zoom value from Corners of Revit UiView XYZ diagVector = TL.Subtract(BR); // **** CUSTOM VALUE FOR TEKLA **** // //zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS); // **** CUSTOM VALUE FOR TEKLA **** // double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS) * customZoomValue; type = "OrthogonalCamera"; } else // it is a perspective view { centerIMP = uidoc.ActiveView.Origin; type = "PerspectiveCamera"; zoomValue = 45; } ViewOrientation3D t = ConvertBasePoint(centerIMP, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); //ViewOrientation3D t = new ViewOrientation3D(centerIMP, uidoc.ActiveView.UpDirection, uidoc.ActiveView.ViewDirection); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; if (type == "OrthogonalCamera") { v.OrthogonalCamera = new OrthogonalCamera(); v.OrthogonalCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.ViewToWorldScale = zoomValue; } else { v.PerspectiveCamera = new PerspectiveCamera(); v.PerspectiveCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.FieldOfView = zoomValue; } // handle section box if enabled if (view3D.IsSectionBoxActive) { BoundingBoxXYZ sectionBox = view3D.GetSectionBox(); // Note that the section box can be rotated and transformed. // So the min/max corners coordinates relative to the model must be computed via the transform. Transform trf = sectionBox.Transform; XYZ max = sectionBox.Max; //Maximum coordinates (upper-right-front corner of the box before transform is applied). XYZ min = sectionBox.Min; //Minimum coordinates (lower-left-rear corner of the box before transform is applied). // Transform the min and max to model coordinates XYZ maxInModelCoords = trf.OfPoint(max); XYZ minInModelCoords = trf.OfPoint(min); // Convert to project unit DisplayUnitType lengthUnitType = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits; maxInModelCoords = new XYZ(UnitUtils.ConvertFromInternalUnits(maxInModelCoords.X, lengthUnitType), UnitUtils.ConvertFromInternalUnits(maxInModelCoords.Y, lengthUnitType), UnitUtils.ConvertFromInternalUnits(maxInModelCoords.Z, lengthUnitType)); minInModelCoords = new XYZ(UnitUtils.ConvertFromInternalUnits(minInModelCoords.X, lengthUnitType), UnitUtils.ConvertFromInternalUnits(minInModelCoords.Y, lengthUnitType), UnitUtils.ConvertFromInternalUnits(minInModelCoords.Z, lengthUnitType)); // Convert to shared coordinates maxInModelCoords = ARUP.IssueTracker.Revit.Classes.Utils.ConvertToFromSharedCoordinate(doc, maxInModelCoords, false); minInModelCoords = ARUP.IssueTracker.Revit.Classes.Utils.ConvertToFromSharedCoordinate(doc, minInModelCoords, false); // Add to BCF clipping planes v.ClippingPlanes = BcfAdapter.GetClippingPlanesFromBoundingBox ( maxInModelCoords.X, maxInModelCoords.Y, maxInModelCoords.Z, minInModelCoords.X, minInModelCoords.Y, minInModelCoords.Z ); } } //COMPONENTS PART FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType(); System.Collections.Generic.ICollection <ElementId> collection = null; if (elemCheck == 0) { collection = collector.ToElementIds(); } else if (elemCheck == 1) { collection = uidoc.Selection.GetElementIds(); } if (null != collection && collection.Any()) { v.Components = new List <IssueTracker.Classes.BCF2.Component>(); foreach (var eId in collection) { Guid guid = ExportUtils.GetExportId(doc, eId); string ifcguid = IfcGuid.ToIfcGuid(guid).ToString(); v.Components.Add(new ARUP.IssueTracker.Classes.BCF2.Component(doc.Application.VersionName, eId.ToString(), ifcguid)); } } return(v); } catch (System.Exception ex1) { TaskDialog.Show("Error!", "exception: " + ex1); } return(null); }
/// <summary> /// Write the model to IFC. /// </summary> /// <param name="model"></param> /// <param name="path">The path to the generated IFC STEP file.</param> public static void ToIFC(this Model model, string path) { var ifc = new Document("Elements", "Elements", Environment.UserName, null, null, null, "Elements", null, null, null, null, null, null, null, null ); var proj = ifc.AllInstancesOfType <IfcProject>().FirstOrDefault(); // Add a site var site = new IfcSite(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, IfcElementCompositionEnum.ELEMENT); var projAggregate = new IfcRelAggregates(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, proj, new List <IfcObjectDefinition> { site }); // Add building and building storey var building = new IfcBuilding(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, IfcElementCompositionEnum.ELEMENT); var storey = new IfcBuildingStorey(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, IfcElementCompositionEnum.ELEMENT); var aggregate = new IfcRelAggregates(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, building, new List <IfcObjectDefinition> { storey }); // Aggregate the building into the site var siteAggregate = new IfcRelAggregates(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, site, new List <IfcObjectDefinition> { building }); ifc.AddEntity(site); ifc.AddEntity(projAggregate); ifc.AddEntity(building); ifc.AddEntity(storey); ifc.AddEntity(aggregate); ifc.AddEntity(siteAggregate); var products = new List <IfcProduct>(); var context = ifc.AllInstancesOfType <IfcGeometricRepresentationContext>().FirstOrDefault(); foreach (var e in model.Elements.Values) { try { products.AddRange(e.ToIfcProducts(context, ifc)); } catch (Exception ex) { Console.WriteLine($"There was an error writing an element of type {e.GetType()} to IFC: " + ex.Message); Console.WriteLine(ex.StackTrace); continue; } } var spatialRel = new IfcRelContainedInSpatialStructure(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, products, storey); ifc.AddEntity(spatialRel); if (File.Exists(path)) { File.Delete(path); } File.WriteAllText(path, ifc.ToSTEP(path)); }
//<summary> //Generate a VisualizationInfo of the current view //</summary> //<returns></returns> private VisualizationInfo GenerateViewpoint() { try { var uidoc = uiapp.ActiveUIDocument; var doc = uidoc.Document; var v = new VisualizationInfo(); //Corners of the active UI view var topLeft = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; var bottomRight = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; //It's a 2D view //not supported by BCF, but I store it under a custom //fields using 2D coordinates and sheet id if (uidoc.ActiveView.ViewType != ViewType.ThreeD) { v.SheetCamera = new SheetCamera { SheetID = uidoc.ActiveView.Id.IntegerValue, TopLeft = new Point { X = topLeft.X, Y = topLeft.Y, Z = topLeft.Z }, BottomRight = new Point { X = bottomRight.X, Y = bottomRight.Y, Z = bottomRight.Z } }; } //It's a 3d view else { var viewCenter = new XYZ(); var view3D = (View3D)uidoc.ActiveView; double zoomValue = 1; // it is a orthogonal view if (!view3D.IsPerspective) { double x = (topLeft.X + bottomRight.X) / 2; double y = (topLeft.Y + bottomRight.Y) / 2; double z = (topLeft.Z + bottomRight.Z) / 2; //center of the UI view viewCenter = new XYZ(x, y, z); //vector going from BR to TL XYZ diagVector = topLeft.Subtract(bottomRight); //lenght of the vector double dist = topLeft.DistanceTo(bottomRight) / 2; //ViewToWorldScale value zoomValue = dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)).ToMeters(); // **** CUSTOM VALUE FOR TEKLA **** // // calculated sperimentally, not sure why but it works //if (UserSettings.Get("optTekla") == "1") // zoomValue = zoomValue * 2.5; // **** CUSTOM VALUE FOR TEKLA **** // ViewOrientation3D t = RevitUtils.ConvertBasePoint(doc, viewCenter, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; v.OrthogonalCamera = new OrthogonalCamera { CameraViewPoint = { X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }, CameraUpVector = { X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }, CameraDirection = { X = vi.X.ToMeters() * -1, Y = vi.Y.ToMeters() * -1, Z = vi.Z.ToMeters() * -1 }, ViewToWorldScale = zoomValue }; } // it is a perspective view else { viewCenter = uidoc.ActiveView.Origin; //revit default value zoomValue = 45; ViewOrientation3D t = RevitUtils.ConvertBasePoint(doc, viewCenter, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; v.PerspectiveCamera = new PerspectiveCamera { CameraViewPoint = { X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }, CameraUpVector = { X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }, CameraDirection = { X = vi.X.ToMeters() * -1, Y = vi.Y.ToMeters() * -1, Z = vi.Z.ToMeters() * -1 }, FieldOfView = zoomValue }; } } //COMPONENTS PART string versionName = doc.Application.VersionName; v.Components = new List <Component>(); var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .ToElementIds(); var hiddenElems = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .Where(x => x.IsHidden(doc.ActiveView) || !doc.ActiveView.IsElementVisibleInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate, x.Id)).ToList();//would need to check how much this is affecting performance var selectedElems = uidoc.Selection.GetElementIds(); //include only hidden elements and selected in the BCF if (visibleElems.Count() > hiddenElems.Count()) { foreach (var elem in hiddenElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem.Id)), Visible = false, Selected = false, AuthoringToolId = elem.Id.IntegerValue.ToString() }); } foreach (var elem in selectedElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)), Visible = true, Selected = true, AuthoringToolId = elem.IntegerValue.ToString() }); } } //include only visigle elements //all the others are hidden else { foreach (var elem in visibleElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)), Visible = true, Selected = selectedElems.Contains(elem), AuthoringToolId = elem.IntegerValue.ToString() }); } } return(v); } catch (System.Exception ex1) { TaskDialog.Show("Error generating viewpoint", "exception: " + ex1); } return(null); }
/// <summary> /// Write the model to IFC. /// </summary> /// <param name="model"></param> /// <param name="path">The path to the generated IFC STEP file.</param> public static void ToIFC(this Model model, string path) { var ifc = new Document("Elements", "Elements", Environment.UserName, null, null, null, "Elements", null, null, null, null, null, null, null, null ); var proj = ifc.AllInstancesOfType <IfcProject>().FirstOrDefault(); // Add a site var site = new IfcSite(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, "Hypar Site", "The default site generated by Hypar", null, null, null, null, IfcElementCompositionEnum.ELEMENT, new IfcCompoundPlaneAngleMeasure(new List <int> { 0, 0, 0 }), new IfcCompoundPlaneAngleMeasure(new List <int> { 0, 0, 0 }), 0, null, null); var projAggregate = new IfcRelAggregates(IfcGuid.ToIfcGuid(Guid.NewGuid()), proj, new List <IfcObjectDefinition> { site }); // Add building and building storey var building = new IfcBuilding(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, "Default Building", "The default building generated by Hypar.", null, null, null, null, IfcElementCompositionEnum.ELEMENT, 0, 0, null); var storey = new IfcBuildingStorey(IfcGuid.ToIfcGuid(Guid.NewGuid()), null, "Default Storey", "The default storey generated by Hypar", null, null, null, null, IfcElementCompositionEnum.ELEMENT, 0); var aggregate = new IfcRelAggregates(IfcGuid.ToIfcGuid(Guid.NewGuid()), building, new List <IfcObjectDefinition> { storey }); // Aggregate the building into the site var siteAggregate = new IfcRelAggregates(IfcGuid.ToIfcGuid(Guid.NewGuid()), site, new List <IfcObjectDefinition> { building }); ifc.AddEntity(site); ifc.AddEntity(projAggregate); ifc.AddEntity(building); ifc.AddEntity(storey); ifc.AddEntity(aggregate); ifc.AddEntity(siteAggregate); var products = new List <IfcProduct>(); var context = ifc.AllInstancesOfType <IfcGeometricRepresentationContext>().FirstOrDefault(); // IfcRelAssociatesMaterial // IfcMaterialDefinitionRepresentation // https://forums.buildingsmart.org/t/where-and-how-will-my-colors-be-saved-in-ifc/1806/12 var styleAssignments = new Dictionary <Guid, List <IfcStyleAssignmentSelect> >(); var white = Colors.White.ToIfcColourRgb(); ifc.AddEntity(white); // TODO: Fix color support in all applications. // https://forums.buildingsmart.org/t/why-is-it-so-difficult-to-get-colors-to-show-up/2312/12 foreach (var m in model.AllElementsOfType <Material>()) { var material = new IfcMaterial(m.Name, null, "Hypar"); ifc.AddEntity(material); var color = m.Color.ToIfcColourRgb(); ifc.AddEntity(color); var transparency = new IfcNormalisedRatioMeasure(1.0 - m.Color.Alpha); var shading = new IfcSurfaceStyleShading(color, transparency); ifc.AddEntity(shading); var styles = new List <IfcSurfaceStyleElementSelect> { new IfcSurfaceStyleElementSelect(shading), }; var surfaceStyle = new IfcSurfaceStyle(material.Name, IfcSurfaceSide.BOTH, styles); ifc.AddEntity(surfaceStyle); var styleAssign = new IfcStyleAssignmentSelect(surfaceStyle); var assignments = new List <IfcStyleAssignmentSelect>() { styleAssign }; styleAssignments.Add(m.Id, assignments); } foreach (var e in model.Elements.Values.Where(e => { var t = e.GetType(); return(((e is GeometricElement && !((GeometricElement)e).IsElementDefinition) || e is ElementInstance) && t != typeof(ModelCurve) && t != typeof(ModelPoints) && t != typeof(AnalysisMesh)); })) { try { products.AddRange(e.ToIfcProducts(context, ifc, styleAssignments)); } catch (Exception ex) { Console.WriteLine($"There was an error writing an element of type {e.GetType()} to IFC: " + ex.Message); Console.WriteLine(ex.StackTrace); continue; } } var spatialRel = new IfcRelContainedInSpatialStructure(IfcGuid.ToIfcGuid(Guid.NewGuid()), products, storey); ifc.AddEntity(spatialRel); if (File.Exists(path)) { File.Delete(path); } File.WriteAllText(path, ifc.ToSTEP(path)); }
/// <summary> /// Generate Viewpoint /// </summary> /// <param name="elemCheck"></param> /// <returns></returns> private VisualizationInfo generateViewpoint(int elemCheck) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; VisualizationInfo v = new VisualizationInfo(); XYZ centerIMP = new XYZ(); string type = ""; double zoomValue = 1; if (uidoc.ActiveView.ViewType != ViewType.ThreeD) //is a 2D view { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; v.SheetCamera = new SheetCamera(); v.SheetCamera.SheetID = uidoc.ActiveView.Id.IntegerValue; v.SheetCamera.TopLeft = new IssueTracker.Data.Point(TL.X, TL.Y, TL.Z); v.SheetCamera.BottomRight = new IssueTracker.Data.Point(BR.X, BR.Y, BR.Z); } else { View3D view3D = (View3D)uidoc.ActiveView; if (!view3D.IsPerspective) //IS ORTHO { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; double xO = (TL.X + BR.X) / 2; double yO = (TL.Y + BR.Y) / 2; double zO = (TL.Z + BR.Z) / 2; //converto to METERS centerIMP = new XYZ(xO, yO, zO); double dist = TL.DistanceTo(BR) / 2; //custom value to get solibri zoom value from Corners of Revit UiView XYZ diagVector = TL.Subtract(BR); double customZoomValue = (ProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS) * customZoomValue; type = "OrthogonalCamera"; } else // it is a perspective view { centerIMP = uidoc.ActiveView.Origin; type = "PerspectiveCamera"; zoomValue = 45; } ViewOrientation3D t = ConvertBasePoint(centerIMP, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; if (type == "OrthogonalCamera") { v.OrthogonalCamera = new OrthogonalCamera(); v.OrthogonalCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.ViewToWorldScale = zoomValue; } else { v.PerspectiveCamera = new PerspectiveCamera(); v.PerspectiveCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.FieldOfView = zoomValue; } } //COMPONENTS PART FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType(); System.Collections.Generic.ICollection <ElementId> collection = null; if (elemCheck == 0) { collection = collector.ToElementIds(); } else if (elemCheck == 1) { collection = uidoc.Selection.GetElementIds(); } if (null != collection && collection.Any()) { v.Components = new IssueTracker.Data.Component[collection.Count]; for (var i = 0; i < collection.Count; i++) { Guid guid = ExportUtils.GetExportId(doc, collection.ElementAt(i)); string ifcguid = IfcGuid.ToIfcGuid(guid).ToString(); ; v.Components[i] = new Case.IssueTracker.Data.Component(doc.Application.VersionName, collection.ElementAt(i).ToString(), ifcguid); } } return(v); } catch (System.Exception ex1) { TaskDialog.Show("Error!", "exception: " + ex1); } return(null); }
internal static Space ToSpace(this IfcSpace space) { var transform = new Transform(); var repItems = space.Representation.Representations.SelectMany(r => r.Items); if (!repItems.Any()) { throw new Exception("The provided IfcSlab does not have any representations."); } var localPlacement = space.ObjectPlacement.ToTransform(); transform.Concatenate(localPlacement); var foundSolid = repItems.First(); var material = new Material("space", new Color(1.0f, 0.0f, 1.0f, 0.5f), 0.0f, 0.0f); if (foundSolid.GetType() == typeof(IfcExtrudedAreaSolid)) { var solid = (IfcExtrudedAreaSolid)foundSolid; var profileDef = (IfcArbitraryClosedProfileDef)solid.SweptArea; transform.Concatenate(solid.Position.ToTransform()); var pline = (IfcPolyline)profileDef.OuterCurve; var outline = pline.ToPolygon(true); var result = new Space(new Profile(outline), (IfcLengthMeasure)solid.Depth, material, transform, null, false, IfcGuid.FromIfcGUID(space.GlobalId), space.Name); return(result); } else if (foundSolid.GetType() == typeof(IfcFacetedBrep)) { var solid = (IfcFacetedBrep)foundSolid; var shell = solid.Outer; var newSolid = new Solid(); for (var i = 0; i < shell.CfsFaces.Count; i++) { var f = shell.CfsFaces[i]; foreach (var b in f.Bounds) { var loop = (IfcPolyLoop)b.Bound; var poly = loop.Polygon.ToPolygon(); newSolid.AddFace(poly); } } var result = new Space(newSolid, transform, null, false, Guid.NewGuid(), space.Name); return(result); } return(null); }
internal static Floor ToFloor(this IfcSlab slab, IEnumerable <IfcOpeningElement> openings) { var transform = new Transform(); transform.Concatenate(slab.ObjectPlacement.ToTransform()); // Console.WriteLine($"IfcSlab transform:\n{transform}\n"); // Check if the slab is contained in a building storey foreach (var cis in slab.ContainedInStructure) { transform.Concatenate(cis.RelatingStructure.ObjectPlacement.ToTransform()); } var repItems = slab.Representation.Representations.SelectMany(r => r.Items); if (!repItems.Any()) { throw new Exception("The provided IfcSlab does not have any representations."); } var solid = slab.RepresentationsOfType <IfcExtrudedAreaSolid>().FirstOrDefault(); if (solid == null) { return(null); } var outline = (Polygon)solid.SweptArea.ToCurve(); var solidTransform = solid.Position.ToTransform(); solidTransform.Concatenate(transform); var floor = new Floor(new Profile(outline), (IfcLengthMeasure)solid.Depth, solidTransform, BuiltInMaterials.Concrete, null, false, IfcGuid.FromIfcGUID(slab.GlobalId)); floor.Openings.AddRange(openings.Select(o => o.ToOpening())); return(floor); }