Toposolid elements represent the topography and site conditions of your model.
Let us explore on how to get the contour lines from the Toposolid using the Revit API. Toposolid contour lines can be accessed via view-specific geometry. For a quick observation from the Revit UI before even diving into coding, we can access the displaying view and use Revit Lookup to retrieve the Toposolid contour lines via Revit GeometryElement
class.
See the RevitLookup snippet below:
The snippet provides us with all the information about the Toposolid we would be interested with, together with the associated contour line. As show, you are able to drill down to the actual contour line and its properties. With the above information at hand, its straightforward to explore the same same programmatically.
We first need to define the geometry option settings since Toposolid we have realized from RevitLookup that Toposolid has a solid geometry of its own.
An important note:
Make sure geometry options View
property is set to doc.ActiveView
this ensures we can get the geometry of the centerline in the Revit active view.
Options options = app.Create.NewGeometryOptions();
options.View = doc.ActiveView;
An interesting observation has come up from Ning Zhou on the forum post: https://forums.autodesk.com/t5/revit-api-forum/how-to-get-contour-lines-from-toposolid/m-p/12315476
Using the same code approach as below, TopographySurface implementation for getting contour lines is straightforward as seen from the RevitLookUp.
However, using the same code approach for Toposolid, the contour lines are not visible as seen on the RevitLookUp.
Using options.View = doc.ActiveView;
makes the Toposolid contour lines visible in the code implementation as shown:
Acknowledgment to Ning Zhou for a working sample on how to get contour lines from Toposolid.
The sample below shows the full implementation on how to set the geometry settings, retrieving the number of contour lines from a Toposolid as well as getting GraphicsStyle
of each contour line.
using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using System.Linq; namespace GetTopoSolidContourLines { [Transaction(TransactionMode.Manual)] public class Class1 : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; //Define a reference Object to accept the pick result Reference pickedref = null; //Pick a group Selection sel = uiapp.ActiveUIDocument.Selection; pickedref = sel.PickObject(ObjectType.Element,
"Please select a toposolid"); Element elem = doc.GetElement(pickedref); if (elem != null) { Toposolid ts = elem as Toposolid; GetTopoSolidContourLines(doc, ts, app); } return Result.Succeeded; } private void GetTopoSolidContourLines(Document doc, Toposolid ts, Application app) { string lineGs = ""; Options options = app.Create.NewGeometryOptions(); options.View = doc.ActiveView; GeometryElement geomElement =ts.get_Geometry(options); TaskDialog.Show("Number of contour lines on the Toposolid is: ", geomElement.Count().ToString()); foreach(GeometryObject geometry in geomElement) { Line line = geometry as Line; if (line != null) { ElementId gsId = line.GraphicsStyleId as ElementId; GraphicsStyle gs = doc.GetElement(gsId) as GraphicsStyle; string gsName = gs.Name; lineGs += gsName + "\n"; } } TaskDialog.Show("Revit Toposolid Contour lines Graphic Styles", lineGs); ; } } }
Thanks to my colleague Jeremy for the detailed explanation on the topic in his blog: The Building Coder: https://thebuildingcoder.typepad.com/blog/2010/05/curtain-wall-geometry.html and the forum post on Revit community forum by Ning Zhou : Solved: Re: how to get contour lines from toposolid - Autodesk Community - Revit Products that has led to discussion of this topic further