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))); }
void g() { ElementId SectionId = GetViewTypeIdByViewType( ViewFamily.Section); ViewSection NyViewSectionR = ViewSection.CreateSection( doc.Document, SectionId, bbNewSectionR); }
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 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); }
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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; UIDocument uiDoc = uiApp.ActiveUIDocument; _app = uiApp.Application; _doc = uiDoc.Document; Reference reference = uiDoc.Selection.PickObject(ObjectType.Element); Element element = uiDoc.Document.GetElement(reference); Wall wall = (Wall)element; ViewFamilyType vft = new FilteredElementCollector(_doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); // Determine section box BoundingBoxXYZ sectionBox = GetSectionViewParallelToWall(wall); //BoundingBoxXYZ sectionBox2 = GetSectionViewPerpendiculatToWall(wall); // Create wall section view using (Transaction tx = new Transaction(_doc)) { tx.Start("Create Wall Section View"); ViewSection.CreateSection(_doc, vft.Id, sectionBox); //ViewSection.CreateSection(_doc, vft.Id, sectionBox2); tx.Commit(); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; UIDocument uiDoc = uiApp.ActiveUIDocument; Document doc = uiDoc.Document; Selection sel = uiApp.ActiveUIDocument.Selection; //pick a point XYZ point = sel.PickPoint("pick a point inside a room"); Room room = doc.GetRoomAtPoint(point); SpatialElementBoundaryOptions options = new SpatialElementBoundaryOptions(); IList <IList <BoundarySegment> > boundaries = room.GetBoundarySegments(options); //create wall section view ViewFamilyType vftElevation = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>(x => ViewFamily.Elevation == x.ViewFamily); ViewFamilyType vftSection = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); using (Transaction tx = new Transaction(doc)) { tx.Start("create wall section view"); for (int i = 0; i < boundaries.Count; i++) { for (int j = 0; j < boundaries[i].Count; j++) { Wall wall0 = boundaries[i][j].Element as Wall; BoundingBoxXYZ section = getSectionVewParallelToWall(wall0); ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, vftElevation.Id, point, 96); //ViewPlan viewPlan = ViewPlan.Create(doc, , wall0.LevelId); //viewPlan.CropBox = section; ViewSection.CreateSection(doc, vftSection.Id, section); } } tx.Commit(); } return(Result.Succeeded); }
/// <summary> /// Creates a new view section. /// </summary> /// <param name="doc"></param> /// <param name="elmId"></param> /// <param name="box"></param> /// <returns></returns> public static ViewSection CreateViewSection(this Document doc, ElementId elmId, BoundingBoxXYZ box) { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } if (elmId == null) { throw new ArgumentNullException(nameof(elmId)); } if (box == null) { throw new ArgumentNullException(nameof(box)); } return(doc.GetElement(elmId) == null ? null : ViewSection.CreateSection(doc, elmId, box)); }
private static ViewSection CreateSectionView(BoundingBoxXYZ bbox) { TransactionManager.Instance.EnsureInTransaction(Document); // (sic) From the Dynamo legacy implementation var viewFam = DocumentManager.Instance.ElementsOfType <ViewFamilyType>() .FirstOrDefault(x => x.ViewFamily == ViewFamily.Section); if (viewFam == null) { throw new Exception("There is no three dimensional view family in the document"); } var viewSection = ViewSection.CreateSection(Document, viewFam.Id, bbox); TransactionManager.Instance.TransactionTaskDone(); return(viewSection); }
///在墙的中点,创建剖面/// /// public static View CreatWallSection(Wall wall) { Document doc = wall.Document; LocationCurve lc = wall.Location as LocationCurve; Line l = lc.Curve as Line; XYZ midpoint = (l.GetEndPoint(0) + l.GetEndPoint(1)) / 2; XYZ lineDir = l.Direction; Transform tsf = Transform.Identity; tsf.Origin = midpoint; tsf.BasisZ = lineDir; tsf.BasisY = XYZ.BasisZ; tsf.BasisX = -lineDir.CrossProduct(XYZ.BasisZ).Normalize(); Parameter para = wall.LookupParameter("无连接高度"); double z = para.AsDouble(); double width = 400 / 304.8; double depth = 300 / 308.4; XYZ min = new XYZ(-width / 2, 0, -depth); XYZ max = new XYZ(width / 2, z, 0); BoundingBoxXYZ box = new BoundingBoxXYZ(); box.Transform = tsf; box.Min = min; box.Max = max; ViewFamilyType vft = (new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>().Where(m => m.ViewFamily == ViewFamily.Section)).First(); return(ViewSection.CreateSection(doc, vft.Id, box)); }
private void sectionViewBeamZ() { UIDocument UiDoc = this.ActiveUIDocument; Document doc = UiDoc.Document; //Get element by filler by Id integer of category List <int> myListIdCategory = new List <int>(); myListIdCategory.Add((int)BuiltInCategory.OST_StructuralFraming); Reference myRef = UiDoc.Selection.PickObject(ObjectType.Element, new FilterByIdCategory(myListIdCategory), "Pick a Beam..."); Element elem = doc.GetElement(myRef); ElementId elemTypeId = elem.GetTypeId(); Element elemType = doc.GetElement(elemTypeId); // Ensure wall is straight LocationCurve lc = elem.Location as LocationCurve; // Type view Family ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); #region Create View 2 //Section theo phuong doc dam // Using 0.5 and "true" to specify that the // parameter is normalized places the transform // origin at the center of the location curve Transform curveTransform = lc.Curve.ComputeDerivatives(0.5, true); // The transform contains the location curve // mid-point and tangent, and we can obtain // its normal in the XY plane: XYZ origin_Y = curveTransform.Origin; // Set tam cua section View la origin cua curve Transform XYZ viewdir_Y = curveTransform.BasisX.Normalize(); // view dir da bi xoay di 90 do XYZ up_Y = XYZ.BasisZ; // Huong len trung voi truc z XYZ right_Y = up_Y.CrossProduct(viewdir_Y); // right theo tam dien thuan // Create a transform from vectors above. Transform transform_Y = Transform.Identity; transform_Y.Origin = origin_Y; transform_Y.BasisX = viewdir_Y; transform_Y.BasisY = right_Y; transform_Y.BasisZ = up_Y; BoundingBoxXYZ sectionBoxY = new BoundingBoxXYZ(); sectionBoxY.Transform = transform_Y; // Xác định điểm offset using (Transaction myTrans = new Transaction(doc, "Create view section of Beam")) { myTrans.Start(); ViewSection.CreateSection(doc, vft.Id, sectionBoxY); myTrans.Commit(); } #endregion }
private void sectionViewBeamX(Element myElem) { UIDocument UiDoc = this.ActiveUIDocument; Document doc = UiDoc.Document; Element elem = myElem; ElementId elemTypeId = elem.GetTypeId(); Element elemType = doc.GetElement(elemTypeId); // Element type Name string nameOfBeam = elem.Name; //TaskDialog.Show("test2", nameOfBeam); // Ensure wall is straight LocationCurve lc = elem.Location as LocationCurve; Line line = lc.Curve as Line; // Create section View // Các tham số để tạo view section /// <summary> /// public static ViewSection CreateSection(Document document, ElementId viewFamilyTypeId, BoundingBoxXYZ sectionBox) /// </summary> /// //Tao viewFamilytypeId (tham so thu 2) ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); // tao BoundingBox (tham so thu 3) XYZ p = line.GetEndPoint(0); XYZ q = line.GetEndPoint(1); XYZ v = q - p; //Set boundingBox BoundingBoxXYZ bb_X = elem.get_BoundingBox(null); double minZ_X = bb_X.Min.Z; double maxZ_X = bb_X.Max.Z; double minY_X = bb_X.Min.Y; double maxY_X = bb_X.Max.Y; //lay cac thong so kich thuoc dam double l = v.GetLength(); // length of beam (endpoint - start Point) double h = maxZ_X - minZ_X; // h of beam double b = maxY_X - minY_X; // b of beam double offset = 0.1 * l; // khoang cach offset XYZ min = new XYZ(-l / 2 - h, 0 - offset - h, 0); XYZ max = new XYZ(l / 2 + h, offset, offset); XYZ midpoint = p + 0.5 * v; // Toa do trung diem XYZ beamdir = v.Normalize(); // Truc dam XYZ upX = XYZ.BasisZ; // Huong z thang dung XYZ viewdirX = beamdir.CrossProduct(upX); // Huong nhin cua View Transform tX = Transform.Identity; tX.Origin = midpoint; // Goc view tX.BasisX = beamdir; // Huong X la trung voi huong beam tX.BasisY = upX; // Huong y trung voi truc z tX.BasisZ = viewdirX; // Huong z trung voi huong nhin view (y) BoundingBoxXYZ sectionBoxX = new BoundingBoxXYZ(); sectionBoxX.Transform = tX; sectionBoxX.Min = min; sectionBoxX.Max = max; using (Transaction myTrans = new Transaction(doc, "Create view section X of Beam")) { myTrans.Start(); ViewSection vSX = ViewSection.CreateSection(doc, vft.Id, sectionBoxX); // vSX.Name = nameOfBeam + "_X"; //vSX.ViewName = "ABC"; myTrans.Commit(); } }
/// <summary> /// Createsection View for elements /// </summary> public void createSectionViewWall() { UIDocument uidoc = this.ActiveUIDocument; Document doc = uidoc.Document; Reference myRef = uidoc.Selection.PickObject(ObjectType.Element); Wall wall = doc.GetElement(myRef) as Wall; // Ensure wall is straight LocationCurve lc = wall.Location as LocationCurve; Line line = lc.Curve as Line; if (null == line) { TaskDialog.Show("Error", "Unable to retrieve wall location line."); return; } // Determine view family type to use ViewFamilyType vft = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); // Determine section box XYZ p = line.GetEndPoint(0); XYZ q = line.GetEndPoint(1); XYZ v = q - p; BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z; double maxZ = bb.Max.Z; double w = v.GetLength(); double h = maxZ - minZ; double d = wall.WallType.Width; double offset = 0.5; XYZ min = new XYZ(-w, -offset, -offset); XYZ max = new XYZ(w, h + offset, offset); XYZ midpoint = p + 0.5 * v; XYZ walldir = v.Normalize(); XYZ up = XYZ.BasisZ; XYZ viewdir = walldir.CrossProduct(up); Transform t = Transform.Identity; t.Origin = midpoint; t.BasisX = walldir; t.BasisY = up; t.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = t; sectionBox.Min = min; sectionBox.Max = max; // Create wall section view using (Transaction tx = new Transaction(doc)) { tx.Start("Create Wall Section View"); ViewSection.CreateSection(doc, vft.Id, sectionBox); tx.Commit(); } }
/// <summary> /// Adds the new view section. /// </summary> /// <param name="doc"></param> /// <param name="elmId"></param> /// <param name="box"></param> /// <returns></returns> public static ViewSection AddViewSection(this Document doc, ElementId elmId, BoundingBoxXYZ box) { return(doc.GetElement(elmId) == null ? null : ViewSection.CreateSection(doc, elmId, box)); }
/// <summary> /// Returns the cut lines. /// </summary> /// <param name="viewId">The view identifier.</param> public static void CutLines(ElementId viewId) { Utils.Log(string.Format("UtilsSectionView.CutLines started...", "")); var uidoc = DocumentManager.Instance.CurrentUIDocument; var doc = uidoc.Document; var view = doc.GetElement(viewId) as View; var app = doc.Application; Options opt = new Options(); opt.View = view; BoundingBoxXYZ crop = view.CropBox; IList <DetailCurve> detailCurves = new List <DetailCurve>(); IList <Curve> linkedCurves = new List <Curve>(); Transform tr = view.CropBox.Transform; string path = Path.Combine(Path.GetTempPath(), "Copy.rvt"); var rliCollection = new FilteredElementCollector(doc) .OfClass(typeof(RevitLinkInstance)) .WhereElementIsNotElementType() .Cast <RevitLinkInstance>(); Document link = null; RevitServices.Transactions.TransactionManager.Instance.ForceCloseTransaction(); CloseCopy(); Utils.Log(string.Format("Preparing Revit Links...", "")); if (rliCollection.Count() > 0) { #region RevitLinkInstances foreach (RevitLinkInstance rli in rliCollection) { ElementId efrId = rli.GetTypeId(); var status = ExternalFileUtils.GetExternalFileReference(doc, efrId).GetLinkedFileStatus(); Utils.Log(string.Format("Status {0}...", status)); if (status == LinkedFileStatus.InClosedWorkset || status == LinkedFileStatus.Invalid || status == LinkedFileStatus.LocallyUnloaded || status == LinkedFileStatus.NotFound || status == LinkedFileStatus.Unloaded) { continue; } app.CopyModel(ModelPathUtils.ConvertUserVisiblePathToModelPath(rli.GetLinkDocument().PathName), path, true); link = app.OpenDocumentFile(path); // access projectlocations // test if the the project location in the host file exists in the linked document // if exists retrieve the transform object via project position // apply the transform to the total transform of the revit link instance Utils.Log(string.Format("Processing {0}...", path)); Transform rliTransform = rli.GetTotalTransform(); // TODO: include angle in the calculation // TODO: include different project location from the Link Instance // TODO: test for different locations of the same instance tr.Origin = rliTransform.Inverse.OfPoint(view.Origin); tr.BasisX = rliTransform.Inverse.OfVector(-view.RightDirection); tr.BasisY = XYZ.BasisZ; tr.BasisZ = tr.BasisX.CrossProduct(tr.BasisY); BoundingBoxXYZ bb = new BoundingBoxXYZ(); bb.Transform = tr; XYZ min = view.CropBox.Min; XYZ max = view.CropBox.Max; bb.Min = new XYZ(min.X, min.Y, 0); bb.Max = new XYZ(max.X, max.Y, -min.Z); IList <ElementId> detailCurveIds = new List <ElementId>(); var linkedViewId = ElementId.InvalidElementId; // TODO: create other view family types, currently works only for sections using (Transaction q = new Transaction(link, "Cut1")) { q.Start(); ElementId vftId = new FilteredElementCollector(link) .OfClass(typeof(ViewFamilyType)) .WhereElementIsElementType() .Cast <ViewFamilyType>() .First(x => x.ViewFamily == ViewFamily.Section) .Id; View linkedView = ViewSection.CreateSection(link, vftId, bb); link.Regenerate(); foreach (Curve c in CutCurvesInView(link, linkedView.Id)) { //linkedCurves.Add(c.CreateTransformed(Transform.CreateTranslation(translation))); linkedCurves.Add(c.CreateTransformed(rliTransform)); } q.RollBack(); } link.Close(false); Utils.Log(string.Format("Completed", "")); } #endregion } Utils.Log(string.Format("Processing current document...", "")); using (Transaction t = new Transaction(doc, "Cut")) { t.Start(); #region Current Document Detail Curves IList <ElementId> toDelete = new List <ElementId>(); foreach (Group g in new FilteredElementCollector(doc, view.Id) .OfClass(typeof(Group)) .WhereElementIsNotElementType() .Cast <Group>() .Where(x => x.GroupType.Name == view.Name)) { g.Pinned = false; toDelete.Add(g.Id); } if (toDelete.Count > 0) { doc.Delete(toDelete); toDelete.Clear(); } Utils.Log(string.Format("Deleted {0} groups.", toDelete.Count)); GraphicsStyle gs = new FilteredElementCollector(doc) .OfClass(typeof(GraphicsStyle)) .WhereElementIsNotElementType() .Cast <GraphicsStyle>() .First(x => x.GraphicsStyleCategory.Name == "Medium Lines"); // TODO make it usable for different languages as well Utils.Log(string.Format("Preparing for extracting curves...", "")); foreach (Curve c in CutCurvesInView(doc, view.Id)) { try { var dc = doc.Create.NewDetailCurve(view, c); if (null != dc) { detailCurves.Add(dc); } } catch { continue; } } if (linkedCurves.Count > 0) { foreach (Curve c in linkedCurves.Where(x => x.Length > doc.Application.ShortCurveTolerance)) { try { var dc = doc.Create.NewDetailCurve(view, c); if (null != dc) { detailCurves.Add(dc); } } catch { continue; } } } foreach (DetailCurve dc in detailCurves) { dc.LineStyle = gs; } // this is necessary otherwise a warning pops up for editing a group outside of scope doc.Regenerate(); #endregion #region Group foreach (GroupType gt in new FilteredElementCollector(doc) .OfClass(typeof(GroupType)) .WhereElementIsElementType() .Where(x => x.Name == view.Name)) { toDelete.Add(gt.Id); } if (toDelete.Count > 0) { doc.Delete(toDelete); } if (detailCurves.Count > 0) { Group g = doc.Create.NewGroup(detailCurves.Select(x => x.Id).ToList()); g.GroupType.Name = view.Name; g.Pinned = true; } #endregion t.Commit(); } CloseCopy(); Utils.Log(string.Format("UtilsSectionView.CutLines completed.", "")); }
void f() { NyViewSectionB = ViewSection.CreateSection( doc.Document, SectionId, bbNewSectionF); }
private View CreateViewAndSectionMark(UIDocument uidoc, Element e) { Document doc = uidoc.Document; Wall wall = e as Wall; // Ensure wall is straight LocationCurve lc = wall.Location as LocationCurve; Line line = lc.Curve as Line; if (null == line) { TaskDialog.Show("Error", "Unable to retrieve wall location line."); //return; } // Determine view family type to use ViewFamilyType vft = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); XYZ p = line.GetEndPoint(0); XYZ q = line.GetEndPoint(1); XYZ v = q - p; //Gets the bounding box of the wall BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z; double maxZ = bb.Max.Z; //gets the width and height of the wall double w = v.GetLength(); double h = maxZ - minZ; //this is the bottom left and upper right coordinate of the viewport window. the Z value also sets the depth of the view XYZ max = new XYZ(0.5 * w, maxZ, 1); XYZ min = new XYZ(0.5 * -w, minZ, -1); Transform localcoordinates = HelperClass.getLocalCoordinates(e, StructSelected, uidoc); //Create a new bounding box. this box will define the limits of the section mark BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = localcoordinates; sectionBox.Min = min; sectionBox.Max = max; // Create wall section view View view = null; using (Transaction tx = new Transaction(doc)) { tx.Start("Create Wall Section View"); view = ViewSection.CreateSection(doc, vft.Id, sectionBox) as View; //cropbox is turned off so all elements get hidden when passing the active view filter view.CropBoxActive = false; tx.Commit(); } return(view); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; Selection sel = uidoc.Selection; var form_to_show = new LoadExcel(uiapp); form_to_show.ShowDialog(); View3D view = doc.ActiveView as View3D; if (null == view) { message = "Please run this command in a 3D view."; return(Result.Failed); } Element scopeBox = new FilteredElementCollector(doc, view.Id) .OfCategory(BuiltInCategory.OST_VolumeOfInterest) .WhereElementIsNotElementType() .FirstElement(); ElementId scopeBoxName = scopeBox.Id; BoundingBoxXYZ viewScopeBox = GenerateBoundingBoxXYZ(scopeBox); //set up view family type - have to play with this one more ViewFamilyType vft = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); string filenametemp = get_str(); //make the transaction; should add more sections here later; using (Transaction tx = new Transaction(doc)) { tx.Start("Move And Resize Section Box"); ViewSection section = ViewSection.CreateSection(doc, vft.Id, viewScopeBox); section.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(scopeBoxName); section.get_Parameter(BuiltInParameter.VIEW_NAME).Set(get_str()); GetTitleBlocks(doc); GenerateSheet(doc, section); //view.SetSectionBox(viewScopeBox); tx.Commit(); } return(Result.Succeeded); }
public static void Draw(Document doc, Element elem, String Section_Name, double LeftOffset, double RightOffset, double TopOffset, double BottomOffset, double NearClipOffset, double FarClipOffset) { ElementId elemid = elem.Id; //= refe.ElementId; XYZ Cen_pt = ((LocationPoint)elem.Location).Point; XYZ Y_Plane = new XYZ(0, -1, 0); ViewFamilyType view = KJU.Filter.ElementFiltering(doc, typeof(ViewFamilyType), "Section", Section_Name, null) as ViewFamilyType; FamilyInstance inst = elem as FamilyInstance; Transform tr = inst.GetTransform(); Parameter Elec_PanelName = inst.get_Parameter(BuiltInParameter.RBS_ELEC_PANEL_NAME); string Elec_Equipment_Name = null; Room room = inst.Room; if (null != room) { Elec_Equipment_Name = room.Name.Substring(0, room.Name.Length - room.Number.Length - 1) + "-" + inst.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString(); } else { Elec_Equipment_Name = "Exterior" + "-" + inst.get_Parameter(BuiltInParameter.ALL_MODEL_MARK).AsString(); } double Half_Width = inst.GetParameters("##Width")[0].AsDouble() / 2.0, Half_Height = inst.GetParameters("##Height")[0].AsDouble() / 2.0; XYZ Right_Dir = tr.BasisX; XYZ St_Pt = tr.Origin - Right_Dir * Half_Width, End_Pt = tr.Origin + Right_Dir * Half_Width; XYZ v = St_Pt - End_Pt; double X_Angle = (End_Pt - St_Pt).AngleOnPlaneTo(XYZ.BasisX, XYZ.BasisZ); //TaskDialog.Show("Angle","Angle = " + Math.Round(X_Angle * 180 / Math.PI,5).ToString() // + " --- " + Elec_Equipment_Name); XYZ Min = new XYZ(-(Half_Width + LeftOffset), -(Half_Height + BottomOffset), NearClipOffset); XYZ Max = new XYZ(Half_Width + RightOffset, Half_Height + TopOffset, FarClipOffset); XYZ Orgin = End_Pt + 0.5 * v; XYZ X_Dir = v.Normalize(); XYZ Up_Dir = XYZ.BasisZ; XYZ View_Dir = X_Dir.CrossProduct(Up_Dir); Transform Sec_Tr = Transform.Identity; Sec_Tr.Origin = Orgin; Sec_Tr.BasisX = X_Dir; Sec_Tr.BasisY = Up_Dir; Sec_Tr.BasisZ = View_Dir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = Sec_Tr; sectionBox.Min = Min; sectionBox.Max = Max; ViewSection vs = null; using (Transaction tn = new Transaction(doc)) { tn.Start("Section"); try { vs = ViewSection.CreateSection(doc, view.Id, sectionBox); Elec_PanelName.Set(Elec_Equipment_Name); vs.Name = inst.get_Parameter(BuiltInParameter.RBS_ELEC_PANEL_NAME).AsString(); tn.Commit(); } catch (Exception) { return; } } }
private Result pipeSection(Document doc, Pipe pipe) { LocationCurve lc = pipe.Location as LocationCurve; Curve curve = lc.Curve as Curve; if (null == curve) { TaskDialog.Show("...", "Unable to retrieve pipe location line."); return(Result.Failed); } // Determine view family type to use ViewFamilyType vft = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); // Determine section box XYZ p = curve.GetEndPoint(0); XYZ q = curve.GetEndPoint(1); XYZ v = q - p; XYZ v2 = new XYZ(v.X, v.Y, 0); BoundingBoxXYZ bb = pipe.get_BoundingBox(null); double minZ = bb.Min.Z; double maxZ = bb.Max.Z; double avg = (maxZ - minZ) / 2; double w = v.GetLength(); double h = maxZ - minZ; double d = pipe.Diameter; double offset = 0.1 * w; XYZ min = new XYZ(-w / 2 - side, -avg - above, -offset); XYZ max = new XYZ(w / 2 + side, avg + above, 3); XYZ ductdir = v2.Normalize(); XYZ up = XYZ.BasisZ; XYZ viewdir = ductdir.CrossProduct(up); XYZ midpoint = p + 0.5 * v; Transform t = Transform.Identity; t.Origin = midpoint; t.BasisX = ductdir; t.BasisY = up; t.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); try { sectionBox.Transform = t; sectionBox.Min = min; sectionBox.Max = max; } catch (Exception ex) { using (Transaction tx = new Transaction(doc)) { tx.Start("Create pipe Section View"); if (SectionConfigForm.vft == null) { viewSec = ViewSection.CreateSection(doc, vft.Id, sectionBox); } else { viewSec = ViewSection.CreateSection(doc, SectionConfigForm.vft.Id, sectionBox); } tx.Commit(); } } using (Transaction tx = new Transaction(doc)) { tx.Start("Create pipe Section View"); if (SectionConfigForm.vft == null) { viewSec = ViewSection.CreateSection(doc, vft.Id, sectionBox); } else { viewSec = ViewSection.CreateSection(doc, SectionConfigForm.vft.Id, sectionBox); } tx.Commit(); } return(Result.Succeeded); }
public static ViewSection CreateWallSection(Document linkedDoc, Document doc, Polygon directPolygon, ElementId id, string viewName, double offset) { Element e = linkedDoc.GetElement(id); if (!(e is Wall)) { throw new Exception("Element is not a wall!"); } Wall wall = (Wall)e; Line line = (wall.Location as LocationCurve).Curve as Line; ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); XYZ p1 = line.GetEndPoint(0), p2 = line.GetEndPoint(1); List <XYZ> ps = new List <XYZ> { p1, p2 }; ps.Sort(new ZYXComparer()); p1 = ps[0]; p2 = ps[1]; BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z, maxZ = bb.Max.Z; double l = GeomUtil.GetLength(GeomUtil.SubXYZ(p2, p1)); double h = maxZ - minZ; double w = wall.WallType.Width; XYZ tfMin = new XYZ(-l / 2 - offset, minZ - offset, -w - offset); XYZ tfMax = new XYZ(l / 2 + offset, maxZ + offset, w + offset); XYZ wallDir = GeomUtil.UnitVector(p2 - p1); XYZ upDir = XYZ.BasisZ; XYZ viewDir = GeomUtil.CrossMatrix(wallDir, upDir); XYZ midPoint = (p1 + p2) / 2; XYZ pMidPoint = GetProjectPoint(directPolygon.Plane, midPoint); XYZ pPnt = GeomUtil.OffsetPoint(pMidPoint, viewDir, w * 10); if (GeomUtil.IsBigger(GeomUtil.GetLength(pMidPoint, directPolygon.CentralXYZPoint), GeomUtil.GetLength(pPnt, directPolygon.CentralXYZPoint))) { wallDir = -wallDir; upDir = XYZ.BasisZ; viewDir = GeomUtil.CrossMatrix(wallDir, upDir); } else { } pPnt = GeomUtil.OffsetPoint(p1, wallDir, offset); XYZ min = null, max = null; if (GeomUtil.IsBigger(GeomUtil.GetLength(GeomUtil.SubXYZ(pPnt, midPoint)), GeomUtil.GetLength(GeomUtil.SubXYZ(p1, midPoint)))) { min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, wallDir, offset), -viewDir, offset); max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, -wallDir, offset), viewDir, offset); } else { min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, -wallDir, offset), -viewDir, offset); max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, wallDir, offset), viewDir, offset); } min = new XYZ(min.X, min.Y, minZ - offset); max = new XYZ(max.X, max.Y, maxZ + offset); Transform tf = Transform.Identity; tf.Origin = (p1 + p2) / 2; tf.BasisX = wallDir; tf.BasisY = XYZ.BasisZ; tf.BasisZ = GeomUtil.CrossMatrix(wallDir, upDir); BoundingBoxXYZ sectionBox = new BoundingBoxXYZ() { Transform = tf, Min = tfMin, Max = tfMax }; ViewSection vs = ViewSection.CreateSection(doc, vft.Id, sectionBox); tf = vs.get_BoundingBox(null).Transform.Inverse; max = tf.OfPoint(max); min = tf.OfPoint(min); double maxx = 0, maxy = 0, maxz = 0, minx = 0, miny = 0, minz = 0; if (max.Z > min.Z) { maxz = max.Z; minz = min.Z; } else { maxz = min.Z; minz = max.Z; } if (Math.Round(max.X, 4) == Math.Round(min.X, 4)) { maxx = max.X; minx = minz; } else if (max.X > min.X) { maxx = max.X; minx = min.X; } else { maxx = min.X; minx = max.X; } if (Math.Round(max.Y, 4) == Math.Round(min.Y, 4)) { maxy = max.Y; miny = minz; } else if (max.Y > min.Y) { maxy = max.Y; miny = min.Y; } else { maxy = min.Y; miny = max.Y; } BoundingBoxXYZ sectionView = new BoundingBoxXYZ(); sectionView.Max = new XYZ(maxx, maxy, maxz); sectionView.Min = new XYZ(minx, miny, minz); vs.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(ElementId.InvalidElementId); vs.get_Parameter(BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING).Set(0); vs.CropBoxActive = true; vs.CropBoxVisible = true; doc.Regenerate(); vs.CropBox = sectionView; vs.Name = viewName; return(vs); }
//*****************************CreateSectionStart()***************************** public void CreateSectionStart(Document doc, UIDocument uidoc) { // My library LibraryGetItems libGet = new LibraryGetItems(); Element e = libGet.SelectElement(uidoc, doc); Wall wall = null; if (e != null) { wall = e as Wall; } // Create a BoundingBoxXYZ instance centered on wall BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z; double maxZ = bb.Max.Z; double h = maxZ - minZ; Level level = doc.ActiveView.GenLevel; double top = 90 - level.Elevation; double bottom = -(level.Elevation + 25); LocationCurve lc = wall.Location as LocationCurve; Line line = lc.Curve as Line; XYZ p = line.GetEndPoint(0); XYZ q = line.GetEndPoint(1); XYZ v = p - q; // p point 0 - q point 1 - view direction up. double halfLength = v.GetLength() / 2; double offset = 3; // offset by 3 feet. //Max/Min X = Section line Length, Max/Min Y is the height of the section box, Max/Min Z far clip XYZ min = new XYZ(-halfLength, bottom, -offset); XYZ max = new XYZ(halfLength, top, offset); XYZ midpoint = q + 0.5 * v; // q get lower midpoint. XYZ walldir = v.Normalize(); XYZ up = XYZ.BasisZ; XYZ viewdir = walldir.CrossProduct(up); Transform t = Transform.Identity; t.Origin = midpoint; t.BasisX = walldir; t.BasisY = up; t.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = t; sectionBox.Min = min; // scope box start sectionBox.Max = max; // scope box end ViewFamilyType vft = viewFamilyType(doc); View viewTemplate = libGet.GetViewTemplate(doc, "Z-ELEV ARCH OFF"); ViewSection vs = null; //Create wall section view using (Transaction tx = new Transaction(doc)) { try { tx.Start("Create Section"); vs = ViewSection.CreateSection(doc, vft.Id, sectionBox); tx.Commit(); } catch { } } using (Transaction tr = new Transaction(doc)) { try { tr.Start("Apply Structural View Template"); vs.ViewTemplateId = viewTemplate.Id; vs.Scale = 24; tr.Commit(); } catch { } } }
//*****************************CreateSectionPerpendicular()***************************** public void CreateSectionPerpendicular(Document doc, UIDocument uidoc) { // My library LibraryGetItems libGet = new LibraryGetItems(); Element e = libGet.SelectElement(uidoc, doc); Wall wall = null; if (e != null) { wall = e as Wall; } LocationCurve lc = wall.Location as LocationCurve; Transform curveTransform = lc.Curve.ComputeDerivatives(0.5, true); // The transform contains the location curve // mid-point and tangent, and we can obtain // its normal in the XY plane: XYZ origin = curveTransform.Origin; XYZ viewdir = curveTransform.BasisX.Normalize(); XYZ up = XYZ.BasisZ; XYZ right = up.CrossProduct(viewdir); // Set up view transform, assuming wall's "up" // is vertical. For a non-vertical situation // such as section through a sloped floor, the // surface normal would be needed Transform transform = Transform.Identity; transform.Origin = origin; transform.BasisX = right; transform.BasisY = up; transform.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = transform; // Min & Max X values define the section // line length on each side of the wall. // Max Y is the height of the section box. // Max Z (5) is the far clip offset. double d = wall.WallType.Width; BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z; double maxZ = bb.Max.Z; double h = maxZ - minZ; // Z value offset from the current level in view. Level level = doc.ActiveView.GenLevel; double top = 90 - level.Elevation; double bottom = -(level.Elevation + 25); sectionBox.Min = new XYZ(-2 * d, bottom, 0); sectionBox.Max = new XYZ(2 * d, top, 5); ViewFamilyType vft = viewFamilyType(doc); View viewTemplate = libGet.GetViewTemplate(doc, "Z-ELEV ARCH OFF"); ViewSection vs = null; //Create wall section view using (Transaction tx = new Transaction(doc)) { try { tx.Start("Create Section"); vs = ViewSection.CreateSection(doc, vft.Id, sectionBox); doc.Regenerate(); tx.Commit(); } catch { } } using (Transaction t = new Transaction(doc)) { try { t.Start("Apply Structural View Template"); vs.ViewTemplateId = viewTemplate.Id; vs.Scale = 24; t.Commit(); } catch { } } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { #region//Utils StringBuilder sb = new StringBuilder(); Collector collector = new Collector(); LengthUnitConverter converter = new LengthUnitConverter(); #endregion #region//Application context UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; #endregion #region//Check if current project is family if (doc.IsFamilyDocument) { Message.Display("Can't use command in family document", WindowType.Warning); return(Result.Cancelled); } #endregion #region//Select elements List <Element> genericModelList = collector.GetGenericModels(doc); List <Element> List_GenericModels = new List <Element>(); List <string> List_GenericModelStrings = new List <string>(); FamilyInstance familyInstance = null; foreach (Element genericModel in genericModelList) { familyInstance = doc.GetElement(genericModel.Id) as FamilyInstance; if (familyInstance.SuperComponent == null) { if (List_GenericModelStrings.Contains(genericModel.Name)) { } else { List_GenericModels.Add(genericModel); List_GenericModelStrings.Add(genericModel.Name); } } } #endregion #region//Check if list of generic models is empty if (List_GenericModels.Count == 0) { Message.Display("There aren't any generic models in the project", WindowType.Warning); return(Result.Cancelled); } #endregion #region//Execute task for each generic model foreach (Element genericModel in List_GenericModels) { FamilyInstance genericModelFamily = doc.GetElement(genericModel.Id) as FamilyInstance; FamilySymbol genericModelSymbol = genericModelFamily.Symbol; #region //Get type parameters of element string MDK_merk = genericModelSymbol.LookupParameter("MDK_merk").AsString(); #endregion #region //Get nested family FamilyInstance nestedFamily = null; string nestedFamilyName = "Profiel_1"; List <double> nestedFamilyOriginZ = new List <double>(); List <FamilyInstance> nestedFamilies = new List <FamilyInstance>(); FamilyInstance familyContainer = null; LocationCurve curveContainer = null; Line lineContainer = null; ICollection <ElementId> subComponentIds = genericModelFamily.GetSubComponentIds(); foreach (ElementId id in subComponentIds) { if (doc.GetElement(id).Name == nestedFamilyName) { nestedFamilies.Add(doc.GetElement(id) as FamilyInstance); familyContainer = doc.GetElement(id) as FamilyInstance; curveContainer = familyContainer.Location as LocationCurve; lineContainer = curveContainer.Curve as Line; nestedFamilyOriginZ.Add(lineContainer.Origin.Z); } } double minValue = int.MaxValue; int minIndex; int index = -1; foreach (double num in nestedFamilyOriginZ) { index++; if (num <= minValue) { minValue = num; minIndex = index; } } nestedFamily = nestedFamilies[index]; if (nestedFamily == null) { Message.Display("There isn't a nested family in the element with the specified name.", WindowType.Error); return(Result.Cancelled); } #endregion #region//Get direction of family LocationCurve locationCurve = nestedFamily.Location as LocationCurve; Line locationLine = locationCurve.Curve as Line; XYZ dir = locationLine.Direction.Normalize();; #endregion #region//Create Boundingbox XYZ lineStart = locationLine.GetEndPoint(0); XYZ lineEnd = locationLine.GetEndPoint(1); XYZ lineDifference = lineEnd - lineStart; BoundingBoxXYZ genicModelbb = genericModel.get_BoundingBox(null); double minZ = genicModelbb.Min.Z; double maxZ = genicModelbb.Max.Z; double width = lineDifference.GetLength(); double height = maxZ - minZ; double thickness = converter.ConvertToFeet(500); double offset = converter.ConvertToFeet(500); XYZ min = new XYZ(-width - converter.ConvertToFeet(1000), minZ - offset, -offset); XYZ max = new XYZ(width, maxZ + offset, +offset); XYZ midpoint = lineStart + 0.5 * lineDifference; XYZ up = XYZ.BasisZ; XYZ viewDir = dir.CrossProduct(up); Transform t = Transform.Identity; t.Origin = midpoint; t.BasisX = dir; t.BasisY = up; t.BasisZ = viewDir; BoundingBoxXYZ boundingBox = new BoundingBoxXYZ(); boundingBox.Transform = t; boundingBox.Min = min; boundingBox.Max = max; #endregion #region//Get viewFamilyType ViewFamilyType viewFamily = collector.GetViewFamilyType(doc, ViewFamily.Section).FirstOrDefault(); #endregion #region //Create Section using (Transaction tx = new Transaction(doc)) { tx.Start("Create Section"); ViewSection section = ViewSection.CreateSection(doc, viewFamily.Id, boundingBox); section.Name = genericModel.Name; section.Scale = 50; section.CropBoxVisible = false; section.get_Parameter(BuiltInParameter.SECTION_COARSER_SCALE_PULLDOWN_METRIC).Set(1); section.LookupParameter("Subdiscipline").Set("LEGEND"); tx.Commit(); } #endregion } #endregion #region//Get all section views List <View> sectionViewList = collector.GetViews(doc, ViewType.Section); List <View> List_SectionViews = new List <View>(); foreach (View sectionView in sectionViewList) { if (sectionView.Name.Contains("Kozijn")) { List_SectionViews.Add(sectionView); } } #endregion #region//Execute task for each sectionView foreach (View sectionView in List_SectionViews) { #region//Get DimensionType DimensionType genericModelDimension = collector.GetLinearDimensionTypeByName(doc, "hoofdmaatvoering"); DimensionType nestedFamilyDimension = collector.GetLinearDimensionTypeByName(doc, "stelkozijn"); #endregion #region//Get directions for dimensions XYZ widthDirection = sectionView.RightDirection.Normalize(); XYZ heigthDirection = new XYZ(0, 0, 1); #endregion #region//Select elements List <Element> genericModelInViewList = collector.GetGenericModels(doc, sectionView.Id); List <Element> List_GenericModelsInView = new List <Element>(); FamilyInstance familyInstanceInView = null; foreach (Element genericModel in genericModelInViewList) { familyInstanceInView = doc.GetElement(genericModel.Id) as FamilyInstance; if (familyInstanceInView.SuperComponent == null) { List_GenericModelsInView.Add(genericModel); } } #endregion #region//Execute task for each generic model foreach (Element genericModel in List_GenericModelsInView) { FamilyInstance genericModelFamily = doc.GetElement(genericModel.Id) as FamilyInstance; FamilySymbol genericModelSymbol = genericModelFamily.Symbol; #region//Get nested family 1 string nestedFamilyName1 = "31_MDK_GM_stelkozijn_lijn"; FamilyInstance nestedFamily1 = null; ICollection <ElementId> subComponentIds1 = genericModelFamily.GetSubComponentIds(); foreach (ElementId id in subComponentIds1) { if (doc.GetElement(id).Name == nestedFamilyName1) { nestedFamily1 = doc.GetElement(id) as FamilyInstance; } } #endregion #region//Get nested family 2 FamilyInstance nestedFamily2 = null; string nestedFamilyName2 = "Profiel_1"; List <double> nestedFamilyOriginZ = new List <double>(); List <FamilyInstance> nestedFamilies = new List <FamilyInstance>(); FamilyInstance familyContainer = null; LocationCurve curveContainer = null; Line lineContainer = null; ICollection <ElementId> subComponentIds2 = genericModelFamily.GetSubComponentIds(); foreach (ElementId id in subComponentIds2) { if (doc.GetElement(id).Name == nestedFamilyName2) { nestedFamilies.Add(doc.GetElement(id) as FamilyInstance); familyContainer = doc.GetElement(id) as FamilyInstance; curveContainer = familyContainer.Location as LocationCurve; lineContainer = curveContainer.Curve as Line; nestedFamilyOriginZ.Add(lineContainer.Origin.Z); } } double minValue = int.MaxValue; int minIndex; int index = -1; foreach (double num in nestedFamilyOriginZ) { index++; if (num <= minValue) { minValue = num; minIndex = index; } } nestedFamily2 = nestedFamilies[index]; if (nestedFamily2 == null) { Message.Display("There isn't a nested family in the element with the specified name.", WindowType.Error); return(Result.Cancelled); } #endregion #region//Get type parameters of element double MDK_breedte = genericModelSymbol.LookupParameter("MDK_breedte").AsDouble(); #endregion #region//Get instance parameters of element double MDK_offset_vooraanzicht = genericModelFamily.LookupParameter("MDK_offset_vooraanzicht").AsDouble(); #endregion #region//Get direction of family LocationCurve locationCurve = nestedFamily2.Location as LocationCurve; Line locationLine = locationCurve.Curve as Line; XYZ dir = locationLine.Direction.Normalize();; #endregion #region//Check if generic model is in same direction as view double genericModelAngle = Math.Round(Math.Atan2(dir.Y, dir.X) * (180 / Math.PI), 5); double activeViewAngle = Math.Round(Math.Atan2(widthDirection.Y, widthDirection.X) * (180 / Math.PI), 5); if (genericModelAngle <= 0) { genericModelAngle = genericModelAngle + 180; } else { genericModelAngle = genericModelAngle - 180; } if (genericModelAngle != activeViewAngle) { Message.Display("The generic model isn't parallel to the active view.", WindowType.Error); return(Result.Cancelled); } #endregion #region//Get locationpoint of selected element LocationPoint location = genericModelFamily.Location as LocationPoint; XYZ locationpoint = location.Point; #endregion #region// Get references which refer to the reference planes in the family ReferenceArray genericModelHeightref = new ReferenceArray(); ReferenceArray genericModelWidthref = new ReferenceArray(); ReferenceArray nestedFamilyHeightref = new ReferenceArray(); ReferenceArray nestedFamilyWidthref = new ReferenceArray(); foreach (var e in genericModelFamily.GetReferences(FamilyInstanceReferenceType.Top)) { genericModelHeightref.Append(e); } foreach (var e in genericModelFamily.GetReferences(FamilyInstanceReferenceType.Bottom)) { genericModelHeightref.Append(e); } foreach (var e in genericModelFamily.GetReferences(FamilyInstanceReferenceType.StrongReference)) { genericModelWidthref.Append(e); } foreach (var e in nestedFamily1.GetReferences(FamilyInstanceReferenceType.StrongReference)) { nestedFamilyWidthref.Append(e); } foreach (var e in nestedFamily1.GetReferences(FamilyInstanceReferenceType.Top)) { nestedFamilyHeightref.Append(e); } foreach (var e in nestedFamily1.GetReferences(FamilyInstanceReferenceType.Bottom)) { nestedFamilyHeightref.Append(e); } #endregion #region//Create endpoints for line creation XYZ genericModelHeight = GetDistance(locationpoint, widthDirection, MDK_breedte, 1000); XYZ genericModelWidth = new XYZ(locationpoint.X, locationpoint.Y, locationpoint.Z + MDK_offset_vooraanzicht - converter.ConvertToFeet(1000)); XYZ nestedFamilyHeight = GetDistance(locationpoint, widthDirection, MDK_breedte, 500); XYZ nestedFamilyWidth = new XYZ(locationpoint.X, locationpoint.Y, locationpoint.Z + MDK_offset_vooraanzicht - converter.ConvertToFeet(500)); #endregion #region//Create line for dimension Line genericModelHeightLine = Line.CreateBound(genericModelHeight, genericModelHeight + heigthDirection * 100); Line genericModelWidthLine = Line.CreateBound(genericModelWidth, genericModelWidth + widthDirection * 100); Line nestedFamilyHeightLine = Line.CreateBound(nestedFamilyHeight, nestedFamilyHeight + heigthDirection * 100); Line nestedFamilyWidthLine = Line.CreateBound(nestedFamilyWidth, nestedFamilyWidth + widthDirection * 100); #endregion #region//Create Dimensions using (Transaction tx = new Transaction(doc)) { tx.Start("Create Dimensions"); #region//Create and set workplane to place dimensions on Plane plane = Plane.CreateByNormalAndOrigin(sectionView.ViewDirection, sectionView.Origin); SketchPlane sketchPlane = SketchPlane.Create(doc, plane); sectionView.SketchPlane = sketchPlane; #endregion #region//Create Dimensions doc.Create.NewDimension(sectionView, genericModelHeightLine, genericModelHeightref, genericModelDimension); doc.Create.NewDimension(sectionView, genericModelWidthLine, genericModelWidthref, genericModelDimension); doc.Create.NewDimension(sectionView, nestedFamilyHeightLine, nestedFamilyHeightref, nestedFamilyDimension); doc.Create.NewDimension(sectionView, nestedFamilyWidthLine, nestedFamilyWidthref, nestedFamilyDimension); #endregion tx.Commit(); } #endregion } #endregion } #endregion return(Result.Succeeded); }
private Result mepSection(Document doc, IList <MEPCurve> mep) { //check straight IList <LocationCurve> lc = mep.Select(x => x.Location).Cast <LocationCurve>().ToList(); //duct.Location as LocationCurve; IList <Curve> curve = lc.Select(x => x.Curve).Cast <Curve>().ToList(); //lc.Curve as Curve; if (curve.Count == 0) { TaskDialog.Show("...", "Unable to retrieve wall location line."); return(Result.Failed); } // Determine view family type to use ViewFamilyType vft = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); // Determine section box IList <XYZ> p = curve.Select(x => x.GetEndPoint(0)).ToList(); IList <XYZ> q = curve.Select(x => x.GetEndPoint(1)).ToList(); IList <XYZ> v = q.Zip(p, (x, y) => x - y).ToList(); IList <XYZ> v2 = v.Select(x => x.X).Zip(v.Select(y => y.Y), (x, y) => new XYZ(x, y, 0)).ToList(); //Z => 0 IList <XYZ> allPoints = p.Concat(q).ToList(); //double minAllX = allPoints.Select(x => x.X).Min(); //double minAllY = allPoints.Select(y => y.Y).Min(); //double minAllZ = allPoints.Select(z => z.Z).Min(); //double maxAllX = allPoints.Select(x => x.X).Max(); //double maxAllY = allPoints.Select(y => y.Y).Max(); //double maxAllZ = allPoints.Select(z => z.Z).Max(); IList <BoundingBoxXYZ> boundingBoxes = mep.Select(x => x.get_BoundingBox(doc.ActiveView)).ToList(); double minAllX = boundingBoxes.Select(x => x.Min).Select(x => x.X).Min(); double minAllY = boundingBoxes.Select(x => x.Min).Select(x => x.Y).Min(); double minAllZ = boundingBoxes.Select(x => x.Min).Select(x => x.Z).Min(); double maxAllX = boundingBoxes.Select(x => x.Max).Select(x => x.X).Max(); double maxAllY = boundingBoxes.Select(x => x.Max).Select(x => x.Y).Max(); double maxAllZ = boundingBoxes.Select(x => x.Max).Select(x => x.Z).Max(); XYZ minAll = new XYZ(minAllX, minAllY, minAllZ); XYZ maxAll = new XYZ(maxAllX, maxAllY, maxAllZ); minAll.Normalize(); maxAll.Normalize(); BoundingBoxXYZ boundingBoxAll = new BoundingBoxXYZ(); boundingBoxAll.Min = minAll; boundingBoxAll.Max = maxAll; //t.Origin = midpoint; //t.BasisX = ductdir; //t.BasisY = up; //t.BasisZ = viewdir; Transform transform = boundingBoxAll.Transform; //boundingBoxAll.Transform = Transform.CreateRotation(XYZ.BasisX, 4.71); //transform.BasisY = XYZ.BasisZ; //Transform transformAll = boundingBoxAll.Transform; try { using (Transaction t = new Transaction(doc, "View Section")) { t.Start(); viewSec = ViewSection.CreateSection(doc, vft.Id, boundingBoxAll); t.Commit(); } } catch (Exception ex) { TaskDialog.Show("O", ex.Message); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { using (Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "InsertSection")) { try { bool isValidSelect = false; do { Reference selectedObject = commandData.Application.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, "Select door!"); if (selectedObject != null) { Element element = commandData.Application.ActiveUIDocument.Document.GetElement(selectedObject.ElementId); ElementType elementType = commandData.Application.ActiveUIDocument.Document.GetElement(element.GetTypeId()) as ElementType; double height = elementType.get_Parameter(BuiltInParameter.DOOR_HEIGHT).AsDouble(); double width = elementType.get_Parameter(BuiltInParameter.DOOR_WIDTH).AsDouble(); FamilyInstance familyInstance = element as FamilyInstance; if (height == 0) { height = familyInstance.get_Parameter(BuiltInParameter.DOOR_HEIGHT).AsDouble(); } if (width == 0) { width = familyInstance.get_Parameter(BuiltInParameter.DOOR_WIDTH).AsDouble(); } Transform doorTransform = familyInstance.get_Geometry(new Options()).Select(s => s as GeometryInstance).Select(y => y.Transform).FirstOrDefault(); if (element.Category.Name == "Doors") { Document doc = commandData.Application.ActiveUIDocument.Document; View view = doc.ActiveView; ViewFamilyType viewFamilyType = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().Where(t => t.ViewFamily == ViewFamily.Section).FirstOrDefault(); if (viewFamilyType == null) { return(Result.Failed); } Transform curveTransform = doorTransform; curveTransform.BasisX = new XYZ(curveTransform.BasisX.Y, curveTransform.BasisX.X, curveTransform.BasisX.Z); XYZ origin = curveTransform.Origin; // mid-point of location curve XYZ viewDirection = curveTransform.BasisX.Normalize(); // tangent vector along the location curve XYZ normal = viewDirection.CrossProduct(XYZ.BasisZ).Normalize(); // location curve normal @ mid-point Transform transform = Transform.Identity; transform.Origin = origin; transform.BasisX = normal; transform.BasisY = XYZ.BasisZ; // can use this simplification because wall's "up" is vertical. // For a non-vertical situation (such as section through a sloped floor the surface normal would be needed) transform.BasisZ = normal.CrossProduct(XYZ.BasisZ); BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = transform; sectionBox.Min = new XYZ(-(width / 2), 0, 0); sectionBox.Max = new XYZ(width / 2, height, 5); transaction.Start(); ViewSection viewSection = ViewSection.CreateSection(doc, viewFamilyType.Id, sectionBox); transaction.Commit(); isValidSelect = true; } else { TaskDialog.Show("Error", "It is not door!"); } } else { TaskDialog.Show("Error", "It is not object!"); } } while (!isValidSelect); } catch (Exception e) { return(Result.Failed); } } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; IEnumerable <ElementId> selElSet = uidoc.Selection.GetElementIds(); IList <double> XX = new List <double>(), YY = new List <double>(), ZZ = new List <double>(); XX.Clear(); YY.Clear(); ZZ.Clear(); if (selElSet.Count().Equals(0)) { return(Result.Failed); } foreach (ElementId elll in selElSet) { double n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Min.X; XX.Add(n); n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Max.X; XX.Add(n); n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Min.Y; YY.Add(n); n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Max.Y; YY.Add(n); n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Min.Z; ZZ.Add(n); n = doc.GetElement(elll).get_BoundingBox(doc.ActiveView).Max.Z; ZZ.Add(n); } FilteredElementCollector lvlcol = new FilteredElementCollector(doc). OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType(); double minElevation = 0, maxElevation = 0; foreach (Level lvl in lvlcol) { if (lvl.Elevation > maxElevation) { maxElevation = lvl.Elevation; } if (lvl.Elevation < minElevation) { minElevation = lvl.Elevation; } } XYZ min = new XYZ(XX.Min(), YY.Min(), minElevation - 5); XYZ max = new XYZ(XX.Max(), YY.Max(), maxElevation + 5); if (max.Subtract(min).GetLength() < 5) { min.Add(min.Multiply(1.5)); max.Add(max.Multiply(1.5)); } Transform t = Transform.Identity; t.BasisX = XYZ.BasisX; t.BasisY = XYZ.BasisY; t.BasisZ = XYZ.BasisZ; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = t; sectionBox.Min = min; sectionBox.Max = max; ViewFamilyType vft = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); using (Transaction tx = new Transaction(doc)) { tx.Start("Create Section View"); View Myview = ViewSection.CreateSection(doc, vft.Id, sectionBox); #region Test/////////////////3D ViewFamilyType vft3d = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault <ViewFamilyType>(x => ViewFamily.ThreeDimensional == x.ViewFamily); View3D view3dEX = View3D.CreateIsometric(doc, vft3d.Id); view3dEX.SetSectionBox(sectionBox); #endregion tx.Commit(); uidoc.ActiveView = view3dEX; } return(Result.Succeeded); }