Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why created dimension in FamilyInstance cannot be seen, but can be find in Lookup?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
YF.Yang
637 Views, 4 Replies

Why created dimension in FamilyInstance cannot be seen, but can be find in Lookup?

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;

 

Labels (2)
4 REPLIES 4
Message 2 of 5
RPTHOMAS108
in reply to: YF.Yang

Is the active view a 3D view?

 

In the UI you can dimension in a 3D view when active work plane is set.

 

Create.NewDimension doesn't have a 'plane' argument that the Dimension would be placed on so I always wondered how that would work i.e. would it take the active work plane for a 3D view? Other 2D views have a more inherent plane with view range for the 2D annotation/detail items (although work plane for model items can still be altered for such).

 

So it may be also that view range in relation to line or references positions needs to also be checked. 

Message 3 of 5
YF.Yang
in reply to: RPTHOMAS108

Hi RPTHOMAS108,

The active view is elevation south. I have created a DetailLine at dimension's position and the DetailLine can be seen, because I also concerned the problem is the view range at first. When Checked in Lookup, the Dimension have been created and its position doesn't have any problem.

In addition, if use the code as below to create dimension of a wall, it works. So it really confused me why Create.NewDimension works well at wall, but cannot be seen at FamilyInstance.

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);

#region modified for wall
foreach (GeometryObject gObj in geometryElement)
{
    Solid solid = gObj as Solid;
    foreach (Face face in solid.Faces)
    {
        XYZ normal = face.ComputeNormal(new UV(0, 0));
        if (Math.Abs(normal.Z) > 0.1)
        {
            if (normal.Z > 0.1)
            {
                face1 = face;
            }
            else
            {
                face2 = face;
            }
        }
    }
}
#endregion

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();
}

return Result.Succeeded;
Message 4 of 5
FAIR59
in reply to: YF.Yang

For family instances there are 2 ways Revit displays geometry:

  • standard as a "copy" of the familySymbol geometry
  • as an "inplace" geometry, when the  geometry of the symbol has been altered by cutting / coping / joining.

You can check first, if the geometry is modified "in Situ" using the HasModifiedGeometry Method for FamilyInstances.

 

Remarks:

This method returns true if the geometry has been modified from post-processing activity in Revit such as joining, cutting, coping, extension, adaptive component modification, or other similar activity.
 
 

 

bool usesSymbolGeometry = (elem is FamilyInstance) && !(elem as FamilyInstance).HasModifiedGeometry;
GeometryElement instanceGeometry = usesSymbolGeometry?  geometryInstance.GetSymbolGeometry(): geometryInstance.GetInstanceGeometry() ;

 

Message 5 of 5
YF.Yang
in reply to: FAIR59

Thank you FAIR59, it works! 👍

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Rail Community