void UpdateReferencingSheet( ViewSection selectedViewport) { BuiltInParameter bip = BuiltInParameter.VIEW_DISCIPLINE; Parameter discipline = selectedViewport.get_Parameter( bip ); int disciplineNo = discipline.AsInteger(); Document doc = selectedViewport.Document; Transaction transaction = new Transaction( doc ); if( TransactionStatus.Started == transaction.Start( "Updating the model" ) ) { //switch( disciplineNo ) //{ // case 1: // discipline.Set( 2 ); // break; // default: // discipline.Set( 1 ); // break; //} //discipline.Set( disciplineNo ); discipline.Set( 1 == disciplineNo ? 2 : 1 ); transaction.Commit(); } }
public void CreateFilledRegion(Document doc, ViewSection intElev, BoundingBoxXYZ roombb) { List <CurveLoop> filledRegionBoundaries = FilledRegionBoundary(intElev); ElementId filledRegionTypeId = new FilteredElementCollector(doc) .OfClass(typeof(FilledRegionType)) .Select(f => f as FilledRegionType) .Where(f => f != null && f.BackgroundPatternColor.Red == 255 && f.BackgroundPatternColor.Blue == 255 && f.BackgroundPatternColor.Green == 255 && f.IsMasking == true) .Select(f => f.Id) .FirstOrDefault(); FilledRegion region = FilledRegion.Create(doc, filledRegionTypeId, intElev.Id, filledRegionBoundaries); // set inside and outside lineweight Element lineStyle = FilledRegion.GetValidLineStyleIdsForFilledRegion(doc) .Select(id => doc.GetElement(id)) .Where(el => el.Name.Contains("05") && el.Name.ToLower().Contains("solid")) .FirstOrDefault(); region.SetLineStyleId(lineStyle.Id); }
/// <summary> /// 选择立面 /// </summary> /// <param name="name"></param> /// <returns></returns> public ViewSection SellectViewSection(string name) { List <ViewSection> viewSections = CollectViewSections(); ViewSection viewSection = viewSections.Where(x => x.Name.Contains(name)).ToList()[0]; return(viewSection); }
public Room GetElevRoom(ViewSection ie, List <Room> phasedRooms, Document doc) { XYZ cbmin = ie.CropBox.get_Bounds(0); XYZ cbmax = ie.CropBox.get_Bounds(1); XYZ viewPoint = new XYZ( (cbmax.X + cbmin.X) / 2, 1, cbmax.Z ); double[][] transform = Matrix.transform2matrix(ie.CropBox.Transform); Matrix.print("VS Transform", transform, Debug); double[] viewPointVector = Matrix.xyz2matrix(viewPoint); double[][] transformInv = Matrix.invert(transform); double[] viewPointVectorT = Matrix.dot(transformInv, viewPointVector); XYZ viewPointT = Matrix.matrix2xyz(viewPointVectorT); XYZ offsetOrigin = new XYZ ( viewPointT.X + ie.Origin.X, viewPointT.Y + ie.Origin.Y, 1 ); foreach (Room r in phasedRooms) { if (r.IsPointInRoom(offsetOrigin)) { return(r); } } throw new Exception("No room located at point" + offsetOrigin); }
public Tuple <XYZ, XYZ> GetElevEndpoints(ViewSection view) { XYZ vpMin = view.CropBox.Min; XYZ vpMax = view.CropBox.Max; Debug("vpMin " + vpMin); Debug("vpMax " + vpMax); XYZ endpoint1 = new XYZ( vpMin.X, vpMin.Y, vpMax.Z); XYZ endpoint2 = new XYZ( vpMax.X, vpMin.Y, vpMax.Z); Tuple <XYZ, XYZ> viewEndpoints = new Tuple <XYZ, XYZ>(endpoint1, endpoint2); Debug("endpoint1 " + endpoint1); Debug("endpoint2 " + endpoint2); return(viewEndpoints); }
public XYZ GetViewSectionNormal(Document doc, ElevationMarker marker) { ViewSection elevViewSection = (ViewSection)doc.GetElement(marker.GetViewId(0)); double[][] transform = Matrix.transform2matrix(elevViewSection.CropBox.Transform); XYZ cbMinT = Matrix.matrix2xyz(Matrix.dot(transform, Matrix.xyz2matrix(elevViewSection.CropBox.Min))); XYZ cbMaxT = Matrix.matrix2xyz(Matrix.dot(transform, Matrix.xyz2matrix(elevViewSection.CropBox.Max))); XYZ elevViewSectionCoordEndPoint1 = new XYZ( cbMinT.X, cbMinT.Y, cbMaxT.Z); XYZ elevViewSectionCoordEndPoint2 = new XYZ( cbMinT.X, cbMinT.Y, cbMinT.Z); double[][] inverse = Matrix.invert(transform); XYZ cbEP1 = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(elevViewSectionCoordEndPoint1))); XYZ cbEP2 = Matrix.matrix2xyz(Matrix.dot(inverse, Matrix.xyz2matrix(elevViewSectionCoordEndPoint2))); // these points are already in the model coordiante system so no need to translate XYZ elevViewSectionNormal = cbEP2.Subtract(cbEP1); return(elevViewSectionNormal); }
private int CalculateVerticalTranslation(NSNotification notification, out bool shouldHideTopSection) { nfloat screenHeight = UIScreen.MainScreen.Bounds.Height; nfloat navigationBarHeight = this.GetNavigationBarHeight(); NSValue keyboardFrame = (NSValue)notification.UserInfo.ObjectForKey(UIKeyboard.FrameEndUserInfoKey); nfloat keyboardHeight = keyboardFrame.CGRectValue.Height; nfloat availableSpace = screenHeight - keyboardHeight - navigationBarHeight - this.bottomPadding; nfloat fieldGroupHeight = this.GetCombinedSectionHeight(); ViewSection topMostVisibleSection = this.topSection; if (fieldGroupHeight > availableSpace) { shouldHideTopSection = true; topMostVisibleSection = this.bottomSection; fieldGroupHeight = this.bottomSection.Height; } else { shouldHideTopSection = false; } nfloat offset = 0; if (fieldGroupHeight < availableSpace) { offset = (availableSpace - fieldGroupHeight) / 2.0f - this.bottomPadding; } nfloat distanceFromTop = navigationBarHeight + offset; return((int)Math.Ceiling(distanceFromTop - topMostVisibleSection.TopView.Frame.Top)); }
/// <summary> /// Create vertical dimensioning, cf. /// http://forums.autodesk.com/t5/revit-api-forum/how-can-i-create-dimension-line-that-is-not-parallel-to-detail/m-p/6801271 /// </summary> void CreateVerticalDimensioning(ViewSection viewSection) { Document doc = viewSection.Document; XYZ point3 = new XYZ(417.8, 80.228, 46.8); XYZ point4 = new XYZ(417.8, 80.811, 46.3); Line geomLine3 = Line.CreateBound(point3, point4); Line dummyLine = Line.CreateBound(XYZ.Zero, XYZ.BasisY); using (Transaction tx = new Transaction(doc)) { tx.Start("tx"); DetailLine line3 = doc.Create.NewDetailCurve( viewSection, geomLine3) as DetailLine; DetailLine dummy = doc.Create.NewDetailCurve( viewSection, dummyLine) as DetailLine; ReferenceArray refArray = new ReferenceArray(); refArray.Append(dummy.GeometryCurve.Reference); refArray.Append(line3.GeometryCurve.GetEndPointReference(0)); refArray.Append(line3.GeometryCurve.GetEndPointReference(1)); XYZ dimPoint1 = new XYZ(417.8, 80.118, 46.8); XYZ dimPoint2 = new XYZ(417.8, 80.118, 46.3); Line dimLine3 = Line.CreateBound(dimPoint1, dimPoint2); Dimension dim = doc.Create.NewDimension( viewSection, dimLine3, refArray); doc.Delete(dummy.Id); tx.Commit(); } }
void UpdateReferencingSheet( ViewSection selectedViewport) { BuiltInParameter bip = BuiltInParameter.VIEW_DISCIPLINE; Parameter discipline = selectedViewport.get_Parameter(bip); int disciplineNo = discipline.AsInteger(); Document doc = selectedViewport.Document; Transaction transaction = new Transaction(doc); if (TransactionStatus.Started == transaction.Start("Updating the model")) { //switch( disciplineNo ) //{ // case 1: // discipline.Set( 2 ); // break; // default: // discipline.Set( 1 ); // break; //} //discipline.Set( disciplineNo ); discipline.Set(1 == disciplineNo ? 2 : 1); transaction.Commit(); } }
private static bool DuplicateReferenceCallouts(View fromView, View toView) { bool result = false; try { Document fromDoc = fromView.Document; Document toDoc = toView.Document; CopyPasteOptions copyPasteOptions = new CopyPasteOptions(); copyPasteOptions.SetDuplicateTypeNamesHandler(new HideAndAcceptDuplicateTypeNamesHandler()); ICollection <ElementId> referenceCalloutIds = fromView.GetReferenceCallouts(); if (referenceCalloutIds.Count > 0) { foreach (ElementId eId in referenceCalloutIds) { XYZ firstPoint = null; XYZ secondPoint = null; bool cornerFound = GetCalloutCornerPoints(fromDoc, eId, out firstPoint, out secondPoint); Element callout = fromDoc.GetElement(eId); if (null != callout) { using (Transaction trans = new Transaction(toDoc, "Duplicate Reference Callout")) { try { trans.Start(); toDoc.Regenerate(); FilteredElementCollector collector = new FilteredElementCollector(toDoc); List <ViewDrafting> views = collector.OfClass(typeof(ViewDrafting)).ToElements().Cast <ViewDrafting>().ToList(); var viewFound = from view in views where view.Name == callout.Name select view; if (viewFound.Count() > 0) { ViewDrafting referenceView = viewFound.First(); ViewSection.CreateReferenceCallout(toDoc, toView.Id, referenceView.Id, firstPoint, secondPoint); } trans.Commit(); } catch (Exception ex) { string message = ex.Message; trans.RollBack(); } } } } } } catch (Exception ex) { string message = ex.Message; //MessageBox.Show("Failed to duplicate reference callouts.\n"+ex.Message, "Duplicate Reference Callouts", MessageBoxButton.OK, MessageBoxImage.Warning); errorMessage.AppendLine(toView.Name + ": errors in duplicating reference callouts"); } return(result); }
public static GCViewLive CreateSectionAtFaceParameter(GCRevitDocument doc, Face face, UV param, double viewCropDim, double viewDepth) { var viewTypeId = GetSectionType(doc, StandardSectionViewFamilyTypeName).Id; var boundBox = GenerateBoundingBoxFromFaceAndParameter(face, param, viewCropDim, viewDepth); return(GCViewLive.CreateGCViewLive(ViewSection.CreateSection(doc.Document, viewTypeId, boundBox))); }
/// <summary> /// Creates a filled region for the elevatin using the previously found boundaries /// and the user selected filled region type and line style /// </summary> /// <param name="doc">UI Document</param> /// <param name="intElev">Interior Elevation</param> /// <param name="filledRegionId">Id of user selected filled region</param> /// <param name="lineStyle">Id of user selected line style</param> public void CreateFilledRegion(Document doc, ViewSection intElev, ElementId filledRegionId, ElementId lineStyle) { List <CurveLoop> filledRegionBoundaries = FilledRegionBoundary(intElev); FilledRegion region = FilledRegion.Create(doc, filledRegionId, intElev.Id, filledRegionBoundaries); region.SetLineStyleId(lineStyle); }
public void SetCropBox(Document doc, ElevationMarker marker, Wall w) { ViewSection extElev = (ViewSection)doc.GetElement(marker.GetViewId(0)); BoundingBoxXYZ eecb = extElev.CropBox; XYZ cbboundsmin = extElev.CropBox.Min; XYZ cbboundsmax = extElev.CropBox.Max; LocationCurve wallCurve = w.Location as LocationCurve; XYZ wmin = wallCurve.Curve.GetEndPoint(0); XYZ wallEP2 = wallCurve.Curve.GetEndPoint(1); Parameter wallHeight = w.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM); XYZ wmax = new XYZ ( wallEP2.X, wallEP2.Y, wallEP2.Z + wallHeight.AsDouble() ); double[][] transform = Matrix.transform2matrix(eecb.Transform); double[][] transformInv = Matrix.invert(transform); double[] wMinMatrix = Matrix.xyz2matrix(wmin); double[] wMinTMatrix = Matrix.dot(transform, wMinMatrix); XYZ wMinT = Matrix.matrix2xyz(wMinTMatrix); double[] wMaxMatrix = Matrix.xyz2matrix(wmax); double[] wMaxTMatrix = Matrix.dot(transform, wMaxMatrix); XYZ wMaxT = Matrix.matrix2xyz(wMaxTMatrix); double[] originMatrix = Matrix.xyz2matrix(eecb.Transform.Origin); double[] originTMatrix = Matrix.dot(transform, originMatrix); XYZ originT = Matrix.matrix2xyz(originTMatrix); XYZ wMinTOrdered; XYZ wMaxTOrdered; Utility.ReorderMinMax(wMinT, wMaxT, out wMinTOrdered, out wMaxTOrdered); XYZ wbbboundsmin = new XYZ( wMinTOrdered.X - originT.X, wMinTOrdered.Y - originT.Y, cbboundsmin.Z ); XYZ wbbboundsmax = new XYZ( wMaxTOrdered.X - originT.X, wMaxTOrdered.Y - originT.Y - 0.01, cbboundsmax.Z ); eecb.set_Bounds(0, wbbboundsmin); eecb.set_Bounds(1, wbbboundsmax); extElev.CropBox = eecb; extElev.CropBoxVisible = false; }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { m_project = commandData.Application.ActiveUIDocument; // Get the selected element and store it to data member. if (!GetSelectedElement()) { message = m_errorInformation; return(Autodesk.Revit.UI.Result.Failed); } // Create a BoundingBoxXYZ instance which used in NewViewSection() method if (!GenerateBoundingBoxXYZ()) { message = m_errorInformation; return(Autodesk.Revit.UI.Result.Failed); } // Create a section view. Transaction transaction = new Transaction(m_project.Document, "CreateSectionView"); transaction.Start(); //ViewSection section = m_project.Document.Create.NewViewSection(m_box); ElementId DetailViewId = new ElementId(-1); IList <Element> elems = new FilteredElementCollector(m_project.Document).OfClass(typeof(ViewFamilyType)).ToElements(); foreach (Element e in elems) { ViewFamilyType v = e as ViewFamilyType; if (v != null && v.ViewFamily == ViewFamily.Detail) { DetailViewId = e.Id; break; } } ViewSection section = ViewSection.CreateDetail(m_project.Document, DetailViewId, m_box); if (null == section) { message = "Can't create the ViewSection."; return(Autodesk.Revit.UI.Result.Failed); } // Modify some parameters to make it look better. section.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2); transaction.Commit(); // If everything goes right, give successful information and return succeeded. TaskDialog.Show("Revit", "Create view section succeeded."); return(Autodesk.Revit.UI.Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }
private static ElementId SectionFromTwoPoints(Document doc, XYZ p1, XYZ p2, double height, double elevation, double view_depth) { //Convert all numeric values to internal units height = UnitUtils.ConvertToInternalUnits(height, DisplayUnitType.DUT_METERS); elevation = UnitUtils.ConvertToInternalUnits(elevation, DisplayUnitType.DUT_METERS); view_depth = UnitUtils.ConvertToInternalUnits(view_depth, DisplayUnitType.DUT_MILLIMETERS); //Filtered the document and get the view section, get its ID FilteredElementCollector filter = new FilteredElementCollector(doc); Element view1 = filter.OfClass(typeof(ViewFamilyType)) .WhereElementIsElementType() .Cast <ViewFamilyType>() .First(x => x.ViewFamily == ViewFamily.Section); ElementId viewId = view1.Id; //Create a bounding box on the origin BoundingBoxXYZ bBox = new BoundingBoxXYZ(); bBox.Min = new XYZ(0, 0, 0); bBox.Max = new XYZ(p1.DistanceTo(p2), height, view_depth); //Cartesian transform for the BBox, from 0,0,0 to line initial point Transform t = new Transform(Transform.Identity); XYZ bb_x = (p2 - p1).Normalize(); XYZ bb_y = XYZ.BasisZ; XYZ bb_z = bb_x.CrossProduct(bb_y); t.Origin = new XYZ(p1.X, p1.Y, elevation); t.BasisX = bb_x; t.BasisY = bb_y; t.BasisZ = bb_z; bBox.Transform = t; //try //{ using (Transaction trans = new Transaction(doc, "Create cross section")) { trans.Start(); ViewSection sec = ViewSection.CreateSection(doc, viewId, bBox); trans.Commit(); return(sec.Id); } //} // catch // { // return null; // } }
public List <Wall> GetWallsInView(Document doc, ViewSection view) { List <Wall> walls = new FilteredElementCollector(doc, view.Id) .OfClass(typeof(Wall)) .Cast <Wall>() .ToList(); return(walls); }
void g() { ElementId SectionId = GetViewTypeIdByViewType( ViewFamily.Section); ViewSection NyViewSectionR = ViewSection.CreateSection( doc.Document, SectionId, bbNewSectionR); }
public ElevationViewProperties(ElevationViewProperties evp) { m_view = evp.ViewObj; viewName = evp.ViewName; viewId = evp.ViewId; viewIndex = evp.ViewIndex; createdByWall = evp.CreatedByWall; wallId = evp.WallId; }
internal static IEnumerator <Type> Process(System.Configuration.Configuration config) { ViewSection viewsection = config.GetSection("RegisterViews") as ViewSection; if (viewsection.IsNotNull()) { foreach (View view in viewsection.Views) { yield return(Type.GetType(view.Class)); } } }
/// <summary> /// Private constructor /// </summary> private SectionView(BoundingBoxXYZ bbox) { TransactionManager.Instance.EnsureInTransaction(Document); ViewSection vd = CreateSectionView(bbox); InternalSetSectionView(vd); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.CleanupAndSetElementForTrace(Document, this.InternalElement); }
public void AssignName(ViewSection intElev, String intElevNewName) { //assign name when "okay" is pressed try { intElev.Name = intElevNewName; } catch { return; } }
public static ViewSection CreateSectionAtBottomAndRight(Document doc, Element StructuralFrame, double bottomorleftoffset, double ToporRightoffset) { IList <Parameter> param1 = new List <Parameter>(); IList <XYZ> points = (StructuralFrame.Location as LocationCurve).Curve.Tessellate(); XYZ p1 = points[0], p2 = points[1]; // XYZ v = p1 - p2; double vec_ang1 = 360 - Math.Round(Converter.R2D((p2 - p1).AngleOnPlaneTo(XYZ.BasisX, XYZ.BasisZ))); vec_ang1 = (vec_ang1 == 360) ? 0.0 : vec_ang1; XYZ pt1 = StructuralFrame.get_BoundingBox(doc.ActiveView).Min; XYZ pt2 = StructuralFrame.get_BoundingBox(doc.ActiveView).Max; double len = (p2 - p1).GetLength() * 0.5; ElementId BeamSymid = StructuralFrame.GetTypeId(); Element BeamSym = doc.GetElement(BeamSymid); double wid = BeamSym.GetParameters("Beam Width")[0].AsDouble(); double ht = pt2.Z - pt1.Z; ViewFamilyType view = Filter.ElementFiltering(doc, typeof(ViewFamilyType), "Section", "Building Section", null) as ViewFamilyType; XYZ min = new XYZ(-len - bottomorleftoffset, pt1.Z - 1, -wid); XYZ max = new XYZ(len + ToporRightoffset, pt2.Z + 1, wid); XYZ midpt = p1 + (p2 - p1) / 2; XYZ BeamDir = null; if (((vec_ang1 >= 0) && (vec_ang1 <= 135)) || ((vec_ang1 >= 315) && (vec_ang1 <= 360))) { BeamDir = (p1 - p2).Normalize(); } else { BeamDir = (p2 - p1).Normalize(); } XYZ up = XYZ.BasisZ; XYZ viewdir = BeamDir.CrossProduct(up); Transform t = Transform.Identity; t.Origin = midpt; t.BasisX = BeamDir; t.BasisY = up; t.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = t; sectionBox.Min = min; sectionBox.Max = max; ViewSection vsec = ViewSection.CreateSection(doc, view.Id, sectionBox); return(vsec); }
public static ViewSection CreateSectionAtBottomAndRight(Document doc, XYZ Start_Point, XYZ End_Point, BoundingBoxXYZ bb, double MaxBeamWidth, double MaxBeamDepth, double bottomorleftoffset, double ToporRightoffset) { IList <Parameter> param1 = new List <Parameter>(); // XYZ v = Start_Point - End_Point; double vec_ang1 = 360 - Math.Round(Converter.R2D((End_Point - Start_Point).AngleOnPlaneTo(XYZ.BasisX, XYZ.BasisZ))); vec_ang1 = (vec_ang1 == 360) ? 0.0 : vec_ang1; XYZ pt1 = bb.Min; XYZ pt2 = bb.Max; double len = (End_Point - Start_Point).GetLength() * 0.5; ViewFamilyType view = Filter.ElementFiltering(doc, typeof(ViewFamilyType), "Section", "Building Section", null) as ViewFamilyType; XYZ min = new XYZ(-len - bottomorleftoffset, pt1.Z - 1, -MaxBeamWidth); XYZ max = new XYZ(len + ToporRightoffset, pt2.Z + 1, MaxBeamWidth); XYZ midpt = Start_Point + (End_Point - Start_Point) / 2; XYZ BeamDir = null; if (((vec_ang1 >= 0) && (vec_ang1 <= 135)) || ((vec_ang1 >= 315) && (vec_ang1 <= 360))) { BeamDir = (Start_Point - End_Point).Normalize(); } else { BeamDir = (End_Point - Start_Point).Normalize(); } XYZ up = XYZ.BasisZ; XYZ viewdir = BeamDir.CrossProduct(up); Transform t = Transform.Identity; t.Origin = midpt; t.BasisX = BeamDir; t.BasisY = up; t.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = t; sectionBox.Min = min; sectionBox.Max = max; ViewSection vsec = ViewSection.CreateSection(doc, view.Id, sectionBox); return(vsec); }
/// <summary> /// Initializes a new instance of the KeyboardLayoutHideSectionAnimation class. /// </summary> /// <param name="topViews">A list of views representing the top section of the screen layout and will be hidden based on screen space and keyboard state.</param> /// <param name="bottomViews">A list of views that are below the top views and intended to be moved based on the keyboard state.</param> /// <param name="bottomPadding">An optional amount of padding to apply to the bottom of the views when moving them vertical.</param> public KeyboardLayoutHideSectionAnimation( IEnumerable <UIView> topViews, IEnumerable <UIView> bottomViews, int bottomPadding = 0) { Throw.IfArgumentNull(topViews, "topViews"); Throw.IfArgumentNull(bottomViews, "bottomViews"); this.topSection = new ViewSection(topViews); this.bottomSection = new ViewSection(bottomViews); this.bottomPadding = bottomPadding; }
/// <summary> /// 获取剖面视图在模型坐标系下的 BoundingBoxXYZ(默认是局部坐标系的) /// </summary> /// <param name="viewSection"></param> /// <returns></returns> public static BoundingBoxXYZ GetViewSectionBBox(this ViewSection viewSection) { BoundingBoxXYZ bbox = viewSection.CropBox; var min = bbox.Transform.OfPoint(bbox.Min); var max = bbox.Transform.OfPoint(bbox.Max); BoundingBoxXYZ newBBox = new BoundingBoxXYZ(); newBBox.Max = max; newBBox.Min = min; return(newBBox); }
private static ViewSection CreateSectionView(BoundingBoxXYZ bbox) { //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.Section select type; //create a new view ViewSection view = ViewSection.CreateSection(dynRevitSettings.Doc.Document, viewFamilyTypes.First().Id, bbox); return(view); }
public static void AlignSectionsOnSheet(Document doc, List <ElementId> viewsIds, ViewSheet sheet) { //test reverse viewids viewsIds.Reverse(); //Get scale value of first view ViewSection sec1 = doc.GetElement(viewsIds[0]) as ViewSection; int scale = sec1.Scale; //Get sheet id ElementId sheetId = sheet.Id; //Get length of views List <double> lengths = new List <double>(); foreach (ElementId idview in viewsIds) { Element viewEl = doc.GetElement(idview); ViewSection viewsec = viewEl as ViewSection; double length = viewsec.CropBox.Max.X - viewsec.CropBox.Min.X; lengths.Add((length / scale)); } double x_coord = 0; for (int i = 0; i < viewsIds.Count(); i++) { if (i == 0) { x_coord = 0; } else { x_coord += (lengths[i - 1] + lengths[i]) / 2.0; } using (Transaction trans = new Transaction(doc, "Place section in sheet")) { trans.Start(); XYZ point = new XYZ(x_coord, 0, 0); Viewport v = Viewport.Create(doc, sheetId, viewsIds[i], point); trans.Commit(); } } }
private void ApplyTemplateSettings() { try { if (toolSettings.ViewTemplateId != -1) { ViewSection viewSection = m_doc.GetElement(new ElementId(toolSettings.ViewTemplateId)) as ViewSection; if (null != viewSection) { ICollection <ElementId> parameterIds = viewSection.GetTemplateParameterIds(); int viewScaleImperial = (int)BuiltInParameter.VIEW_SCALE_PULLDOWN_IMPERIAL; int viewScaleMetric = (int)BuiltInParameter.VIEW_SCALE_PULLDOWN_METRIC; int viewScale = (int)BuiltInParameter.VIEW_SCALE; var selectedIds = from paramId in parameterIds where paramId.IntegerValue == viewScaleImperial || paramId.IntegerValue == viewScaleMetric || paramId.IntegerValue == viewScale select paramId; if (selectedIds.Count() > 0) { using (Transaction trans = new Transaction(m_doc, "SetViewTemplate")) { trans.Start(); try { if (toolSettings.ScaleByTemplate) { toolSettings.CustomScale = viewSection.Scale; } else { viewSection.SetNonControlledTemplateParameterIds(selectedIds.ToList()); } trans.Commit(); } catch (Exception ex) { trans.RollBack(); MessageBox.Show("Failed to include or exclude View Scale parameter from the view template.\n" + ex.Message, "View Template", MessageBoxButton.OK, MessageBoxImage.Warning); } } } } } } catch (Exception ex) { MessageBox.Show("Failed to apply template settings.\n" + ex.Message, "Elevation Creator : ApplyTemplateSettings", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private static ViewBox getSectionViewBox(ViewSection vs) { ViewBox box = new ViewBox(); XYZ tmp1 = vs.Origin; XYZ right = XYZ.BasisZ.CrossProduct(vs.ViewDirection); box.P1 = vs.CropBox.Transform.OfPoint(vs.CropBox.Min); box.P2 = vs.CropBox.Transform.OfPoint(vs.CropBox.Max); box.TransformationMatrix = vs.CropBox.Transform; box.DirectionUp = vs.UpDirection; box.EyePosition = vs.Origin.Add(vs.ViewDirection.Multiply(10)); box.DirectionView = vs.ViewDirection.Negate(); box.bbox = vs.CropBox; return(box); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { m_project = commandData.Application.ActiveUIDocument; // Get the selected element and store it to data member. if (!GetSelectedElement()) { message = m_errorInformation; return(Autodesk.Revit.UI.Result.Failed); } // Create a BoundingBoxXYZ instance which used in NewViewSection() method if (!GenerateBoundingBoxXYZ()) { message = m_errorInformation; return(Autodesk.Revit.UI.Result.Failed); } // Create a section view. Transaction transaction = new Transaction(m_project.Document, "CreateSectionView"); transaction.Start(); ViewSection section = m_project.Document.Create.NewViewSection(m_box); if (null == section) { message = "Can't create the ViewSection."; return(Autodesk.Revit.UI.Result.Failed); } // Modify some parameters to make it look better. section.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL).Set(2); transaction.Commit(); // If everything goes right, give successful information and return succeeded. MessageBox.Show("Create view section succeeded.", "Revit"); return(Autodesk.Revit.UI.Result.Succeeded); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }
/// <summary> /// 获取剖面视图在平面视图上的范围框的点的序列, Z = minZ /// </summary> /// <param name="viewSection"></param> /// <returns></returns> public static List <XYZ> GetViewSectionPlanePointsLoop(this ViewSection viewSection) { BoundingBoxXYZ bbox = viewSection.CropBox; Double farCropDist = viewSection.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).AsDouble(); var direct = viewSection.ViewDirection.Normalize(); var minPt = bbox.Transform.OfPoint(bbox.Min); var maxPt = bbox.Transform.OfPoint(bbox.Max); var p1 = new XYZ(minPt.X, minPt.Y, minPt.Z); var p3 = new XYZ(maxPt.X, maxPt.Y, minPt.Z); var p2 = p3 - direct * farCropDist; var p4 = p1 + direct * farCropDist; return(new List <XYZ> { p1, p2, p3, p4 }); }
private void Stream( ArrayList data, ViewSection view ) { data.Add( new Snoop.Data.ClassSeparator( typeof( ViewSection ) ) ); Utils.StreamWithReflection( data, typeof( ViewSection ), view ); // nothing at this level yet }
private static ViewBox getSectionViewBox(ViewSection vs) { ViewBox box = new ViewBox(); XYZ tmp1 = vs.Origin; XYZ right = XYZ.BasisZ.CrossProduct(vs.ViewDirection); box.P1 = vs.CropBox.Transform.OfPoint(vs.CropBox.Min); box.P2 = vs.CropBox.Transform.OfPoint(vs.CropBox.Max); box.TransformationMatrix = vs.CropBox.Transform; box.DirectionUp = vs.UpDirection; box.EyePosition = vs.Origin.Add(vs.ViewDirection.Multiply(10)); box.DirectionView = vs.ViewDirection.Negate(); box.bbox = vs.CropBox; return box; }