NewDimension - dimension created but not visible
Hi,
I'm trying to create a dimension referencing lines in a family. The code below creates the dimension but it is not visible in the view. The newly created but invisible dimension is listed in RevitLookup. Any ideas why isn't shown in the project?
RVT attached with code as a document macro.
Thanks
Harry
public void holddim2()
{
Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = this.ActiveUIDocument;
Options opt = new Options();
opt.ComputeReferences = true;
opt.IncludeNonVisibleObjects = true;
Element e = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element));
List<Curve> curves = new List<Curve>();
List<Solid> solids = new List<Solid>();
AddCurvesAndSolids(e.get_Geometry(opt), out curves, out solids);
ReferenceArray ra = new ReferenceArray();
XYZ end0 = null;
XYZ end1 = null;
foreach (Curve c in curves)
{
if (c is Line)
{
Line l = c as Line;
if (Math.Abs(l.Length - 0.0123) > 0.01)
continue;
if (l.Reference == null)
continue;
ra.Append(l.Reference);
if (end0 == null)
end0 = l.GetEndPoint(1);
else if (end1 == null)
end1 = l.GetEndPoint(1);
}
}
Line line = Line.CreateBound(new XYZ(end0.X, end0.Y, 0), new XYZ(end1.X, end1.Y, 0));
using (Transaction t = new Transaction(doc, "dim"))
{
t.Start();
Dimension d = doc.Create.NewDimension(doc.ActiveView, line, ra);
TaskDialog.Show("make dim", d.Id.IntegerValue.ToString() + Environment.NewLine + ra.Size);
t.Commit();
}
}
public static void AddCurvesAndSolids(Autodesk.Revit.DB.GeometryElement geomElem, out List<Curve> curves, out List<Solid> solids)
{
curves = new List<Curve>();
solids = new List<Solid>();
foreach (Autodesk.Revit.DB.GeometryObject geomObj in geomElem)
{
Autodesk.Revit.DB.Curve curve = geomObj as Autodesk.Revit.DB.Curve;
if (null != curve)
{
curves.Add(curve);
continue;
}
Autodesk.Revit.DB.Solid solid = geomObj as Autodesk.Revit.DB.Solid;
if (null != solid)
{
if (solid.Faces.Size > 0)
{
solids.Add(solid);
continue;
}
}
//If this GeometryObject is Instance, call AddCurvesAndSolids
Autodesk.Revit.DB.GeometryInstance geomInst = geomObj as Autodesk.Revit.DB.GeometryInstance;
if (null != geomInst)
{
AddCurvesAndSolids(geomInst.GetInstanceGeometry(), out curves, out solids);
}
}
}