'Invalid direction of dimension' error when trying to create vertical dimension

dem1st
Enthusiast
Enthusiast

'Invalid direction of dimension' error when trying to create vertical dimension

dem1st
Enthusiast
Enthusiast

References get created fine (Z axis) but nevertheless when the program hits dimension creation it throws an error 'The direction of dimension is invalid.'

 

 

 

            XYZ p1z = new XYZ(-5, 5, 5);
            XYZ p2z = new XYZ(5, 5, 5);
            XYZ p3z = new XYZ(-5, 5, 10);
            XYZ p4z = new XYZ(5, 5, 10);
			
	    XYZ cutVecZ = new XYZ(0, 1, 0);

	using (Transaction t = new Transaction(doc, "Refplanes"))
            {
                    t.Start();                    
                    refplane1 = doc.FamilyCreate.NewReferencePlane(p1z, p2z, cutVecZ, uidoc.ActiveGraphicalView);
                    refplane2 = doc.FamilyCreate.NewReferencePlane(p3z, p4z, cutVecZ, uidoc.ActiveGraphicalView);
                    t.Commit();   
            }
		Line lin = Line.CreateBound(p1z, p3z);
                ReferenceArray ra = new ReferenceArray();
                ra.Append(refplane1.GetReference());
                ra.Append(refplane2.GetReference());

		using (Transaction t = new Transaction(doc, "Dimension"))
            {                
                t.Start();               
                var dim3 = doc.FamilyCreate.NewLinearDimension(uidoc.ActiveGraphicalView, lin, ra);
                t.Commit();
            }

 

 

 

dem1st_0-1637234278414.png

 

0 Likes
Reply
Accepted solutions (1)
1,272 Views
2 Replies
Replies (2)

dem1st
Enthusiast
Enthusiast

I guess in transaction I should set the active view to a different one, right? Is that the problem?

0 Likes

dem1st
Enthusiast
Enthusiast
Accepted solution

For anyone who got stuck with the same issue the solution is to store reference to the view you want your dimension to be on and use it when creating a new dimemnsion NewLinearDimension(pView, lin, ra)

 

Element FindElement(Autodesk.Revit.DB.Document docum, Type targetType, string targetName)
{
return new FilteredElementCollector(doc).OfClass(targetType).First<Element>(e => e.Name.Equals(targetName));
}



View pView = FindElement(doc, typeof(View), "Front") as View;



using (Transaction t = new Transaction(doc, "Dimension"))
{
t.Start();
var dim = doc.FamilyCreate.NewLinearDimension(pView, lin, ra);
t.Commit();
}

 

Thanks to Jeremy and XtraLabs!

0 Likes