public static View3D Create3DView(ViewOrientation3D orient, string name, bool isPerspective) { //http://adndevblog.typepad.com/aec/2012/05/viewplancreate-method.html IEnumerable <ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(dynRevitSettings.Doc.Document).OfClass(typeof(ViewFamilyType)) let type = elem as ViewFamilyType where type.ViewFamily == ViewFamily.ThreeDimensional select type; //create a new view View3D view = isPerspective ? View3D.CreatePerspective(dynRevitSettings.Doc.Document, viewFamilyTypes.First().Id) : View3D.CreateIsometric(dynRevitSettings.Doc.Document, viewFamilyTypes.First().Id); view.SetOrientation(orient); view.SaveOrientationAndLock(); try { //will fail if name is not unique view.Name = name; } catch { view.Name = CreateUniqueViewName(name); } return(view); }
public void ViewCreate() { Document doc = this.ActiveUIDocument.Document; // get a ViewFamilyType for a 3D View. created new instance of ViewFamilYType calle 'viewFamilyType' ViewFamilyType viewFamilyType = (from v in new FilteredElementCollector(doc). // Creates new filteredElementCollector to select all ViewFamilyTypes OfClass(typeof(ViewFamilyType)). Cast <ViewFamilyType>() where v.ViewFamily == ViewFamily.ThreeDimensional select v).First(); Categories categories = doc.Settings.Categories; Category dim = categories.get_Item(BuiltInCategory.OST_Dimensions); Category line = categories.get_Item(BuiltInCategory.OST_Lines); XYZ eye = new XYZ(100, 100, 100); XYZ forward = new XYZ(-1, 1, -1); XYZ up = new XYZ(-1, 1, 2); ViewOrientation3D vOrient = new ViewOrientation3D(eye, up, forward); using (Transaction t = new Transaction(doc, "Create view")) { t.Start(); View3D view = View3D.CreateIsometric(doc, viewFamilyType.Id); view.get_Parameter(BuiltInParameter.MODEL_GRAPHICS_STYLE) .Set(4); view.SetOrientation(vOrient); view.HideCategoryTemporary(dim.Id); view.HideCategoryTemporary(line.Id); view.SaveOrientationAndLock(); t.Commit(); } }
public override Value Evaluate(FSharpList <Value> args) { View3D view = null; var eye = (XYZ)((Value.Container)args[0]).Item; var userUp = (XYZ)((Value.Container)args[1]).Item; var direction = (XYZ)((Value.Container)args[2]).Item; var name = ((Value.String)args[3]).Item; XYZ side; if (direction.IsAlmostEqualTo(userUp) || direction.IsAlmostEqualTo(userUp.Negate())) { side = XYZ.BasisZ.CrossProduct(direction); } else { side = userUp.CrossProduct(direction); } XYZ up = side.CrossProduct(direction); //need to reverse the up direction to get the //proper orientation - there might be a better way to handle this var orient = new ViewOrientation3D(eye, -up, direction); if (this.Elements.Any()) { Element e; if (dynUtils.TryGetElement(this.Elements[0], typeof(View3D), out e)) { view = (View3D)e; if (!view.ViewDirection.IsAlmostEqualTo(direction)) { view.Unlock(); view.SetOrientation(orient); view.SaveOrientationAndLock(); } if (view.Name != null && view.Name != name) { view.Name = CreateUniqueViewName(name); } } else { //create a new view view = dynViewBase.Create3DView(orient, name, false); Elements[0] = view.Id; } } else { view = Create3DView(orient, name, false); Elements.Add(view.Id); } return(Value.NewContainer(view)); }
public override Value Evaluate(FSharpList <Value> args) { View3D view = null; var eye = (XYZ)((Value.Container)args[0]).Item; var target = (XYZ)((Value.Container)args[1]).Item; var name = ((Value.String)args[2]).Item; var extents = ((Value.Container)args[3]).Item; var isolate = Convert.ToBoolean(((Value.Number)args[4]).Item); var globalUp = XYZ.BasisZ; var direction = target.Subtract(eye); var up = direction.CrossProduct(globalUp).CrossProduct(direction); var orient = new ViewOrientation3D(eye, up, direction); if (this.Elements.Any()) { if (dynUtils.TryGetElement(this.Elements[0], out view)) { if (!view.ViewDirection.IsAlmostEqualTo(direction) || !view.Origin.IsAlmostEqualTo(eye)) { view.Unlock(); view.SetOrientation(orient); view.SaveOrientationAndLock(); } if (!view.Name.Equals(name)) { view.Name = ViewBase.CreateUniqueViewName(name); } } else { //create a new view view = ViewBase.Create3DView(orient, name, isPerspective); Elements[0] = view.Id; } } else { view = Create3DView(orient, name, isPerspective); Elements.Add(view.Id); } var fec = dynRevitUtils.SetupFilters(dynRevitSettings.Doc.Document); if (isolate) { view.CropBoxActive = true; var element = extents as Element; if (element != null) { var e = element; var all = fec.ToElements(); var toHide = fec.ToElements().Where(x => !x.IsHidden(view) && x.CanBeHidden(view) && x.Id != e.Id).Select(x => x.Id).ToList(); if (toHide.Count > 0) { view.HideElements(toHide); } dynRevitSettings.Doc.Document.Regenerate(); Debug.WriteLine(string.Format("Eye:{0},Origin{1}, BBox_Origin{2}, Element{3}", eye.ToString(), view.Origin.ToString(), view.CropBox.Transform.Origin.ToString(), (element.Location as LocationPoint).Point.ToString())); //http://wikihelp.autodesk.com/Revit/fra/2013/Help/0000-API_Deve0/0039-Basic_In39/0067-Views67/0069-The_View69 if (isPerspective) { var farClip = view.get_Parameter("Far Clip Active"); farClip.Set(0); } else { //http://adndevblog.typepad.com/aec/2012/05/set-crop-box-of-3d-view-that-exactly-fits-an-element.html var pts = new List <XYZ>(); ParseElementGeometry(element, pts); var bounding = view.CropBox; var transInverse = bounding.Transform.Inverse; var transPts = pts.Select(transInverse.OfPoint).ToList(); //ingore the Z coordindates and find //the max X ,Y and Min X, Y in 3d view. double dMaxX = 0, dMaxY = 0, dMinX = 0, dMinY = 0; //geom.XYZ ptMaxX, ptMaxY, ptMinX,ptMInY; //coorresponding point. bool bFirstPt = true; foreach (var pt1 in transPts) { if (true == bFirstPt) { dMaxX = pt1.X; dMaxY = pt1.Y; dMinX = pt1.X; dMinY = pt1.Y; bFirstPt = false; } else { if (dMaxX < pt1.X) { dMaxX = pt1.X; } if (dMaxY < pt1.Y) { dMaxY = pt1.Y; } if (dMinX > pt1.X) { dMinX = pt1.X; } if (dMinY > pt1.Y) { dMinY = pt1.Y; } } } bounding.Max = new XYZ(dMaxX, dMaxY, bounding.Max.Z); bounding.Min = new XYZ(dMinX, dMinY, bounding.Min.Z); view.CropBox = bounding; } } else { var xyz = extents as BoundingBoxXYZ; if (xyz != null) { view.CropBox = xyz; } } view.CropBoxVisible = false; } else { view.UnhideElements(fec.ToElementIds()); view.CropBoxActive = false; } return(Value.NewContainer(view)); }