- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hey all, I want to use new dimension but as I searched in forum there is a need two references to create a new dimension
but Idk what references should be used in the code, I'd appreciate give me a hint about the reference array in dimension logic.
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
namespace WallDimension
{
[Transaction(TransactionMode.Manual)]
public class Auto : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
var uiapp = commandData.Application;
var uidoc = uiapp.ActiveUIDocument;
var doc = uidoc.Document;
View vw = doc.ActiveView;
try
{
// Prompt the user to select a wall element
Reference pickedRef = uidoc.Selection.PickObject(ObjectType.Element, "Select a wall");
Element selectedElement = uidoc.Document.GetElement(pickedRef);
// Ensure the selected element has a location curve
LocationCurve locationCurve = selectedElement.Location as LocationCurve;
if (locationCurve == null)
{
message = "The selected element does not have a location curve.";
return Result.Failed;
}
Curve wallCurve = locationCurve.Curve;
XYZ startPoint = wallCurve.GetEndPoint(0);
XYZ endPoint = wallCurve.GetEndPoint(1);
Line wallLine = Line.CreateBound(startPoint, endPoint);
// Retrieve references from the wall geometry
ReferenceArray refArray = new ReferenceArray();
refArray.Append(pickedRef);
//what should add for reference
refArray.Append(pickedRef);
using (Transaction trans = new Transaction(doc, "Create Wall Dimension"))
{
trans.Start();
Dimension newDimension = doc.Create.NewDimension(vw, wallLine, refArray);
trans.Commit();
}
return Result.Succeeded;
}
catch (Exception e)
{
message = e.Message;
return Result.Failed;
}
}
}
}
Solved! Go to Solution.
Link copied