Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dimension framing in SectionView

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
vankhoi9966
1452 Views, 4 Replies

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

Dimension framing in SectionView

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..

4 REPLIES 4
Message 2 of 5
aignatovich
in reply to: vankhoi9966

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....

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....

Message 3 of 5
vankhoi9966
in reply to: aignatovich

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

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.

Message 4 of 5
aignatovich
in reply to: vankhoi9966

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

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

Message 5 of 5
vankhoi9966
in reply to: aignatovich

vankhoi9966
Contributor
Contributor

Yeah...

 

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

0 Likes

Yeah...

 

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report