I’m resolved the first problem with view3D here, for the second I don’t have any reason, why I need to do that with zoom in background. you can reference. kudo for @c.poupin with sample code.
public static void ZoomToLinkElement(List<Revit.Elements.Element> elements,bool isCropView=false)
{
if(elements==null) throw new ArgumentNullException($"{nameof(elements)} is null");
UIDocument uidoc = DocumentManager.Instance.CurrentUIDocument;
ElementId viewId = uidoc.ActiveView.Id;
List<UIView> uiViews = uidoc.GetOpenUIViews().Where(x => x.ViewId == viewId).ToList();
if (uiViews.Count == 0) return;
UIView uiView = uiViews.First();
BoundingBoxXYZ boundingBoxXYZ = new BoundingBoxXYZ();
boundingBoxXYZ.Min = new XYZ(double.MaxValue, double.MaxValue, double.MaxValue);
boundingBoxXYZ.Max = new XYZ(double.MinValue, double.MinValue, double.MinValue);
foreach (var element in elements)
{
BoundingBoxXYZ boundingBox = element.InternalElement.get_BoundingBox(uidoc.ActiveView);
if (boundingBox == null) continue;
boundingBoxXYZ.Min = new XYZ(Math.Min(boundingBoxXYZ.Min.X, boundingBox.Min.X),
Math.Min(boundingBoxXYZ.Min.Y, boundingBox.Min.Y),
Math.Min(boundingBoxXYZ.Min.Z, boundingBox.Min.Z));
boundingBoxXYZ.Max = new XYZ(Math.Max(boundingBoxXYZ.Max.X, boundingBox.Max.X),
Math.Max(boundingBoxXYZ.Max.Y, boundingBox.Max.Y),
This file has been truncated. show original
3 Likes