Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created October 5, 2021 04:31
Show Gist options
  • Save chuongmep/3843a0106c588e755c8c7277ecd12ae1 to your computer and use it in GitHub Desktop.
Save chuongmep/3843a0106c588e755c8c7277ecd12ae1 to your computer and use it in GitHub Desktop.
public static Dimension CreateGridDimension(View view, Grid grid1, Grid grid2)
{
Curve curve1 = grid1.Curve;
Curve curve2 = grid2.Curve;
if(curve1 == null || curve1.Reference == null || curve2 == null || curve2.Reference == null)
{
return null;
}
Line line = Line.CreateBound(curve1.GetEndPoint(0), curve2.GetEndPoint(0));
Reference re1 = new Reference(grid1);
Reference re2 = new Reference(grid2);
ReferenceArray references = new ReferenceArray();
references.Append(re1);
references.Append(re2);
return view.Document.Create.NewDimension(view, line, references);
}
@chuongmep
Copy link
Author

@chuongmep
Copy link
Author

with python

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

#Converting input from Dynamo to Revit
line = IN[0].ToRevitType()
grids = UnwrapElement(IN[1])

#Getting refrences from grid
gridRef = ReferenceArray()
opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True
opt.View = doc.ActiveView
for grid in grids:
	for obj in grid.get_Geometry(opt):
		if isinstance(obj, Line):
			gline = obj
			gridRef.Append(gline.Reference)

#Create the dimension in a transaction
TransactionManager.Instance.EnsureInTransaction(doc)

dim = doc.Create.NewDimension(doc.ActiveView, line, gridRef)

TransactionManager.Instance.TransactionTaskDone()

OUT = dim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment