NewDimension - dimension created but not visible

boostyourbim
Advocate
Advocate

NewDimension - dimension created but not visible

boostyourbim
Advocate
Advocate

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

Reply
2,950 Views
7 Replies
Replies (7)

boostyourbim
Advocate
Advocate
0 Likes

Anonymous
Not applicable
A couple of suggestions:
Check that the dimension's referenced elements are visible in the view, if the elements are not visible in the view, the the dimension will not display.
Also check whether dimensions are set as visible in the visibility and graphics settings of the view.
0 Likes

Anonymous
Not applicable
One more thing. Are you setting ComputeReferences to true in your geometry options?
0 Likes

Anonymous
Not applicable
Nevermind i see that you are. Reading the code on my phone makes it easy to miss.
0 Likes

Anonymous
Not applicable

I met the same problem as U.

The Dimension was created with sentence "Dimension dim= document.Create.NewDimension(document.ActiveView, line, arry );", but was failed to visible in ANY Views in Revit.

image.png

The dimension could be found in the DB and located in any views, but it was invisible in any circonstance.

Have U fixed your problem?

I'm looking forward to your answer.

0 Likes

FAIR59
Advisor
Advisor

the code used by boostyourbim gets the (reference) lines  from the familySymbol.

 

For the (reference) lines of the familyinstance :

		void FamilyInstanceGetLines(Autodesk.Revit.DB.GeometryElement geomElem, out List<Curve> curves)
		{
			curves = new List<Curve>();
            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;
                }
                //If this GeometryObject is Instance, call recursive FamilyInstanceGetLines
                Autodesk.Revit.DB.GeometryInstance geomInst = geomObj as Autodesk.Revit.DB.GeometryInstance;
                if (null != geomInst)
                {
					List<Curve> resCurve = new List<Curve>();
					FamilyInstanceGetLines(geomInst.GetSymbolGeometry(), out resCurve);
                	if (resCurve!=null) curves.AddRange(resCurve);
                }
            }
		}

    

 

jeremytammik
Autodesk
Autodesk

Please refer to this other discussion on fixing a non-visible dimension after copying it from another view:

 

https://forums.autodesk.com/t5/revit-api-forum/copy-dimensions-from-a-view-to-another/m-p/7226217

 

Maybe that solution will help in your case as well?

 

Cheers,

 

Jeremy

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes