Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Dimension framing in SectionView

vankhoi9966
Contributor

Dimension framing in SectionView

vankhoi9966
Contributor
Contributor

Hi.

How do I have to determine the reference of the four segments that make up the beam section in the section view .....
Sorry, I'm from VietNam so not good at english, I have to use google translate.

 

Thanks all..

0 Likes
Reply
Accepted solutions (1)
1,510 Views
4 Replies
Replies (4)

aignatovich
Advisor
Advisor

Hi!

 

This is dependent on your beam family geometry and section view position relative to beam position. Anyway you need to explore your beam geometry. You should get beamFamilyInstance symbol geometry with Options.ComputeReferences == true and find appropriate faces or edges. Explore faces normal with correlation to sectionview ViewDirection, RightDirection and UpDirection.

 

There is a simpler way if you use Revit 2018 and can prepare your family with named reference planes and get references via familyInstance.GetReferenceByName method

 

You may also look at http://thebuildingcoder.typepad.com/blog/2017/09/extentelem-and-square-face-dimensioning-references....

vankhoi9966
Contributor
Contributor

Thank you very much.
My beam is rectangular. I want the dimension of the beam width and height in cross section ....
I searched for a month and still have not found ....

 

I use Revit 2018 and C # language.

0 Likes

aignatovich
Advisor
Advisor
Accepted solution

Look at this:

[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
	public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
	{
		var uiapp = commandData.Application;
		var uidoc = uiapp.ActiveUIDocument;
		var doc = uidoc.Document;

		var selectedBeam = uidoc
			.Selection
			.GetElementIds()
			.Select(doc.GetElement)
			.OfType<FamilyInstance>()
			.FirstOrDefault();

		if (selectedBeam == null)
			return Result.Cancelled;

		var beamFaces = GetSolids(selectedBeam)
			.SelectMany(x => x.Faces.OfType<PlanarFace>())
			.ToList();

		var view = doc.ActiveView;

		var leftFace = beamFaces
			.FirstOrDefault(x => x.ComputeNormal(UV.Zero).IsAlmostEqualTo(-1*view.RightDirection));

		var rightFace = beamFaces
			.FirstOrDefault(x => x.ComputeNormal(UV.Zero).IsAlmostEqualTo(view.RightDirection));

		if (leftFace == null || rightFace == null)
		{
			message = "Can't create dimension";

			return Result.Failed;
		}

		var shift = UnitUtils.ConvertToInternalUnits(500, DisplayUnitType.DUT_MILLIMETERS);

		var dimensionOrigin = selectedBeam.GetTotalTransform().Origin + shift * view.UpDirection;

		var dimensionLine = Line.CreateUnbound(dimensionOrigin, view.RightDirection);

		var dimensionReferences = new ReferenceArray();

		dimensionReferences.Append(leftFace.Reference);
		dimensionReferences.Append(rightFace.Reference);

		using (var transaction = new Transaction(doc, "create dimension"))
		{
			transaction.Start();

			doc.Create.NewDimension(view, dimensionLine, dimensionReferences);

			transaction.Commit();
		}

		return Result.Succeeded;
	}

	private IEnumerable<Solid> GetSolids(Element element)
	{
		var geometry = element.get_Geometry(new Options {ComputeReferences = true});

		return GetSolids(geometry)
			.Where(x => x.Volume > 0);
	}

	private static IEnumerable<Solid> GetSolids(IEnumerable<GeometryObject> geometryElement)
	{
		foreach (var geometry in geometryElement)
		{
			var solid = geometry as Solid;
			if (solid != null)
				yield return solid;

			var instance = geometry as GeometryInstance;
			if (instance != null)
				foreach (var instanceSolid in GetSolids(instance.GetSymbolGeometry()))
					yield return instanceSolid;

			var element = geometry as GeometryElement;
			if (element != null)
				foreach (var elementSolid in GetSolids(element))
					yield return elementSolid;
		}
	}
}

And the result for selected beam in section view:

beam.PNG

 

For height dimension you should use UpDirection instead of RightDirection

vankhoi9966
Contributor
Contributor

Yeah...

 

I am very grateful to you......

0 Likes