I have lost several hours today, about 8 trying to filter through all the out of date posts.
I am happy that I have found this one that gives an answer, but unfortunately links back to a post where it doesnt actually show the final solution.
In my application, written in IronPython and using pyRevit. I am building a simple control that allows grids to be generated and now adds the grid dimensions between them.
While I create the grids I store them in a python list. I pass a 'StartGrid' to give it the first 1 or A and after that let the auto numbering take over.
Xgrids = []
Ygrids = []
def DrawGrid(document, PointFrom, PointTo, StartGrid ):
# create model line
l = DB.Line.CreateBound(PointFrom, PointTo)
t.Start()
G = DB.Grid.Create(document,l)
G.ShowBubbleInView(DB.DatumEnds.End0, document.ActiveView)
if StartGrid == 1:
G.Name = str(StartGrid)
Xgrids.append(G)
elif StartGrid == 'A':
G.Name = StartGrid
Ygrids.append(G)
elif StartGrid == 'auto':
if G.Name.isdigit():
Xgrids.append(G)
elif not G.Name.isdigit():
Ygrids.append(G)
t.Commit()
Currently I then loop through the lists and create the grid dimensions. At the start, I also get a filter of the document views so that I can apply the dimensions to all the plan views at the same time.
I also have collected the start and end of the grid so that I can place the dimensions at each end of the grid.
def DimensionGrids(document):
FEC = DB.FilteredElementCollector(document)
RA = DB.ReferenceArray()
dd = FEC.OfClass(DB.ViewPlan)
dimLocPt0 = []
dimLocPt1 = []
t.Start()
for p in dd:
if not p.IsTemplate:
for g in Xgrids:
RA.Append(DB.Reference(g))
if dimLocPt0.Count < 2:
if dimLocPt0.Count == 0:
dimLocPt0.append(g.Curve.GetEndPoint(0))
else:
g.Curve.MakeUnbound()
dimLocPt0.append(g.Curve.Project(dimLocPt0[0]).XYZPoint)
if dimLocPt1.Count < 2:
if dimLocPt1.Count == 0:
dimLocPt1.append(g.Curve.GetEndPoint(1))
else:
g.Curve.MakeUnbound()
dimLocPt1.append(g.Curve.Project(dimLocPt1[0]).XYZPoint)
# p is a plan view
Line0 = DB.Line.CreateBound(dimLocPt0[0],dimLocPt0[1])
Line1 = DB.Line.CreateBound(dimLocPt1[0],dimLocPt1[1])
document.Create.NewDimension(p, Line0, RA)
document.Create.NewDimension(p, Line1, RA)
t.Commit()
I hope that this helps someone else not lose a days worth of time.