Skip to content

Commit 529ad29

Browse files
authored
Create Snippets_DimensionGrids
1 parent 65d267b commit 529ad29

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Create a dimension line between all chosen grid. The gird lines need to be parallel to each other,
3+
which is the case most of the time but not always.
4+
TESTED REVIT API: 2018
5+
The snippet can be used as is in a Revit Application Macro for test purposes
6+
Author: Deyan Nenov | github.com/ArchilizerLtd | www.archilizer.com
7+
This file is shared on www.revitapidocs.com
8+
For more information visit http://github.com/gtalarico/revitapidocs
9+
License: http://github.com/gtalarico/revitapidocs/blob/master/LICENSE.md
10+
*/
11+
12+
public void DimGrids()
13+
{
14+
UIDocument uidoc = this.ActiveUIDocument;
15+
Document doc = uidoc.Document;
16+
17+
// Pick all the grid lines you want to dimension to
18+
GridSelectionFilter filter = new ThisApplication.GridSelectionFilter(doc);
19+
IList<Element> grids = uidoc.Selection.PickElementsByRectangle(filter, "Pick Grid Lines");
20+
21+
ReferenceArray refArray = new ReferenceArray();
22+
XYZ dir = null;
23+
24+
foreach(Element el in grids)
25+
{
26+
Grid gr = el as Grid;
27+
28+
if(gr == null) continue;
29+
if(dir == null)
30+
{
31+
Curve crv = gr.Curve;
32+
dir = new XYZ(0,0,1).CrossProduct((crv.GetEndPoint(0) - crv.GetEndPoint(1))); // Get the direction of the gridline
33+
}
34+
35+
Reference gridRef = null;
36+
37+
// Options to extract the reference geometry needed for the NewDimension method
38+
Options opt = new Options();
39+
opt.ComputeReferences = true;
40+
opt.IncludeNonVisibleObjects = true;
41+
opt.View = doc.ActiveView;
42+
foreach (GeometryObject obj in gr.get_Geometry(opt))
43+
{
44+
if (obj is Line)
45+
{
46+
Line l = obj as Line;
47+
gridRef = l.Reference;
48+
refArray.Append(gridRef); // Append to the list of all reference lines
49+
}
50+
}
51+
}
52+
53+
XYZ pickPoint = uidoc.Selection.PickPoint(); // Pick a placement point for the dimension line
54+
Line line = Line.CreateBound(pickPoint, pickPoint + dir * 100); // Creates the line to be used for the dimension line
55+
56+
using(Transaction t = new Transaction(doc, "Make Dim"))
57+
{
58+
t.Start();
59+
if( !doc.IsFamilyDocument )
60+
{
61+
doc.Create.NewDimension(
62+
doc.ActiveView, line, refArray);
63+
}
64+
t.Commit();
65+
}
66+
}

0 commit comments

Comments
 (0)