Fail to get reference for grid

Fail to get reference for grid

Anonymous
Not applicable
1,902 Views
5 Replies
Message 1 of 6

Fail to get reference for grid

Anonymous
Not applicable

Hi.

I want to create dimensions between grids.

I tried two ways but it fails.

 

the first is

 

List<Curve> gridCurves = new List<Curve>();
var grids = new FilteredElementCollector(doc).OfClass(typeof(Grid)).Cast<Grid>();
foreach (var grid in grids)
{
    var curves = grid.GetCurvesInView(DatumExtentType.ViewSpecific, view); // grid.GetCurvesInView(DatumExtentType.Model, view);
    if (curves.Count() > 0)
    {
        if (curves.first().Reference != null) gridCurves.Add(curves.First());
    }
}

 

 

and the second is

 

var options = new Options();
options.ComputeReferences = true;
options.IncludeNonVisibleObjects = true;
options.View = view;

List<Curve> gridCurves = new List<Curve>();
var grids = new FilteredElementCollector(doc).OfClass(typeof(Grid)).Cast<Grid>();
foreach (var grid in grids)
{
    foreach (GeometryObject geoObj in grid.get_Geometry(options))
    {
        if (geoObj is Line)
        {
            var line = geoObj as Line;
            if (line.Reference != null) gridCurves.Add(line);
        }
    }
}

 

oh, and I tried grid.Curve.GetEndPointReference(0);

 

 

I can't get the reference for the grid.

null reference error when creating dimension.

 

I need your help!

thank you 🙂

0 Likes
Accepted solutions (1)
1,903 Views
5 Replies
Replies (5)
Message 2 of 6

thannaingoo.api
Advocate
Advocate

Hi, 

 

I am not sure this is what you need but you may try this.

 

Thanks,

Naing Oo

 

 

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;

 

XYZ start = null;
XYZ end = null;

 

View view = doc.ActiveView;

Autodesk.Revit.DB.ViewPlan viewPlan = null;
viewPlan = doc.ActiveView as ViewPlan;

 

if (viewPlan == null)
{
TaskDialog.Show("Revit", "Go to Plan View!");
return Result.Cancelled;
}

 

FilteredElementCollector col = new FilteredElementCollector(doc, view.Id).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Grids);
IList<Element> elementList = col.ToElements();

foreach (Element elmt in elementList)
{
Grid grid = elmt as Grid;
IList<Curve> gridCurves = grid.GetCurvesInView(DatumExtentType.Model, view);

foreach (Curve c in gridCurves)
{
start = c.GetEndPoint(0);
end = c.GetEndPoint(1);

TaskDialog.Show("Revit", "Grid StartPoint - " + start.ToString() + "\n" + "Grid EndPoint - " + end.ToString());
}
}

return Result.Succeeded;
}

0 Likes
Message 3 of 6

aignatovich
Advisor
Advisor
Accepted solution

Hi!

 

It is enough to reference entire grid for dimensioning purposes.

 

Just create:

var reference = new Reference(gridElem);
Message 4 of 6

Anonymous
Not applicable

@thannaingoo.api

thank you for your reply!

but I was looking for a way to get grid reference.

0 Likes
Message 5 of 6

Anonymous
Not applicable

@aignatovich

so simple!

it works.. thank you so much!!! Smiley LOL

0 Likes
Message 6 of 6

Arciviz
Advocate
Advocate

Working fine for me Also

0 Likes