Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to create dimension of a FamilyInstance (e.g. Column) in 2018 version by the code as below. The dimension cannot be seen, but can be find in Lookup. I have checked the view, all elements have been visible. I would like to ask where is the dimension? And how to achieve this?
Thanks in advance.
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Face face1 = null;
Face face2 = null;
Reference reference = uiDoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
Element elem = doc.GetElement(reference.ElementId);
Options options = new Options();
options.View = uiDoc.ActiveView;
options.ComputeReferences = true;
GeometryElement geometryElement = elem.get_Geometry(options);
foreach (GeometryObject item in geometryElement)
{
GeometryInstance geometryInstance = item as GeometryInstance;
if (geometryInstance == null)
continue;
GeometryElement instanceGeometry = geometryInstance.GetInstanceGeometry();
if (instanceGeometry == null)
continue;
foreach (var itemInstance in instanceGeometry)
{
Solid solid = itemInstance as Solid;
if (solid == null || solid.Volume.ToString() == "0")
continue;
foreach (Face faceitem in solid.Faces)
{
XYZ normal = faceitem.ComputeNormal(new UV(0, 0));
if (Math.Abs(normal.Z) > 0.1)
{
if (normal.Z > 0.1)
{
face1 = faceitem;
}
else
{
face2 = faceitem;
}
}
}
}
}
TaskDialog.Show("face1", face1.Origin.ToString());
TaskDialog.Show("face2", face2.Origin.ToString());
if (face1 != null && face2 != null)
{
Transaction tran = new Transaction(doc, "Create Dimension");
tran.Start();
XYZ p1 = face1.Evaluate(new UV(0, 0));
XYZ p2 = face2.Project(p1).XYZPoint;
p1 = new XYZ(p1.X + 10.0, p1.Y, p1.Z);
p2 = new XYZ(p2.X + 10.0, p2.Y, p2.Z);
Line line = Line.CreateBound(p1, p2);
ReferenceArray referenceArray = new ReferenceArray();
referenceArray.Append(face1.Reference);
referenceArray.Append(face2.Reference);
Dimension dimension = doc.Create.NewDimension(uiDoc.ActiveView, line, referenceArray);
tran.Commit();
TaskDialog.Show("dimension", dimension.Id.ToString());
}
return Result.Succeeded;
Solved! Go to Solution.