//
// (C) Copyright 2003-2023 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
namespace Revit.SDK.Samples.WindowWizard.CS
{
///
/// The class allows users to create dimension using Document.FamilyCreate.NewDimension() function
///
class CreateDimension
{
#region Class Memeber Variables
///
/// store the document
///
Document m_document;
///
/// store the application
///
Application m_application;
#endregion
///
/// constructor of CreateDimension class
///
/// the application
/// the document
public CreateDimension(Application app, Document doc)
{
m_application = app;
m_document = doc;
}
#region Class Implementation
///
/// This method is used to create dimension among three reference planes
///
/// the view
/// the first reference plane
/// the second reference plane
/// the middle reference plane
/// the new dimension
public Dimension AddDimension(View view, ReferencePlane refPlane1, ReferencePlane refPlane2, ReferencePlane refPlane)
{
Dimension dim;
Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ();
Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ();
Line line;
Reference ref1;
Reference ref2;
Reference ref3;
ReferenceArray refArray = new ReferenceArray();
ref1 = refPlane1.GetReference();
ref2 = refPlane2.GetReference();
ref3 = refPlane.GetReference();
startPoint = refPlane1.FreeEnd;
endPoint = refPlane2.FreeEnd;
line = Line.CreateBound(startPoint, endPoint);
if (null != ref1 && null != ref2 && null != ref3)
{
refArray.Append(ref1);
refArray.Append(ref3);
refArray.Append(ref2);
}
SubTransaction subTransaction = new SubTransaction(m_document);
subTransaction.Start();
dim = m_document.FamilyCreate.NewDimension(view, line, refArray);
subTransaction.Commit();
return dim;
}
///
/// The method is used to create dimension between referenceplane and face
///
/// the view in which the dimension is created
/// the reference plane
/// the face
/// the new dimension
public Dimension AddDimension(View view, ReferencePlane refPlane, Face face)
{
Dimension dim;
Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ();
Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ();
Line line;
Reference ref1;
Reference ref2;
ReferenceArray refArray = new ReferenceArray();
ref1 = refPlane.GetReference();
PlanarFace pFace = face as PlanarFace;
ref2 = pFace.Reference;
if (null != ref1 && null != ref2)
{
refArray.Append(ref1);
refArray.Append(ref2);
}
startPoint = refPlane.FreeEnd;
endPoint = new Autodesk.Revit.DB.XYZ(startPoint.X, pFace.Origin.Y, startPoint.Z);
SubTransaction subTransaction = new SubTransaction(m_document);
subTransaction.Start();
line = Line.CreateBound(startPoint, endPoint);
dim = m_document.FamilyCreate.NewDimension(view, line, refArray);
subTransaction.Commit();
return dim;
}
///
/// The method is used to create dimension between two faces
///
/// the view
/// the first face
/// the second face
/// the new dimension
public Dimension AddDimension(View view, Face face1, Face face2)
{
Dimension dim;
Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ();
Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ();
Line line;
Reference ref1;
Reference ref2;
ReferenceArray refArray = new ReferenceArray();
PlanarFace pFace1 = face1 as PlanarFace;
ref1 = pFace1.Reference;
PlanarFace pFace2 = face2 as PlanarFace;
ref2 = pFace2.Reference;
if (null != ref1 && null != ref2)
{
refArray.Append(ref1);
refArray.Append(ref2);
}
startPoint = pFace1.Origin;
endPoint = new Autodesk.Revit.DB.XYZ(startPoint.X, pFace2.Origin.Y, startPoint.Z);
SubTransaction subTransaction = new SubTransaction(m_document);
subTransaction.Start();
line = Line.CreateBound(startPoint, endPoint);
dim = m_document.FamilyCreate.NewDimension(view, line, refArray);
subTransaction.Commit();
return dim;
}
#endregion
}
}