<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Create Dimension between two points in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-between-two-points/m-p/7841161#M51814</link>
    <description>&lt;P&gt;Hello! I want to create Dimension between selected points.&lt;/P&gt;&lt;P&gt;I attach my code.&lt;/P&gt;&lt;P&gt;When I do this code, I catch an exception&amp;nbsp;&lt;SPAN&gt;Autodesk.Revit.Exceptions.InvalidOperationException.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I fix it??&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;#region Namespaces
using System;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
#endregion

namespace PickObject
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{

public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;

using (Transaction tx = new Transaction(doc))
{
tx.Start("Start");

PickPoint(uidoc, app);

tx.Commit();
}

return Result.Succeeded;

}


public void PickPoint(UIDocument uidoc, Application app) {
View activeView = uidoc.ActiveView;
SketchPlane sketch = activeView.SketchPlane;
ObjectSnapTypes snapTypes = ObjectSnapTypes.Endpoints | ObjectSnapTypes.Intersections | ObjectSnapTypes.Points | ObjectSnapTypes.Perpendicular;
XYZ startPoint;
XYZ endPoint;

Plane geometryPlane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);

sketch = SketchPlane.Create(uidoc.Document, geometryPlane);

uidoc.Document.ActiveView.SketchPlane = sketch;
uidoc.Document.ActiveView.ShowActiveWorkPlane();
try
{
startPoint = uidoc.Selection.PickPoint(snapTypes, "Select start point");
endPoint = uidoc.Selection.PickPoint(snapTypes, "Select end point");

}

catch(Autodesk.Revit.Exceptions.OperationCanceledException oc)
{
Console.WriteLine(oc.Message);
return;
}
catch(Autodesk.Revit.Exceptions.InvalidOperationException oe)
{
Console.WriteLine(oe.Message);
TaskDialog.Show("Revit", "No work plane set in current view.");
return;

}
catch (Autodesk.Revit.Exceptions.ArgumentNullException n)
{
Console.WriteLine(n.Message);
return;
} //Выбор точек

double dist = startPoint.DistanceTo(endPoint);

string distance = "Distance is " + dist.ToString();
string strCoords = "Selected start point is " + startPoint.ToString() + "\nSelected end point is " + endPoint.ToString() + distance;
Line line = Line.CreateBound(startPoint, endPoint);
CreateLinearDimension(uidoc.Document, startPoint, endPoint, sketch, app);
TaskDialog.Show("Revit", strCoords);

}

&amp;nbsp;

public Dimension CreateLinearDimension(
Document doc, XYZ pt1, XYZ pt2, SketchPlane sketch, Application app)
{ 

// first create line

Line line = Line.CreateBound(pt1, pt2);
ModelCurve modelcurve = doc.Create
.NewModelCurve(line, sketch);



ReferenceArray ra = new ReferenceArray();
ra.Append(modelcurve.GeometryCurve.Reference);
return doc.Create.NewDimension(doc.ActiveView, line, ra);

}


}

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Mar 2018 14:08:19 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-03-09T14:08:19Z</dc:date>
    <item>
      <title>Create Dimension between two points</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-between-two-points/m-p/7841161#M51814</link>
      <description>&lt;P&gt;Hello! I want to create Dimension between selected points.&lt;/P&gt;&lt;P&gt;I attach my code.&lt;/P&gt;&lt;P&gt;When I do this code, I catch an exception&amp;nbsp;&lt;SPAN&gt;Autodesk.Revit.Exceptions.InvalidOperationException.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I fix it??&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;#region Namespaces
using System;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
#endregion

namespace PickObject
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{

public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;

using (Transaction tx = new Transaction(doc))
{
tx.Start("Start");

PickPoint(uidoc, app);

tx.Commit();
}

return Result.Succeeded;

}


public void PickPoint(UIDocument uidoc, Application app) {
View activeView = uidoc.ActiveView;
SketchPlane sketch = activeView.SketchPlane;
ObjectSnapTypes snapTypes = ObjectSnapTypes.Endpoints | ObjectSnapTypes.Intersections | ObjectSnapTypes.Points | ObjectSnapTypes.Perpendicular;
XYZ startPoint;
XYZ endPoint;

Plane geometryPlane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);

sketch = SketchPlane.Create(uidoc.Document, geometryPlane);

uidoc.Document.ActiveView.SketchPlane = sketch;
uidoc.Document.ActiveView.ShowActiveWorkPlane();
try
{
startPoint = uidoc.Selection.PickPoint(snapTypes, "Select start point");
endPoint = uidoc.Selection.PickPoint(snapTypes, "Select end point");

}

catch(Autodesk.Revit.Exceptions.OperationCanceledException oc)
{
Console.WriteLine(oc.Message);
return;
}
catch(Autodesk.Revit.Exceptions.InvalidOperationException oe)
{
Console.WriteLine(oe.Message);
TaskDialog.Show("Revit", "No work plane set in current view.");
return;

}
catch (Autodesk.Revit.Exceptions.ArgumentNullException n)
{
Console.WriteLine(n.Message);
return;
} //Выбор точек

double dist = startPoint.DistanceTo(endPoint);

string distance = "Distance is " + dist.ToString();
string strCoords = "Selected start point is " + startPoint.ToString() + "\nSelected end point is " + endPoint.ToString() + distance;
Line line = Line.CreateBound(startPoint, endPoint);
CreateLinearDimension(uidoc.Document, startPoint, endPoint, sketch, app);
TaskDialog.Show("Revit", strCoords);

}

&amp;nbsp;

public Dimension CreateLinearDimension(
Document doc, XYZ pt1, XYZ pt2, SketchPlane sketch, Application app)
{ 

// first create line

Line line = Line.CreateBound(pt1, pt2);
ModelCurve modelcurve = doc.Create
.NewModelCurve(line, sketch);



ReferenceArray ra = new ReferenceArray();
ra.Append(modelcurve.GeometryCurve.Reference);
return doc.Create.NewDimension(doc.ActiveView, line, ra);

}


}

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 14:08:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-between-two-points/m-p/7841161#M51814</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-09T14:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dimension between two points</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-between-two-points/m-p/7842430#M51815</link>
      <description>&lt;P&gt;You need at least two references to create a dimension i.e. two end points of line. Rather than using model line can use existing references.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In a 3D view picking points is not obvious unless the sketch plane is set to a face i.e. you set it to zero so you will not see what is being picked beneath all the other objects in the view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;       public Dimension CreateLinearDimension(
        Document doc, XYZ pt1, XYZ pt2, SketchPlane sketch, Application app)
        {

            // first create line

            Line line = Line.CreateBound(pt1, pt2);
            ModelCurve modelcurve = doc.Create
            .NewModelCurve(line, sketch);



            ReferenceArray ra = new ReferenceArray();
            ra.Append(modelcurve.GeometryCurve.GetEndPointReference(0));
            ra.Append(modelcurve.GeometryCurve.GetEndPointReference(1));
            return doc.Create.NewDimension(doc.ActiveView, line, ra);

        }&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 22:02:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-between-two-points/m-p/7842430#M51815</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2018-03-09T22:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dimension between two points</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-between-two-points/m-p/7882594#M51816</link>
      <description>&lt;P&gt;If you have more than two references in the list will the dimension create a string of dimensions to multiple points?&lt;/P&gt;</description>
      <pubDate>Sun, 25 Mar 2018 22:41:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/create-dimension-between-two-points/m-p/7882594#M51816</guid>
      <dc:creator>brady0542</dc:creator>
      <dc:date>2018-03-25T22:41:18Z</dc:date>
    </item>
  </channel>
</rss>

