Draw a Detail line in a specific view(python)

Hello guys,
I’ve been searching the web for an example to draw a detail line in a specific view using python.
I am dev developing a small plugin for revit and I need to draw a detail line.
I searched revit api docs to find a method with no success.
Any examples will be appreciated. Thank you

Here’s the API documents entry:

Thank you @JacobSmall,
I tried this one but I got an error regarding the curve:

The error is that Line.ByStartPointEndPoint takes a point not XYZ!
So my question here is what is the difference between XYZ and a point? And how we can create a point?
Thank you

@ali.safiaddine you cannot use DesignScript unless you convert to a Revit curve.

or you could use the following method

In simple terms, XYZ are Revit’s version of a point, and the Point class is Dynamo’s version. Revit API commands require the Revit version, they cannot use Dynamo’s Points. And the opposite is true, Dynamo’s Line.ByStartPointEndPoint cannot use Revit’s XYZ.

For more information and how to convert from Point to XYZ and vice-versa, check out this github page: https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration and go to the GeometryObjects section.

1 Like

Use Point.ByCoordinates(0,0,0) to create the points and the rest should work.

That would get Line.ByStartPointEndPoint to work but that line will not work for the api command doc.Create.NewDetailCurve(). He would still need to convert it to Revit geometry.

Oh my bad. You are totally correct.
So either implying the conversion method ToRevitType() or as mentioned directly creating a Revit Line with Line.CreateUnbound

Thank you guys really appreciated!
But I think I am still missing something. let’s stick to the method provides by @salvatoredragotta . I tried it but I am getting an error:

Thank you @viktor_kuzev for your method but Point.Coordinates(0,0,0) is not working! I think it only works in dynamo right?

It is a method from ProtoGeometry it creates a line, but to draw it as a detail line you need to convert it to a Revit Line.


TBH it’s a bit difficult with these bits of code you’re showing? :slight_smile:

This works for me…

#thanks All!
import clr
import sys

import Revit

# Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

currentView = uidoc.ActiveView

# Import RevitAPI
import Autodesk
from Autodesk.Revit.DB import *
import System


startPt = XYZ(0, 0, 0)
#must be in the view plane, 0 for a plan
directionPt = XYZ(0, 10, 0)

#must be bound
#line = Line.CreateUnbound(startPt, directionPt)
line = Line.CreateBound(startPt, directionPt)

detailCurve = doc.Create.NewDetailCurve(currentView, line)


OUT = detailCurve,

I think you should note… we need a Bound Curve… We also need a Curve which is in the plane of the view, so z value needs to be 0 for a plan… I also don’t know what modules you’re importing, but you can see all the ones I’ve bought in (possibly too many!)… If you want to do a few detail curves you’ll need some lists and iterating…

Hope that’s useful!


Thank you @Mark.Ackerley appreciated!
I did not share my code because it is too big. I am using the exact method you mentioned above but still the same error.
Below is a part of my code :

import sys
import clr
import math
import rpw
import Autodesk
import System
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

from Autodesk.Revit.UI import *
from Autodesk.Revit.DB import *
from Autodesk.DesignScript.Geometry import *
import Autodesk.Revit.UI.Selection
from Autodesk.Revit.DB import Transaction
from rpw.ui.forms import (Console, FlexForm, Label, ComboBox, TextBox, TextBox, CheckBox, Separator, Button)
#Drafting Views

doc = revit.ActiveUIDocument.Document
current_view = uidoc.ActiveView

#Creating Drafting View:
t = Transaction(doc, “Create Drafting View”)
drafting_type_id = get_drafting_type_id()
drafting_view = ViewDrafting.Create(doc,drafting_type_id)
drafting_view.Name= Drafting_View_Name(‘Column Reinforcement’)
#Drawing a Detail line:
t = Transaction(doc,“Create a Curve”)
point2= XYZ(0,10,0)
Detail_Curve= doc.Create.NewDetailCurve(current_view,line)

It doesn’t look like my code :stuck_out_tongue:

My code works for me in a drafting view…

Perhaps you might find it easier to use my code and see if it works?

Then if it fails you could share the error?

Otherwise it’s something else?


Hope that helps,


Hello again @Mark.Ackerley :slight_smile: Thank you for your help!
Finally I found what’s wrong with my script. It is the same concept as yours but the problem was with importing some extra libraries ( The Revit Services library). So once I deleted this library it worked just fine :smiley:

Actually I don’t know what exactly might be the problem or why an extra library import could be a problem.

Anyway thank you and I’ll keep going with my script :smiley:

Hey, great work :smiley:

Hmm… I would have thought that was a conflict between the same method name in different libraries (so you could call the method explicitly to get round it)…

…but for Services, you need it… It’s how you’re able to call the document and transaction managers?

Are you sure you haven’t called it somewhere else in your code?



The lines

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

are actually redundant. from RevitServices... is an import statement, just that you are only importing a specific portion of it. So by using import RevitServices, you are importing the entirety of the RevitServices module which includes DocumentManager, TransactionManager, and everything else (which is slower) and then to import the next two lines, you have imported those things twice (which is redundant).

Basically, if you are only using the DocumentManager and TransactionManager, you do not need the line import RevitServices and it is usually bad practice to import entire modules (especially without as name) anyways.

As for why it suddenly works after removing that line, it is probably from conflicting function names but I can’t tell without seeing the error in context.


Thanks Kenny :slight_smile: makes a lot of sense.