Saturday, February 12, 2011

[Revit API] – How to draw a detail line on a view

I got asked a question similar to this so thought I’d post it up. To draw a detail line on a view, from one point to another, you first need to create a ‘Line’ and then a ‘DetailCurve’.
This may be a little confusing, but a ‘Line’ is not the actual end result, it’s a geometry object that represents where the line will go. To actually draw the line you need to create a DetailCurve, which is the actual Detail Line.
Here’s the code that I’m talking about:
//Create the Points
double x1 = 5.0;
double y1 = 5.0;
double z = 0.0;
double x2 = 117.0;
double y2 = 115.0;
XYZ point1 = app.Application.Create.NewXYZ(x1, y1, z);
XYZ point2 = app.Application.Create.NewXYZ(x2, y2, z);
//Create line
Line line = app.Application.Create.NewLineBound(point1, point2);
DetailCurve detailCurve = doc.Create.NewDetailCurve(doc.ActiveView, line);
TaskDialog.Show("Done", "Line Created");
First off, we are setting up the XYZ for each point that we are going to draw between. These are points in the model. Then we use the NewLineBound method to create a bound line in space between point1 and point2. If you just stopped here, you would see nothing in your model. To actually draw the Detail Line you use the NewDetailCurve method to specify which view you want to draw the line on, and the line that represents it’s geometry.
To run the code you’ll need to be in a transaction (or use Automatic transaction mode), and need to initialize the app and doc variables as you normally would. When you run the tool, the final result is this:
A simple line drawn on the page.


Anonymous said...

Thank you!

Anonymous said...

Hey thanks, it help me a lot!

Im wondering if you know how to draw a point in Revit, cause I try but i didnt find any class like "NewDetailPoint"

thanks again!