internal static Topography FromExisting(TopographySurface topoSurface, bool isRevitOwned) { return(new Topography(topoSurface) { IsRevitOwned = isRevitOwned }); }
/// <summary> /// Normalizes all points in the selected subregion to the average elevation of the host surface. /// </summary> /// <param name="uiDoc">The document.</param> private void NormalizeSubregionAndPoints(UIDocument uiDoc) { Document doc = uiDoc.Document; // Pick subregion TopographySurface subregion = SiteUIUtils.PickSubregion(uiDoc); TopographySurface toposurface = SiteEditingUtils.GetTopographySurfaceHost(subregion); IList <XYZ> points = SiteEditingUtils.GetPointsFromSubregionExact(subregion); // Get elevation of all points on the toposurface IList <XYZ> allPoints = toposurface.GetPoints(); double elevation = SiteEditingUtils.GetAverageElevation(allPoints); // Edit scope for all changes using (TopographyEditScope editScope = new TopographyEditScope(doc, "Edit TS")) { editScope.Start(toposurface.Id); using (Transaction t = new Transaction(doc, "Normalize terrain")) { t.Start(); // Change all points to same elevation toposurface.ChangePointsElevation(points, elevation); t.Commit(); } editScope.Commit(new TopographyEditFailuresPreprocessor()); } }
public ApplicationPlaceholderObject TopographyToNative(Topography speckleSurface) { var docObj = GetExistingElementByApplicationId(((Base)speckleSurface).applicationId); var pts = new List <XYZ>(); for (int i = 0; i < speckleSurface.displayMesh.vertices.Count; i += 3) { var point = new Geometry.Point(speckleSurface.displayMesh.vertices[i], speckleSurface.displayMesh.vertices[i + 1], speckleSurface.displayMesh.vertices[i + 2], speckleSurface.displayMesh.units); pts.Add(PointToNative(point)); } if (docObj != null) { Doc.Delete(docObj.Id); } var revitSurface = TopographySurface.Create(Doc, pts); if (speckleSurface is RevitTopography rt) { SetInstanceParameters(revitSurface, rt); } //Report.Log($"Created Topography {revitSurface.Id}"); return(new ApplicationPlaceholderObject { applicationId = ((Base)speckleSurface).applicationId, ApplicationGeneratedId = revitSurface.UniqueId, NativeObject = revitSurface }); }
public static TopographySurface ToNative(this Topography mySurface) { var(docObj, stateObj) = GetExistingElementByApplicationId(mySurface.ApplicationId, mySurface.Type); var pts = new List <XYZ>(); for (int i = 0; i < mySurface.Vertices.Count; i += 3) { pts.Add(new XYZ(mySurface.Vertices[i] * Scale, mySurface.Vertices[i + 1] * Scale, mySurface.Vertices[i + 2] * Scale)); } if (docObj != null) { Doc.Delete(docObj.Id); // TODO: Can't start a transaction here as we have started a global transaction for the creation of all objects. // TODO: Let each individual ToNative method handle its own transactions. It's a big change, so will leave for later. //var srf = (TopographySurface) docObj; //using( TopographyEditScope e = new TopographyEditScope( Doc, "Speckle Topo Edit" ) ) //{ // e.Start(srf.Id); // srf.DeletePoints( srf.GetPoints() ); // srf.AddPoints( pts ); // e.Commit( null ); //} //return srf; } return(TopographySurface.Create(Doc, pts)); }
void CommitInstance ( Document doc, IGH_DataAccess DA, int Iteration, IEnumerable <Rhino.Geometry.Point3d> points ) { var element = PreviousElement(doc, Iteration); try { if (element?.Pinned ?? true) { var scaleFactor = 1.0 / Revit.ModelUnits; if (scaleFactor != 1.0) { points = points.Select(p => p * scaleFactor); } element = TopographySurface.Create(doc, points.ToHost().ToList()); } } catch (Exception e) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message); } finally { ReplaceElement(doc, DA, Iteration, element); } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user canceled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { Document document = commandData.Application.ActiveUIDocument.Document; TrianglesData trianglesData = TrianglesData.Load(); using (Transaction tran = new Transaction(document, "CreateTrianglesTopography")) { tran.Start(); // Creates a new topography surface element from facets and adds it to the document. IList <PolymeshFacet> triangleFacets = new List <PolymeshFacet>(); foreach (List <int> facet in trianglesData.Facets) { triangleFacets.Add(new PolymeshFacet(facet[0], facet[1], facet[2])); } TopographySurface topoSurface = TopographySurface.Create(document, trianglesData.Points, triangleFacets); Parameter name = topoSurface.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.ROOM_NAME); if (name != null) { name.Set("CreateTrianglesTopography"); } tran.Commit(); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
public ApplicationPlaceholderObject TopographyToNative(Topography speckleSurface) { var docObj = GetExistingElementByApplicationId(((Base)speckleSurface).applicationId); var pts = new List <XYZ>(); for (int i = 0; i < speckleSurface.baseGeometry.vertices.Count; i += 3) { pts.Add(new XYZ( ScaleToNative(speckleSurface.baseGeometry.vertices[i], speckleSurface.baseGeometry.units), ScaleToNative(speckleSurface.baseGeometry.vertices[i + 1], speckleSurface.baseGeometry.units), ScaleToNative(speckleSurface.baseGeometry.vertices[i + 2], speckleSurface.baseGeometry.units))); } if (docObj != null) { Doc.Delete(docObj.Id); } var revitSurface = TopographySurface.Create(Doc, pts); if (speckleSurface is RevitTopography rt) { SetInstanceParameters(revitSurface, rt); } return(new ApplicationPlaceholderObject { applicationId = ((Base)speckleSurface).applicationId, ApplicationGeneratedId = revitSurface.UniqueId, NativeObject = revitSurface }); }
private Topography(IList <XYZ> points) { //Phase 1 - Check to see if the object exists and should be rebound var oldSurf = ElementBinder.GetElementFromTrace <TopographySurface>(Document); var document = DocumentManager.Instance.CurrentDBDocument; //Phase 2- There was no existing point, create one TransactionManager.Instance.EnsureInTransaction(Document); var topo = TopographySurface.Create(document, points); InternalSetTopographySurface(topo); TransactionManager.Instance.TransactionTaskDone(); if (oldSurf != null) { ElementBinder.CleanupAndSetElementForTrace(Document, this.InternalElement); } else { ElementBinder.SetElementForTrace(this.InternalElement); } }
public RevitTopography TopographyToSpeckle(TopographySurface revitTopo) { var speckleTopo = new RevitTopography(); speckleTopo.displayMesh = GetElementMesh(revitTopo); GetAllRevitParamsAndIds(speckleTopo, revitTopo); //Report.Log($"Converted Topography {revitTopo.Id}"); return(speckleTopo); }
public RevitTopography TopographyToSpeckle(TopographySurface revitTopo) { var speckleTopo = new RevitTopography(); speckleTopo.baseGeometry = GetElementMesh(revitTopo); GetAllRevitParamsAndIds(speckleTopo, revitTopo); return(speckleTopo); }
/// <summary> /// Prompts the user to pick a TopographySurface (non-subregion). /// </summary> /// <param name="uiDoc">The document.</param> /// <returns>The selected TopographySurface.</returns> public static TopographySurface PickTopographySurface(UIDocument uiDoc) { Reference toposurfRef = uiDoc.Selection.PickObject(ObjectType.Element, new TopographySurfaceSelectionFilter(), "Select topography surface"); TopographySurface toposurface = uiDoc.Document.GetElement(toposurfRef) as TopographySurface; return(toposurface); }
/// <summary> /// Prompts the user to pick a subregion. /// </summary> /// <param name="uiDoc">The document.</param> /// <returns>The selected subregion.</returns> public static TopographySurface PickSubregion(UIDocument uiDoc) { Reference subregRef = uiDoc.Selection.PickObject(ObjectType.Element, new SubRegionSelectionFilter(), "Select subregion"); TopographySurface subregion = uiDoc.Document.GetElement(subregRef) as TopographySurface; return(subregion); }
/// <summary> /// Gets the points from a rectangular outline surrounding the subregion bounding box. /// </summary> /// <param name="subregion">The subregion.</param> /// <returns>The points.</returns> public static IList <XYZ> GetPointsFromSubregionRough(TopographySurface subregion) { BoundingBoxXYZ bbox = subregion.get_BoundingBox(null); // Get toposurface points TopographySurface toposurface = GetTopographySurfaceHost(subregion); Outline outline = new Outline(bbox.Min, bbox.Max); IList <XYZ> points = toposurface.FindPoints(outline); return(points); }
void ReconstructTopographyByPoints ( Document doc, ref Autodesk.Revit.DB.Element element, IList <Rhino.Geometry.Point3d> points, [Optional] IList <Rhino.Geometry.Curve> regions ) { var scaleFactor = 1.0 / Revit.ModelUnits; if (scaleFactor != 1.0) { for (int p = 0; p < points.Count; ++p) { points[p] = points[p] * scaleFactor; } if (regions != null) { foreach (var region in regions) { region.Scale(scaleFactor); } } } //if (element is TopographySurface topography) //{ // using (var editScope = new TopographyEditScope(doc, "TopographyByPoints")) // { // editScope.Start(element.Id); // topography.DeletePoints(topography.GetPoints()); // topography.AddPoints(points.ToHost().ToList()); // foreach (var subRegionId in topography.GetHostedSubRegionIds()) // doc.Delete(subRegionId); // editScope.Commit(new Revit.FailuresPreprocessor()); // } //} //else { ReplaceElement(ref element, TopographySurface.Create(doc, points.ToHost().ToList())); } if (element != null && regions != null && regions.Count > 0) { var curveLoops = regions.Select(region => CurveLoop.Create(region.ToHost().ToList())).ToList(); SiteSubRegion.Create(doc, curveLoops, element.Id); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Topography); FilteredElementCollector collector = new FilteredElementCollector(doc); IList <Element> topoSurf = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements(); TopographySurface topo = topoSurf[0] as TopographySurface; try { GeometryElement elementGeometry = topo.get_Geometry(new Options()); TaskDialog.Show("Here", elementGeometry.LongCount().ToString()); int count = 0; foreach (GeometryObject obj in elementGeometry) { if (obj is Mesh) { Mesh topoMesh = obj as Mesh; count += topoMesh.NumTriangles; } else if (obj is Solid) { Solid sol = obj as Solid; foreach (Face face in sol.Faces) { Mesh meshFace = face.Triangulate(0.7); } } } TaskDialog.Show("There", count.ToString()); return(Result.Succeeded); } catch (Exception e) { TaskDialog.Show("There", e.Message); return(Result.Cancelled); } }
public TopographySurface Run(Document doc) { var bb0 = coordService.GetRevitCoords(osmStore.MapBottom, osmStore.MapLeft); var bb1 = coordService.GetRevitCoords(osmStore.MapTop, osmStore.MapLeft); var bb2 = coordService.GetRevitCoords(osmStore.MapTop, osmStore.MapRight); var bb3 = coordService.GetRevitCoords(osmStore.MapBottom, osmStore.MapRight); var points = new List <XYZ>() { bb0, bb1, bb2, bb3 }; var topography = TopographySurface.Create(doc, points); return(topography); }
/// <summary> /// Prompts the user to select a point, and returns a point near to the associated TopographySurface. /// </summary> /// <param name="uiDoc">The document.</param> /// <param name="toposurface">The target topography surface.</param> /// <param name="message">The selection message.</param> /// <returns>The point.</returns> public static XYZ PickPointNearToposurface(UIDocument uiDoc, TopographySurface toposurface, String message) { // Pick the point XYZ point = uiDoc.Selection.PickPoint(message); // Get the average elevation for the host topography surface double elevation = SiteEditingUtils.GetAverageElevation(toposurface.GetPoints()); // Project the point onto the Z = average elevation plane XYZ viewDirection = uiDoc.ActiveView.ViewDirection.Normalize(); double elevationDelta = (elevation - point.Z) / viewDirection.Z; point = point + viewDirection * elevationDelta; return(point); }
public DataToTopography(Document document, List <List <XYZ> > contours, double interpolationLength = 10, double proximityTolerance = 5) { Dictionary <string, XYZ> dict = new Dictionary <string, XYZ>(); int counter = 0; foreach (List <XYZ> cntr in contours) { ProcessPolygon processedContour = new ProcessPolygon(cntr); processedContour.LoadEdgeLengths(); processedContour.RemoveClosePoints(proximityTolerance); processedContour.Interpolate(interpolationLength); processedContour.LoadEdgeLengths(); foreach (XYZ item in processedContour.ProcessedPolygon) { string key = item.X.ToString() + item.Y.ToString(); try { dict.Add(key, item); } catch (Exception) { //MessageBox.Show(er.Message); counter++; } } } this.NumberOfFailedPoints = counter; List <XYZ> pnts = new List <XYZ>(); foreach (var item in dict.Keys) { XYZ pn; if (dict.TryGetValue(item, out pn)) { pnts.Add(pn); } } using (Transaction createTopography = new Transaction(document)) { createTopography.Start("Create Topography"); this.Topography = TopographySurface.Create(document, pnts); createTopography.Commit(); } }
/// <summary> /// Deletes a subregion and all topography surface points it contains. /// </summary> /// <param name="uiDoc">The document.</param> public void DeleteSubregionAndPoints(UIDocument uiDoc) { Document doc = uiDoc.Document; // Select subregion TopographySurface subregion = SiteUIUtils.PickSubregion(uiDoc); TopographySurface toposurface = SiteEditingUtils.GetTopographySurfaceHost(subregion); IList <XYZ> points = SiteEditingUtils.GetNonBoundaryPoints(subregion); // All changes are added to one transaction group - will create one undo item using (TransactionGroup deleteGroup = new TransactionGroup(doc, "Delete region")) { deleteGroup.Start(); // Edit scope to delete points- if there are points in the region if (points.Count > 0) { using (TopographyEditScope editScope = new TopographyEditScope(doc, "Edit TS")) { editScope.Start(toposurface.Id); // Transaction for point deletion using (Transaction t = new Transaction(doc, "Delete points")) { t.Start(); toposurface.DeletePoints(points); t.Commit(); } editScope.Commit(new TopographyEditFailuresPreprocessor()); } } // Transaction to delete subregion using (Transaction t2 = new Transaction(doc, "Delete subregion")) { t2.Start(); doc.Delete(subregion.Id); t2.Commit(); } deleteGroup.Assimilate(); } }
private void okButton_Click(object sender, RoutedEventArgs e) { // Get the lat and long domain latMin = Convert.ToDouble(minLatTextBox.Text); latMax = Convert.ToDouble(maxLatTextBox.Text); lonMin = Convert.ToDouble(minLonTextBox.Text); lonMax = Convert.ToDouble(maxLonTextBox.Text); LINE.Geometry.Interval2d topoDomain = new LINE.Geometry.Interval2d(lonMin, lonMax, latMin, latMax); // output parameters string filePath = fileTextBox.Text; if (filePath != null && System.IO.File.Exists(filePath)) { List <List <LINE.Geometry.Point3d> > pts = ElkLib.ProcessTopoFile(filePath, unitScale, topoDomain); List <XYZ> points = new List <XYZ>(); for (int i = 0; i < pts.Count; i++) { List <LINE.Geometry.Point3d> rowPoints = pts[i]; for (int j = 0; j < rowPoints.Count; j++) { XYZ revPoint = new XYZ(rowPoints[j].X, rowPoints[j].Y, rowPoints[j].Z); points.Add(revPoint); } } using (Transaction trans = new Transaction(doc, "Elk Create Topography")) { trans.Start(); if (points.Count > 2) { TopographySurface topo = TopographySurface.Create(doc, points); } trans.Commit(); } } Close(); }
/// <summary> /// Exports topography surface as IFC site object. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="topoSurface">The TopographySurface object.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void ExportTopographySurface(ExporterIFC exporterIFC, TopographySurface topoSurface, GeometryElement geometryElement, ProductWrapper productWrapper) { // Skip if the element is already processed and the Site has been created before if (!IFCAnyHandleUtil.IsNullOrHasNoValue(ExporterCacheManager.SiteHandle) && !IFCAnyHandleUtil.IsNullOrHasNoValue(ExporterCacheManager.ElementToHandleCache.Find(topoSurface.Id))) { return; } string ifcEnumType; IFCExportInfoPair exportType = ExporterUtil.GetExportType(exporterIFC, topoSurface, out ifcEnumType); // Check the intended IFC entity or type name is in the exclude list specified in the UI Common.Enums.IFCEntityType elementClassTypeEnum; if (Enum.TryParse <Common.Enums.IFCEntityType>(exportType.ExportInstance.ToString(), out elementClassTypeEnum) || Enum.TryParse <Common.Enums.IFCEntityType>(exportType.ExportType.ToString(), out elementClassTypeEnum)) { if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum)) { return; } if (elementClassTypeEnum == Common.Enums.IFCEntityType.IfcSite) { ExportSiteBase(exporterIFC, topoSurface.Document, topoSurface, geometryElement, productWrapper); } else { // Export Default Site first before exporting the TopographySurface as a generic element ExportDefaultSite(exporterIFC, topoSurface.Document, productWrapper); using (ProductWrapper genElemProductWrapper = ProductWrapper.Create(exporterIFC, true)) { GenericElementExporter.ExportGenericElement(exporterIFC, topoSurface, geometryElement, genElemProductWrapper, exportType); ExporterUtil.ExportRelatedProperties(exporterIFC, topoSurface, genElemProductWrapper); } productWrapper.ClearInternalHandleWrapperData(topoSurface.Document.ProjectInformation); } } else { ExportSiteBase(exporterIFC, null, topoSurface, geometryElement, productWrapper); } }
public override Value Evaluate(FSharpList <Value> args) { if (!args[0].IsList) { throw new Exception("The input is not a list of points."); } var newPts = ((Value.List)args[0]).Item.Select(x => (XYZ)((Value.Container)x).Item).ToList(); if (!newPts.Any()) { throw new Exception("There are no points in the list."); } TopographySurface topo = null; if (Elements.Any()) { if (dynUtils.TryGetElement(Elements[0], out topo)) { //In Revit 2014, a transaction edit scope is required to edit a topo surface //we can not currently handle this as it generates a transaction group //so just delete the existing surface and remake. DeleteElement(Elements[0]); topo = CreateTopographySurface(newPts); Elements[0] = topo.Id; } } else { topo = CreateTopographySurface(newPts); Elements.Add(topo.Id); } if (topo == null) { throw new ArgumentException("A topography surface could not be created."); } return(Value.NewContainer(topo)); }
/// <summary> /// Gets all non-boundary points from a TopographySurface or Subregion. /// </summary> /// <param name="toposurface">The TopographySurface or Subregion.</param> /// <returns>The non-boundary points.</returns> public static IList <XYZ> GetNonBoundaryPoints(TopographySurface toposurface) { IList <XYZ> existingPoints = toposurface.GetPoints(); // Remove boundary points from the list. IList <XYZ> boundaryPoints = toposurface.GetBoundaryPoints(); foreach (XYZ boundaryPoint in boundaryPoints) { foreach (XYZ existingPoint in existingPoints) { if (boundaryPoint.IsAlmostEqualTo(existingPoint, 1e-05)) { existingPoints.Remove(existingPoint); break; } } } return(existingPoints); }
public static Topography ToSpeckle(this TopographySurface mySurface) { var speckleTopo = new Topography(); speckleTopo.Vertices = new List <double>(); speckleTopo.Faces = new List <int>(); var geom = mySurface.get_Geometry(new Options()); foreach (var element in geom) { if (element is Mesh) { var mesh = ( Mesh )element; foreach (var vert in mesh.Vertices) { speckleTopo.Vertices.AddRange(new double[] { vert.X / Scale, vert.Y / Scale, vert.Z / Scale }); } for (int i = 0; i < mesh.NumTriangles; i++) { var triangle = mesh.get_Triangle(i); var A = triangle.get_Index(0); var B = triangle.get_Index(1); var C = triangle.get_Index(2); speckleTopo.Faces.Add(0); speckleTopo.Faces.AddRange(new int[] { ( int )A, ( int )B, ( int )C }); } } } speckleTopo.parameters = GetElementParams(mySurface); speckleTopo.typeParameters = GetElementTypeParams(mySurface); speckleTopo.ApplicationId = mySurface.UniqueId; speckleTopo.elementId = mySurface.Id.ToString(); speckleTopo.GenerateHash(); return(speckleTopo); }
void ReconstructTopographyByPoints ( Document doc, ref Autodesk.Revit.DB.Element element, IList <Rhino.Geometry.Point3d> points, [Optional] IList <Rhino.Geometry.Curve> regions ) { var scaleFactor = 1.0 / Revit.ModelUnits; var xyz = points.Select(x => x.ChangeUnits(scaleFactor).ToHost()).ToArray(); //if (element is TopographySurface topography) //{ // using (var editScope = new TopographyEditScope(doc, "TopographyByPoints")) // { // editScope.Start(element.Id); // topography.DeletePoints(topography.GetPoints()); // topography.AddPoints(points.ToHost().ToList()); // foreach (var subRegionId in topography.GetHostedSubRegionIds()) // doc.Delete(subRegionId); // editScope.Commit(new Revit.FailuresPreprocessor()); // } //} //else { ReplaceElement(ref element, TopographySurface.Create(doc, xyz)); } if (element is object && regions?.Count > 0) { var curveLoops = regions.Select(region => CurveLoop.Create(region.ChangeUnits(scaleFactor).ToHostMultiple().ToArray())).ToArray(); SiteSubRegion.Create(doc, curveLoops, element.Id); } }
/// <summary> /// Changes the elevation of all points in the subregion by a designated delta. /// </summary> /// <param name="uiDoc">The document.</param> /// <param name="elevationDelta">The change in elevation.</param> public static void ChangeSubregionAndPointsElevation(UIDocument uiDoc, double elevationDelta) { Document doc = uiDoc.Document; // Pick subregion TopographySurface subregion = PickSubregion(uiDoc); TopographySurface toposurface = SiteEditingUtils.GetTopographySurfaceHost(subregion); // Get points IList <XYZ> points = SiteEditingUtils.GetNonBoundaryPoints(subregion); if (points.Count == 0) { return; } // Change in elevation XYZ delta = elevationDelta * XYZ.BasisZ; // Edit scope for all changes using (TopographyEditScope editScope = new TopographyEditScope(doc, "Raise/lower terrain")) { editScope.Start(toposurface.Id); using (Transaction t = new Transaction(doc, "Raise/lower terrain")) { t.Start(); // Use MovePoints to change all points relative to their current position toposurface.MovePoints(points, delta); t.Commit(); } editScope.Commit(new TopographyEditFailuresPreprocessor()); } }
private void InternalSetTopographySurface(TopographySurface topoSurface) { InternalTopographySurface = topoSurface; this.InternalElementId = InternalTopographySurface.Id; this.InternalUniqueId = InternalTopographySurface.UniqueId; }
/// <summary> /// Adds a new retaining pond. /// </summary> /// <param name="uiDoc">The document.</param> /// <param name="pondRadius">The radius of the pond.</param> private void AddNewRetainingPond(UIDocument uiDoc, double pondRadius) { Document doc = uiDoc.Document; // Find toposurfaces FilteredElementCollector tsCollector = new FilteredElementCollector(doc); tsCollector.OfClass(typeof(TopographySurface)); IEnumerable <TopographySurface> tsEnumerable = tsCollector.Cast <TopographySurface>().Where <TopographySurface>(ts => !ts.IsSiteSubRegion); int count = tsEnumerable.Count <TopographySurface>(); // If there is only on surface, use it. If there is more than one, let the user select the target. TopographySurface targetSurface = null; if (count > 1) // tmp { targetSurface = SiteUIUtils.PickTopographySurface(uiDoc); } else { targetSurface = tsEnumerable.First <TopographySurface>(); } // Pick point and project to plane at toposurface average elevation XYZ point = SiteUIUtils.PickPointNearToposurface(uiDoc, targetSurface, "Pick point for center of pond."); double elevation = point.Z; // Add subregion first, so that any previously existing points can be removed to avoid distorting the new region // Find material "Water" FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(Material)); Material mat = collector.Cast <Material>().FirstOrDefault <Material>(m => m.Name == "Water"); // Create subregion curves List <Curve> curves = new List <Curve>(); curves.Add(Arc.Create(point, pondRadius, 0, Math.PI, XYZ.BasisX, XYZ.BasisY)); curves.Add(Arc.Create(point, pondRadius, Math.PI, 2 * Math.PI, XYZ.BasisX, XYZ.BasisY)); CurveLoop curveLoop = CurveLoop.Create(curves); List <CurveLoop> curveLoops = new List <CurveLoop>(); curveLoops.Add(curveLoop); // All changes are added to one transaction group - will create one undo item using (TransactionGroup addGroup = new TransactionGroup(doc, "Add pond group")) { addGroup.Start(); IList <XYZ> existingPoints = null; // Transacton for adding subregion. using (Transaction t2 = new Transaction(doc, "Add subregion")) { t2.Start(); SiteSubRegion region = SiteSubRegion.Create(doc, curveLoops, targetSurface.Id); if (mat != null) { region.TopographySurface.MaterialId = mat.Id; } t2.Commit(); // The boundary points for the subregion cannot be deleted, since they are generated // to represent the subregion boundary rather than representing real points in the host. // Get non-boundary points only to be deleted. existingPoints = SiteEditingUtils.GetNonBoundaryPoints(region.TopographySurface); // Average elevation of all points in the subregion to use as base elevation for the pond topography elevation = SiteEditingUtils.GetAverageElevation(region.TopographySurface.GetPoints()); } // Add the topography points to the target surface via edit scope. using (TopographyEditScope editScope = new TopographyEditScope(doc, "Edit TS")) { editScope.Start(targetSurface.Id); // Transaction for points changes using (Transaction t = new Transaction(doc, "Add points")) { t.Start(); // Delete existing points first to avoid conflict if (existingPoints.Count > 0) { targetSurface.DeletePoints(existingPoints); } // Generate list of points to add IList <XYZ> points = SiteEditingUtils.GeneratePondPointsSurrounding(new XYZ(point.X, point.Y, elevation - 3), pondRadius); targetSurface.AddPoints(points); t.Commit(); } editScope.Commit(new TopographyEditFailuresPreprocessor()); } addGroup.Assimilate(); } }
private TopographySurface CreateTopographySurface(List <XYZ> points) { return(TopographySurface.Create(dynRevitSettings.Doc.Document, points)); }
/// <summary> /// Exports topography surface as IFC site object. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="topoSurface">The TopographySurface object.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void ExportTopographySurface(ExporterIFC exporterIFC, TopographySurface topoSurface, GeometryElement geometryElement, ProductWrapper productWrapper) { ExportSiteBase(exporterIFC, null, topoSurface, geometryElement, productWrapper); }
/// <summary> /// Exports topography surface as IFC site object. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="topSurface"> /// The TopographySurface object. /// </param> /// <param name="geometryElement"> /// The geometry element. /// </param> /// <param name="productWrapper"> /// The IFCProductWrapper. /// </param> public static void ExportTopographySurface(ExporterIFC exporterIFC, TopographySurface topSurface, GeometryElement geometryElement, IFCProductWrapper productWrapper) { ExportSiteBase(exporterIFC, null, topSurface, geometryElement, productWrapper); PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, topSurface, productWrapper); }
internal static Topography FromExisting(TopographySurface topoSurface, bool isRevitOwned) { return new Topography(topoSurface) { IsRevitOwned = isRevitOwned }; }
private void InternalSetTopographySurface(TopographySurface topoSurface) { InternalTopographySurface = topoSurface; this.InternalElementId = InternalTopographySurface.Id; this.InternalUniqueId = InternalTopographySurface.UniqueId; }
private Topography(TopographySurface topoSurface) { InternalSetTopographySurface(topoSurface); }
private Topography(TopographySurface topoSurface) { InternalSetTopographySurface(topoSurface); }