The python code is taken from this discussion: Quick Dimension Question which refers back to this post on the Revit API forum https://forums.autodesk.com/t5/revit-api-forum/how-to-revit-2016-api-create-dimension-between-grid/td-p/5971147
A clear description of the NewDimension method can be found in the revit api docs website along with an example. http://www.revitapidocs.com/2018/47b3977d-da93-e1a4-8bfa-f23a29e5c4c1.htm
The line in IN[0] is where the dimension will be drawn (I used the lines end points + 500mm offset) while the lines in IN[1] are the dimension references.
In order to convert a line (or a grid line) to a reference we need to extract its geometry first (line 27) and then store its reference in a ReferenceArray() (line 18).
The NewDimension method is going to change the Revit project so it must be included in a Transaction.
Please note the code will work also with structural framings as you can extract a Reference from them too.