Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 67020

Re: Create a view camera or 3d view with boundering

$
0
0

Hi!

Try this code:

public static View Create3DView(Room room)
{
	var document = room.Document;

	using (var transaction = new Transaction(document, "create 3d view"))
	{
		transaction.Start();

		var view = View3D.CreatePerspective(document, document.GetDefaultElementTypeId(ElementTypeGroup.ViewType3D));
		
		view.SetOrientation(GetOrientation(room));

		transaction.Commit();

		return view;
	}
}

private static ViewOrientation3D GetOrientation(Room room)
{
	var calculator = new SpatialElementGeometryCalculator(room.Document, new SpatialElementBoundaryOptions
		{
			SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish
		});

	// find first vertical boundary face
	var face = calculator
		.CalculateSpatialElementGeometry(room)
		.GetGeometry()
		.Faces
		.Cast<Face>()
		.First(x => Math.Abs(x.ComputeNormal(UV.Zero).DotProduct(XYZ.BasisZ)) < 1E-5);

	var faceBox = face.GetBoundingBox();

	var faceCenter = face.Evaluate(0.5*(faceBox.Min + faceBox.Max));

	return new ViewOrientation3D(faceCenter, XYZ.BasisZ, -1*face.ComputeNormal(UV.Zero));
}

Also note: there were some problems with 3d view creation on some releases of Revit 2016 and 2017

The result for the kitchen in the rac_basic_sample_project.rvt

view3d generation.PNG

 


Viewing all articles
Browse latest Browse all 67020

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>