public static void CreateDimensionElement(
            Document doc,
            Autodesk.Revit.ApplicationServices.Application app,
            Autodesk.Revit.DB.View view,
            XYZ p1,
            Reference r1,
            XYZ p2,
            Reference r2)
        {
            Autodesk.Revit.Creation.Application creApp = app.Create;
            Autodesk.Revit.Creation.Document    creDoc = doc.Create;
            ReferenceArray refArr = new ReferenceArray();

            refArr.Append(r1);
            refArr.Append(r2);

            Line        line = Line.CreateBound(p1, p2);
            Transaction t    = new Transaction(doc, "Dimension Two Walls");

            t.Start();

            Dimension dim = creDoc.NewDimension(doc.ActiveView, line, refArr);

            t.Commit();
        }