/// <summary> /// This method is used to create ReferencePlane along to a host referenceplane with a offset parameter /// </summary> /// <param name="doc">the document</param> /// <param name="host">the host ReferencePlane</param> /// <param name="view">the view</param> /// <param name="offSet">the offset of the host</param> /// <param name="cutVec">the cutVec of the ReferencePlane</param> /// <param name="name">the name of the ReferencePlane</param> /// <returns>ReferencePlane</returns> public ReferencePlane Create(Document doc, ReferencePlane host, View view, Autodesk.Revit.DB.XYZ offSet, Autodesk.Revit.DB.XYZ cutVec, string name) { Autodesk.Revit.DB.XYZ bubbleEnd = new Autodesk.Revit.DB.XYZ (); Autodesk.Revit.DB.XYZ freeEnd = new Autodesk.Revit.DB.XYZ (); ReferencePlane refPlane; try { refPlane = host as ReferencePlane; if (refPlane != null) { bubbleEnd = refPlane.BubbleEnd.Add(offSet); freeEnd = refPlane.FreeEnd.Add(offSet); SubTransaction subTransaction = new SubTransaction(doc); subTransaction.Start(); refPlane = doc.FamilyCreate.NewReferencePlane(bubbleEnd, freeEnd, cutVec, view); refPlane.Name = name; subTransaction.Commit(); } return refPlane; } catch { return null; } }
/// <summary> /// This method is used to create dimension among three reference planes /// </summary> /// <param name="view">the view</param> /// <param name="refPlane1">the first reference plane</param> /// <param name="refPlane2">the second reference plane</param> /// <param name="refPlane">the middle reference plane</param> /// <returns>the new dimension</returns> public Dimension AddDimension(View view, ReferencePlane refPlane1, ReferencePlane refPlane2, ReferencePlane refPlane) { Dimension dim; Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ (); Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ (); Line line; Reference ref1; Reference ref2; Reference ref3; ReferenceArray refArray = new ReferenceArray(); ref1 = refPlane1.Reference; ref2 = refPlane2.Reference; ref3 = refPlane.Reference; startPoint = refPlane1.FreeEnd; endPoint = refPlane2.FreeEnd; line = m_application.Create.NewLineBound(startPoint, endPoint); if (null != ref1 && null != ref2 && null != ref3) { refArray.Append(ref1); refArray.Append(ref3); refArray.Append(ref2); } SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); dim = m_document.FamilyCreate.NewDimension(view, line, refArray); subTransaction.Commit(); return dim; }
/// <summary> /// Create a extrusion roof. /// </summary> /// <param name="profile">The profile combined of straight lines and arcs.</param> /// <param name="refPlane">The reference plane for the extrusion roof.</param> /// <param name="level">The reference level of the roof to be created.</param> /// <param name="roofType">The type of the newly created roof.</param> /// <param name="extrusionStart">The extrusion start point.</param> /// <param name="extrusionEnd">The extrusion end point.</param> /// <returns>Return a new created extrusion roof.</returns> public ExtrusionRoof CreateExtrusionRoof(CurveArray profile, ReferencePlane refPlane, Level level, RoofType roofType, double extrusionStart, double extrusionEnd) { ExtrusionRoof extrusionRoof = null; Transaction createRoofTransaction = new Transaction(m_commandData.Application.ActiveUIDocument.Document, "ExtrusionRoof"); createRoofTransaction.Start(); try { extrusionRoof = m_creationDoc.NewExtrusionRoof(profile, refPlane, level, roofType, extrusionStart, extrusionEnd); createRoofTransaction.Commit(); } catch (System.Exception e) { createRoofTransaction.RollBack(); throw e; } return extrusionRoof; }
// ====================================== // (2) add alignments // ====================================== void addAlignments(Extrusion pBox) { // // (1) we want to constrain the upper face of the column to the "Upper Ref Level" // // which direction are we looking at? // View pView = findElement(typeof(View), "Front") as View; // find the upper ref level // findElement() is a helper function. see below. // Level upperLevel = findElement(typeof(Level), "Upper Ref Level") as Level; Reference ref1 = upperLevel.PlaneReference; // find the face of the box // findFace() is a helper function. see below. // PlanarFace upperFace = findFace(pBox, new XYZ(0.0, 0.0, 1.0)); // find a face whose normal is z-up. Reference ref2 = upperFace.Reference; // create alignments // _doc.FamilyCreate.NewAlignment(pView, ref1, ref2); // // (2) do the same for the lower level // // find the lower ref level // findElement() is a helper function. see below. // Level lowerLevel = findElement(typeof(Level), "Lower Ref. Level") as Level; Reference ref3 = lowerLevel.PlaneReference; // find the face of the box // findFace() is a helper function. see below. PlanarFace lowerFace = findFace(pBox, new XYZ(0.0, 0.0, -1.0)); // find a face whose normal is z-down. Reference ref4 = lowerFace.Reference; // create alignments // _doc.FamilyCreate.NewAlignment(pView, ref3, ref4); // // (3) same idea for the Right/Left/Front/Back // // get the plan view // note: same name maybe used for different view types. either one should work. View pViewPlan = findElement(typeof(ViewPlan), "Lower Ref. Level") as View; // find reference planes ReferencePlane refRight = findElement(typeof(ReferencePlane), "Right") as ReferencePlane; ReferencePlane refLeft = findElement(typeof(ReferencePlane), "Left") as ReferencePlane; ReferencePlane refFront = findElement(typeof(ReferencePlane), "Front") as ReferencePlane; ReferencePlane refBack = findElement(typeof(ReferencePlane), "Back") as ReferencePlane; // find the face of the box PlanarFace faceRight = findFace(pBox, new XYZ(1.0, 0.0, 0.0)); PlanarFace faceLeft = findFace(pBox, new XYZ(-1.0, 0.0, 0.0)); PlanarFace faceFront = findFace(pBox, new XYZ(0.0, -1.0, 0.0)); PlanarFace faceBack = findFace(pBox, new XYZ(0.0, 1.0, 0.0)); // create alignments // _doc.FamilyCreate.NewAlignment(pViewPlan, refRight.Reference, faceRight.Reference); _doc.FamilyCreate.NewAlignment(pViewPlan, refLeft.Reference, faceLeft.Reference); _doc.FamilyCreate.NewAlignment(pViewPlan, refFront.Reference, faceFront.Reference); _doc.FamilyCreate.NewAlignment(pViewPlan, refBack.Reference, faceBack.Reference); }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="referencePlane"></param> /// <returns></returns> private static Revit.Element CloneElement( Autodesk.Revit.UI.UIApplication app, ReferencePlane referencePlane ) { ReferencePlane referencePlaneClone = app.ActiveUIDocument.Document.Create.NewReferencePlane( referencePlane.BubbleEnd, referencePlane.FreeEnd, referencePlane.Normal, app.ActiveUIDocument.Document.ActiveView ); // TBD: ReferencePlane.View dissappeared (jma - 12/05/06) Utils.ParamUtil.SetParameters( referencePlaneClone.Parameters, referencePlane.Parameters ); return referencePlaneClone; }
/// <summary> /// The implementation of CreateFrame() /// </summary> public override void CreateFrame() { SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); //create sash referenceplane and exterior referenceplane CreateRefPlane refPlaneCreator = new CreateRefPlane(); if (m_sashPlane == null) { m_sashPlane = refPlaneCreator.Create(m_document, m_centerPlane, m_rightView, new Autodesk.Revit.DB.XYZ(0, m_wallThickness / 2 - m_windowInset, 0), new Autodesk.Revit.DB.XYZ(0, 0, 1), "Sash"); } if (m_exteriorPlane == null) { m_exteriorPlane = refPlaneCreator.Create(m_document, m_centerPlane, m_rightView, new Autodesk.Revit.DB.XYZ(0, m_wallThickness / 2, 0), new Autodesk.Revit.DB.XYZ(0, 0, 1), "MyExterior"); } m_document.Regenerate(); //get the wall in the document and retrieve the exterior face List <Wall> walls = Utility.GetElements <Wall>(m_application, m_document); Face exteriorWallFace = GeoHelper.GetWallFace(walls[0], m_rightView, true); if (exteriorWallFace == null) { return; } //add dimension between sash reference plane and wall face,and add parameter "Window Inset",label the dimension with window-inset parameter Dimension windowInsetDimension = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, exteriorWallFace); FamilyParameter windowInsetPara = m_familyManager.AddParameter("Window Inset", BuiltInParameterGroup.INVALID, ParameterType.Length, false); m_familyManager.Set(windowInsetPara, m_windowInset); windowInsetDimension.FamilyLabel = windowInsetPara; //create the exterior frame double frameCurveOffset1 = 0.075; CurveArray curveArr1 = m_extrusionCreator.CreateRectangle(m_width / 2, -m_width / 2, m_sillHeight + m_height, m_sillHeight, 0); CurveArray curveArr2 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr1, frameCurveOffset1); CurveArrArray curveArrArray1 = new CurveArrArray(); curveArrArray1.Append(curveArr1); curveArrArray1.Append(curveArr2); Extrusion extFrame = m_extrusionCreator.NewExtrusion(curveArrArray1, m_sashPlane, m_wallThickness / 2 + m_wallThickness / 12, -m_windowInset); extFrame.SetVisibility(CreateVisibility()); m_document.Regenerate(); //add alignment between wall face and exterior frame face exteriorWallFace = GeoHelper.GetWallFace(walls[0], m_rightView, true); // Get the face again as the document is regenerated. Face exteriorExtrusionFace1 = GeoHelper.GetExtrusionFace(extFrame, m_rightView, true); Face interiorExtrusionFace1 = GeoHelper.GetExtrusionFace(extFrame, m_rightView, false); CreateAlignment alignmentCreator = new CreateAlignment(m_document); alignmentCreator.AddAlignment(m_rightView, exteriorWallFace, exteriorExtrusionFace1); //add dimension between sash referenceplane and exterior frame face and lock the dimension Dimension extFrameWithSashPlane = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, interiorExtrusionFace1); extFrameWithSashPlane.IsLocked = true; m_document.Regenerate(); //create the interior frame double frameCurveOffset2 = 0.125; CurveArray curveArr3 = m_extrusionCreator.CreateRectangle(m_width / 2, -m_width / 2, m_sillHeight + m_height, m_sillHeight, 0); CurveArray curveArr4 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr3, frameCurveOffset2); m_document.Regenerate(); CurveArrArray curveArrArray2 = new CurveArrArray(); curveArrArray2.Append(curveArr3); curveArrArray2.Append(curveArr4); Extrusion intFrame = m_extrusionCreator.NewExtrusion(curveArrArray2, m_sashPlane, m_wallThickness - m_windowInset, m_wallThickness / 2 + m_wallThickness / 12); intFrame.SetVisibility(CreateVisibility()); m_document.Regenerate(); //add alignment between interior face of wall and interior frame face Face interiorWallFace = GeoHelper.GetWallFace(walls[0], m_rightView, false); Face interiorExtrusionFace2 = GeoHelper.GetExtrusionFace(intFrame, m_rightView, false); Face exteriorExtrusionFace2 = GeoHelper.GetExtrusionFace(intFrame, m_rightView, true); alignmentCreator.AddAlignment(m_rightView, interiorWallFace, interiorExtrusionFace2); //add dimension between sash referenceplane and interior frame face and lock the dimension Dimension intFrameWithSashPlane = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, exteriorExtrusionFace2); intFrameWithSashPlane.IsLocked = true; //create the sill frame CurveArray sillCurs = m_extrusionCreator.CreateRectangle(m_width / 2, -m_width / 2, m_sillHeight + frameCurveOffset1, m_sillHeight, 0); CurveArrArray sillCurveArray = new CurveArrArray(); sillCurveArray.Append(sillCurs); Extrusion sillFrame = m_extrusionCreator.NewExtrusion(sillCurveArray, m_sashPlane, -m_windowInset, -m_windowInset - 0.1); m_document.Regenerate(); //add alignment between wall face and sill frame face exteriorWallFace = GeoHelper.GetWallFace(walls[0], m_rightView, true); // Get the face again as the document is regenerated. Face sillExtFace = GeoHelper.GetExtrusionFace(sillFrame, m_rightView, false); alignmentCreator.AddAlignment(m_rightView, sillExtFace, exteriorWallFace); m_document.Regenerate(); //set subcategories of the frames if (m_frameCat != null) { extFrame.Subcategory = m_frameCat; intFrame.Subcategory = m_frameCat; sillFrame.Subcategory = m_frameCat; } subTransaction.Commit(); }
/***************************************************/ private static FamilyInstance FamilyInstance_WorkPlaneBased(Document document, FamilySymbol familySymbol, XYZ origin, Transform orientation, Element host, RevitSettings settings) { if (host != null) { Reference reference; bool closest; XYZ location = host.ClosestPointOn(origin, out reference, out closest, orientation?.BasisZ, settings); if (location == null || reference == null) { return(null); } XYZ refDir = XYZ.BasisX; if (orientation?.BasisX != null) { refDir = orientation.BasisX; if (orientation.BasisZ.DotProduct(orientation.BasisX.CrossProduct(orientation.BasisY)) < 0) { refDir = -refDir; } } FamilyInstance familyInstance = document.Create.NewFamilyInstance(reference, location, refDir, familySymbol); if (familyInstance == null) { return(null); } document.Regenerate(); if (orientation?.BasisZ != null && 1 - Math.Abs(familyInstance.GetTotalTransform().BasisZ.DotProduct(orientation.BasisZ.Normalize())) > settings.AngleTolerance) { BH.Engine.Reflection.Compute.RecordWarning($"The orientation used to create the family instance was not perpendicular to the face on which the instance was placed. The orientation out of plane has been ignored. ElementId: {familyInstance.Id.IntegerValue}"); } if (!closest) { BH.Engine.Reflection.Compute.RecordWarning($"The location point of the created family instance has been snapped to the closest host element's face with normal matching the local Z of the BHoM object's orientation, skipping closer faces with non-matching normals. ElementId: {familyInstance.Id.IntegerValue}"); } else if (origin.DistanceTo(location) > settings.DistanceTolerance) { BH.Engine.Reflection.Compute.RecordWarning($"The location point of the created family instance has been snapped to the closest face of the host element. ElementId: {familyInstance.Id.IntegerValue}"); } return(familyInstance); } else { Reference reference; if (orientation?.BasisZ != null && 1 - Math.Abs(orientation.BasisZ.DotProduct(XYZ.BasisZ)) > settings.AngleTolerance) { ReferencePlane rp = Create.ReferencePlane(document, origin, orientation); reference = rp?.GetReference(); } else { reference = document.LevelBelow(origin, settings).GetPlaneReference(); } XYZ refDir = XYZ.BasisX; if (orientation?.BasisX != null) { refDir = orientation.BasisX; if (orientation.BasisZ.DotProduct(orientation.BasisX.CrossProduct(orientation.BasisY)) < 0) { refDir = -refDir; } } FamilyInstance familyInstance = document.Create.NewFamilyInstance(reference, origin, refDir, familySymbol); if (familyInstance == null) { return(null); } if (document.GetElement(reference.ElementId) is ReferencePlane) { familyInstance.ReferencePlaneCreatedWarning(); } return(familyInstance); } }
// ===================================================================== // (5.1.1) create simple line objects to be displayed in coarse level // ===================================================================== public void addLineObjects() { // // define a simple L-shape detail line object // // 0 // + h = height // | (we also want to draw a vertical line here at point 1) // d | // +-----+ // 1 2 // w // // sizes double w = mmToFeet(600.0); // modified to match reference plane. otherwise, alignment won't work. double d = mmToFeet(600.0); double h = mmToFeet(4000.0); // distance between Lower and Upper Ref Level. double t = mmToFeet(50.0); // slight offset for visbility // define vertices // XYZ[] pts = new XYZ[] { new XYZ((-w / 2.0) + t, d / 2.0, 0.0), new XYZ((-w / 2.0) + t, (-d / 2.0) + t, 0.0), new XYZ(w / 2.0, (-d / 2.0) + t, 0.0) }; XYZ ptH = new XYZ((-w / 2.0) + t, (-d / 2.0) + t, h); // this is for vertical line. // // (2) create a sketch plane // // we need to know the template. If you look at the template (Metric Column.rft) and "Front" view, // you will see "Reference Plane" at "Lower Ref. Level". We are going to create a sketch plane there. // findElement() is a helper function that find an element of the given type and name. see below. // Note: we did the same in creating a profile. // ReferencePlane pRefPlane = findElement(typeof(ReferencePlane), "Reference Plane") as ReferencePlane; //SketchPlane pSketchPlane = _doc.FamilyCreate.NewSketchPlane(pRefPlane.Plane); // Revit 2013 //SketchPlane pSketchPlane = SketchPlane.Create(_doc, pRefPlane.Plane); // Revit 2014 SketchPlane pSketchPlane = SketchPlane.Create(_doc, pRefPlane.GetPlane()); // Revit 2016 // for vertical line, we draw a straight vertical line at the point[1] XYZ normal = new XYZ(1.0, 0.0, 0.0); //Plane pGeomPlaneH = _app.Create.NewPlane( normal, pts[1] ); // Revit 2016 Plane pGeomPlaneH = Plane.CreateByNormalAndOrigin(normal, pts[1]); // Revit 2017 //SketchPlane pSketchPlaneH = _doc.FamilyCreate.NewSketchPlane(pGeomPlaneH); // Revit 2013 SketchPlane pSketchPlaneH = SketchPlane.Create(_doc, pGeomPlaneH); // Revit 2014 // (3) create line objects: two symbolic curves on a plan and one model curve representing a column like a vertical stick. // // Revit 2013 //Line geomLine1 = _app.Create.NewLine(pts[0], pts[1], true); //Line geomLine2 = _app.Create.NewLine(pts[1], pts[2], true); //Line geomLineH = _app.Create.NewLine(pts[1], ptH, true); // Revit 2014 Line geomLine1 = Line.CreateBound(pts[0], pts[1]); Line geomLine2 = Line.CreateBound(pts[1], pts[2]); //Line geomLineH = _app.Create.NewLine(pts[1], ptH, true); // Revit 2013 Line geomLineH = Line.CreateBound(pts[1], ptH); SymbolicCurve pLine1 = _doc.FamilyCreate.NewSymbolicCurve(geomLine1, pSketchPlane); SymbolicCurve pLine2 = _doc.FamilyCreate.NewSymbolicCurve(geomLine2, pSketchPlane); ModelCurve pLineH = _doc.FamilyCreate.NewModelCurve(geomLineH, pSketchPlaneH); // this is vertical line // set the visibilities of two lines to coarse only // FamilyElementVisibility pVis = new FamilyElementVisibility(FamilyElementVisibilityType.ViewSpecific); pVis.IsShownInFine = false; pVis.IsShownInMedium = false; pLine1.SetVisibility(pVis); pLine2.SetVisibility(pVis); FamilyElementVisibility pVisH = new FamilyElementVisibility(FamilyElementVisibilityType.Model); pVisH.IsShownInFine = false; pVisH.IsShownInMedium = false; pLineH.SetVisibility(pVisH); }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="element"></param> /// <returns></returns> public static Revit.Element CloneElement(Application app, Revit.Element element) { Opening opening = element as Opening; if (opening != null) { return(CloneElement(app, opening)); } BoundaryConditions boundaryConditions = element as BoundaryConditions; if (boundaryConditions != null) { return(CloneElement(app, boundaryConditions)); } AreaLoad areaLoad = element as AreaLoad; if (areaLoad != null) { return(CloneElement(app, areaLoad)); } AreaReinforcement areaReinforcement = element as AreaReinforcement; if (areaReinforcement != null) { return(CloneElement(app, areaReinforcement)); } BeamSystem beamSystem = element as BeamSystem; if (beamSystem != null) { return(CloneElement(app, beamSystem)); } Dimension dimension = element as Dimension; if (dimension != null) { return(CloneElement(app, dimension)); } FamilyInstance familyInstance = element as FamilyInstance; if (familyInstance != null) { return(CloneElement(app, familyInstance)); } Floor floor = element as Floor; if (floor != null) { return(CloneElement(app, floor)); } Grid grid = element as Grid; if (grid != null) { return(CloneElement(app, grid)); } Group group = element as Group; if (group != null) { return(CloneElement(app, group)); } Level level = element as Level; if (floor != null) { return(CloneElement(app, floor)); } LineLoad lineLoad = element as LineLoad; if (lineLoad != null) { return(CloneElement(app, lineLoad)); } LoadCase loadCase = element as LoadCase; if (loadCase != null) { return(CloneElement(app, loadCase)); } LoadCombination loadCombination = element as LoadCombination; if (loadCombination != null) { return(CloneElement(app, loadCombination)); } LoadNature loadNature = element as LoadNature; if (loadNature != null) { return(CloneElement(app, loadNature)); } LoadUsage loadUsage = element as LoadUsage; if (loadUsage != null) { return(CloneElement(app, loadUsage)); } ModelCurve modelCurve = element as ModelCurve; if (modelCurve != null) { return(CloneElement(app, modelCurve)); } PointLoad pointLoad = element as PointLoad; if (pointLoad != null) { return(CloneElement(app, pointLoad)); } Rebar rebar = element as Rebar; if (rebar != null) { return(CloneElement(app, rebar)); } ReferencePlane referencePlane = element as ReferencePlane; if (referencePlane != null) { return(CloneElement(app, referencePlane)); } Room room = element as Room; if (room != null) { return(CloneElement(app, room)); } RoomTag roomTag = element as RoomTag; if (roomTag != null) { return(CloneElement(app, roomTag)); } SketchPlane sketchPlane = element as SketchPlane; if (sketchPlane != null) { return(CloneElement(app, sketchPlane)); } View3D view3D = element as View3D; if (view3D != null) { return(CloneElement(app, view3D)); } ViewDrafting viewDrafting = element as ViewDrafting; if (viewDrafting != null) { return(CloneElement(app, viewDrafting)); } ViewSection viewSection = element as ViewSection; if (viewSection != null) { return(CloneElement(app, viewSection)); } ViewSheet viewSheet = element as ViewSheet; if (viewSheet != null) { return(CloneElement(app, viewSheet)); } Wall wall = element as Wall; if (wall != null) { return(CloneElement(app, wall)); } // this element has not yet been exposed in the Creation Document class //Debug.Assert(false); return(null); }
public void ByStartPointEndPoint_NullInputBoth() { Assert.Throws(typeof(System.ArgumentNullException), () => ReferencePlane.ByStartPointEndPoint(null, null)); }
/// <summary> /// Factory method obtaining Custom Asteroids settings from KSP config state. /// </summary> /// /// <returns>A newly constructed ReferenceLoader object containing a full list /// of all valid reference planes in asteroid config files.</returns> /// /// <exception cref="TypeInitializationException">Thrown if the ReferenceLoader /// object could not be constructed. The program is in a consistent state in the event of /// an exception.</exception> internal static ReferenceLoader load() { try { // Start with an empty population list ReferenceLoader allRefs = new ReferenceLoader(); // Search for reference planes in all config files UrlDir.UrlConfig [] configList = GameDatabase.Instance.GetConfigs("CustomAsteroidPlanes"); foreach (UrlDir.UrlConfig curSet in configList) { allRefs.defaultRef = curSet.config.GetValue("defaultRef"); foreach (ConfigNode curNode in curSet.config.nodes) { #if DEBUG Debug.Log("[CustomAsteroids]: " + Localizer.Format("#autoLOC_CustomAsteroids_LogConfig", curNode)); #endif try { ReferencePlane plane = null; switch (curNode.name) { case "REFPLANE": plane = new RefAsOrbit(); break; case "REFVECTORS": plane = new RefVectors(); break; // silently ignore any other nodes present } if (plane != null) { ConfigNode.LoadObjectFromConfig(plane, curNode); allRefs.refs.Add(plane); } } catch (Exception e) { var nodeName = curNode.GetValue("name"); var error = Localizer.Format( "#autoLOC_CustomAsteroids_ErrorLoadRefPlane", nodeName); Debug.LogError("[CustomAsteroids]: " + error); Debug.LogException(e); Util.errorToPlayer(e, error); } // Attempt to parse remaining populations } } #if DEBUG foreach (ReferencePlane x in allRefs.refs) { Debug.Log($"[CustomAsteroids]: " + Localizer.Format("#autoLOC_CustomAsteroids_LogLoadRefPlane", x)); } #endif if (allRefs.defaultRef != null && allRefs.getReferenceSet() == null) { string error = Localizer.Format( "#autoLOC_CustomAsteroids_ErrorNoDefaultPlane", allRefs.defaultRef); Debug.LogError($"[CustomAsteroids]: " + error); Util.errorToPlayerLoc(error); allRefs.defaultRef = null; } return(allRefs); } catch (Exception e) { throw new TypeInitializationException( "Starstrider42.CustomAsteroids.ReferenceLoader", e); } }
private bool CreateCommon() { // Get reference planes List <ReferencePlane> planes = Utility.GetElements <ReferencePlane>(app, doc); foreach (ReferencePlane plane in planes) { if (plane.Name.Equals("Center (Front/Back)")) { centerPlane = plane; } if (plane.Name.Equals("Top") || plane.Name.Equals("Head")) { topPlane = plane; } if (plane.Name.Equals("Bottom") || plane.Name.Equals("Sill")) { bottomPlane = plane; } if (plane.Name.Equals("Left")) { leftPlane = plane; } if (plane.Name.Equals("Right")) { rightPlane = plane; } } // Get views List <View> views = Utility.GetElements <View>(app, doc); foreach (View view in views) { if (view.Name.Equals("Right")) { rightView = view; } if (view.Name.Equals("Left")) { leftView = view; } if (view.Name.Equals("Exterior")) { exteriorView = view; } if (view.Name.Equals("Interior")) { interiorView = view; } } // Get Wall List <Wall> walls = Utility.GetElements <Wall>(app, doc); wall = walls[0]; if (wall == null) { return(false); } // Get wall exterior face exteriorWallFace = GeoHelper.GetWallFace(wall, rightView, WallSide.Exterior); // Get wall interior face interiorWallFace = GeoHelper.GetWallFace(wall, rightView, WallSide.Interior); Debug.WriteLine("\n=======\n"); Debug.WriteLine(String.Format("centerPlane: {0}", centerPlane)); Debug.WriteLine(String.Format("topPlane: {0}", topPlane)); Debug.WriteLine(String.Format("bottomPlane: {0}", bottomPlane)); Debug.WriteLine(String.Format("wall: {0}", wall)); Debug.WriteLine(String.Format("exteriorWallFace: {0}", exteriorWallFace)); Debug.WriteLine(String.Format("interiorWallFace: {0}", interiorWallFace)); Debug.WriteLine(String.Format("rightView: {0}", rightView)); Debug.WriteLine(String.Format("leftView: {0}", leftView)); return(true); }
XYZ GetDimensionStartPointFirstAttempt( Dimension dim) { Document doc = dim.Document; Line dimLine = dim.Curve as Line; if (dimLine == null) { return(null); } dimLine.MakeBound(0, 1); XYZ dimStartPoint = null; XYZ pt1 = dimLine.GetEndPoint(0); // dim.Origin throws "Cannot access this method // if this dimension has more than one segment." //Debug.Assert( Util.IsEqual( pt1, dim.Origin ), // "expected equal points" ); foreach (Reference ref1 in dim.References) { XYZ refPoint = null; Element el = doc.GetElement(ref1.ElementId); GeometryObject obj = el.GetGeometryObjectFromReference( ref1); if (obj == null) { // element is Grid or ReferencePlane or ?? ReferencePlane refPl = el as ReferencePlane; if (refPl != null) { refPoint = refPl.GetPlane().Origin; } Grid grid = el as Grid; if (grid != null) { refPoint = grid.Curve.GetEndPoint(0); } } else { // reference to Line, Plane or Point? Line l = obj as Line; if (l != null) { refPoint = l.GetEndPoint(0); } PlanarFace f = obj as PlanarFace; if (f != null) { refPoint = f.Origin; } } if (refPoint != null) { //View v = doc.ActiveView; View v = dim.View; Plane WorkPlane = v.SketchPlane.GetPlane(); XYZ normal = WorkPlane.Normal.Normalize(); // Project the "globalpoint" of the reference onto the sketchplane XYZ refPtonPlane = refPoint.Subtract( normal.Multiply(normal.DotProduct( refPoint - WorkPlane.Origin))); XYZ lineNormal = normal.CrossProduct( dimLine.Direction).Normalize(); // Project the result onto the dimensionLine dimStartPoint = refPtonPlane.Subtract( lineNormal.Multiply(lineNormal.DotProduct( refPtonPlane - pt1))); } break; } return(dimStartPoint); }
/// <summary> /// Creates a new extrusion roof. /// </summary> /// <param name="doc"></param> /// <param name="profile"></param> /// <param name="plane"></param> /// <param name="lvl"></param> /// <param name="type"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public static ExtrusionRoof AddExtrusionRoof(this Document doc, CurveArray profile, ReferencePlane plane, Level lvl, RoofType type, double start, double end) { return(doc.Create.NewExtrusionRoof(profile, plane, lvl, type, start, end)); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { Application app = commandData.Application.Application; string filename = Path.Combine(_folder, _template); Document familyDoc = app.NewFamilyDocument(filename); Family family = familyDoc.OwnerFamily; Autodesk.Revit.Creation.FamilyItemFactory factory = familyDoc.FamilyCreate; Extrusion extrusion = null; using (Transaction trans = new Transaction( familyDoc)) { trans.Start("Create Extrusion"); XYZ arcCenter = new XYZ(0.0, 3.0, -2.0); // Get the "left" view View view = GetView(ViewType.Elevation, XYZ.BasisY.Negate(), XYZ.BasisZ, familyDoc); // 2D offsets from view 'left' XYZ xOffset = new XYZ(0.0, 10.0, 0.0); XYZ yOffset = new XYZ(0.0, 0.0, -10.0); //################## Reference planes ################################ // Origin's reference planes ReferencePlane referencePlaneOriginX = factory.NewReferencePlane(XYZ.BasisX, XYZ.Zero, XYZ.BasisY, view); referencePlaneOriginX.Name = "ReferencePlane_OriginX"; referencePlaneOriginX.Pinned = true; ReferencePlane referencePlaneOriginY = factory.NewReferencePlane(XYZ.BasisZ, XYZ.Zero, -XYZ.BasisX, view); referencePlaneOriginY.Name = "ReferencePlane_OriginY"; referencePlaneOriginY.Pinned = true; // Reference planes the extruded arc should stick to ReferencePlane referencePlaneX = factory.NewReferencePlane( XYZ.BasisX + yOffset, XYZ.Zero + yOffset, XYZ.BasisY, view); referencePlaneX.Name = "ReferencePlane_X"; ReferencePlane referencePlaneY = factory.NewReferencePlane( XYZ.BasisZ + xOffset, XYZ.Zero + xOffset, -XYZ.BasisX, view); referencePlaneY.Name = "ReferencePlane_Y"; familyDoc.Regenerate(); //################## Create dimensions ############################### // Dimension x ReferenceArray refArrayX = new ReferenceArray(); refArrayX.Append(referencePlaneX.GetReference()); refArrayX.Append(referencePlaneOriginX.GetReference()); Line lineX = Line.CreateUnbound(arcCenter, XYZ.BasisZ); Dimension dimensionX = factory.NewDimension( view, lineX, refArrayX); // Dimension y ReferenceArray refArrayY = new ReferenceArray(); refArrayY.Append(referencePlaneY.GetReference()); refArrayY.Append(referencePlaneOriginY.GetReference()); Line lineY = Line.CreateUnbound(arcCenter, XYZ.BasisY); Dimension dimensionY = factory.NewDimension( view, lineY, refArrayY); familyDoc.Regenerate(); //################## Create arc ###################################### double arcRadius = 1.0; Arc arc = Arc.Create( XYZ.Zero + xOffset + yOffset, arcRadius, 0.0, 2 * Math.PI, XYZ.BasisZ, XYZ.BasisY.Negate()); CurveArray curves = new CurveArray(); curves.Append(arc); CurveArrArray profile = new CurveArrArray(); profile.Append(curves); Plane plane = new Plane(XYZ.BasisX.Negate(), arcCenter); SketchPlane sketchPlane = SketchPlane.Create( familyDoc, plane); Debug.WriteLine("Origin: " + sketchPlane.GetPlane().Origin); Debug.WriteLine("Normal: " + sketchPlane.GetPlane().Normal); Debug.WriteLine("XVec: " + sketchPlane.GetPlane().XVec); Debug.WriteLine("YVec: " + sketchPlane.GetPlane().YVec); extrusion = factory.NewExtrusion(true, profile, sketchPlane, 10); familyDoc.Regenerate(); //################## Add family parameters ########################### FamilyManager fmgr = familyDoc.FamilyManager; FamilyParameter paramX = fmgr.AddParameter("X", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, true); dimensionX.FamilyLabel = paramX; FamilyParameter paramY = fmgr.AddParameter("Y", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, true); dimensionY.FamilyLabel = paramY; // Set their values FamilyType familyType = fmgr.NewType( "Standard"); fmgr.Set(paramX, 10); fmgr.Set(paramY, 10); trans.Commit(); } // Save it to inspect SaveAsOptions opt = new SaveAsOptions(); opt.OverwriteExistingFile = true; filename = Path.Combine(Path.GetTempPath(), "test.rfa"); familyDoc.SaveAs(filename, opt); 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; using (Transaction tx = new Transaction(doc)) { tx.Start("NewExtrusionRoof"); RoofType fs = new FilteredElementCollector(doc) .OfClass(typeof(RoofType)) .Cast <RoofType>() .FirstOrDefault <RoofType>(a => null != a); Level lvl = new FilteredElementCollector(doc) .OfClass(typeof(Level)) .Cast <Level>() .FirstOrDefault <Level>(a => null != a); double x = 1; XYZ origin = new XYZ(x, 0, 0); XYZ vx = XYZ.BasisY; XYZ vy = XYZ.BasisZ; SketchPlane sp = SketchPlane.Create(doc, new Autodesk.Revit.DB.Plane(vx, vy, origin)); CurveArray ca = new CurveArray(); XYZ[] pts = new XYZ[] { new XYZ(x, 1, 0), new XYZ(x, 1, 1), new XYZ(x, 2, 1), new XYZ(x, 2, 2), new XYZ(x, 3, 2), new XYZ(x, 3, 3), new XYZ(x, 4, 3), new XYZ(x, 4, 4) }; int n = pts.Length; for (int i = 1; i < n; ++i) { ca.Append(Line.CreateBound( pts[i - 1], pts[i])); } doc.Create.NewModelCurveArray(ca, sp); View v = doc.ActiveView; ReferencePlane rp = doc.Create.NewReferencePlane2( origin, origin + vx, origin + vy, v); rp.Name = "MyRoofPlane"; ExtrusionRoof er = doc.Create.NewExtrusionRoof( ca, rp, lvl, fs, 0, 3); Debug.Print("Extrusion roof element id: " + er.Id.ToString()); tx.Commit(); } return(Result.Succeeded); }
/// <summary> /// Delete the given reference plane /// if it is not hosting anything. /// </summary> /// <returns>True if the given reference plane /// was in fact deleted, else false.</returns> bool DeleteIfNotHosting( ReferencePlane rp ) { bool rc = false; Document doc = rp.Document; using( Transaction tx = new Transaction( doc ) ) { tx.Start( "Delete ReferencePlane " + ( ++_i ).ToString() ); // Deletion simply fails if the reference // plane hosts anything. If so, the return // value ids collection is null. // In Revit 2014, in that case, the call // throws an exception "ArgumentException: // ElementId cannot be deleted." try { ICollection<ElementId> ids = doc.Delete( rp.Id ); tx.Commit(); rc = true; } catch( ArgumentException ) { tx.RollBack(); } } return rc; }
// ============================== // (1.1) add reference planes // ============================== void addReferencePlanes() { // // we are defining a simple L-shape profile like the following: // // 5 tw 4 // +-+ // | | 3 h = height // d | +---+ 2 // +-----+ td // 0 1 // 6 w // // // we want to add ref planes along (1) 2-3 and (2)3-4. // Name them "OffsetH" and "OffsetV" respectively. (H for horizontal, V for vertical). // double tw = mmToFeet(150.0); // thickness added for Lab2. Hard-coding for simplicity. double td = mmToFeet(150.0); // // (1) add a horizonal ref plane 2-3. // // get a plan view View pViewPlan = (View)findElement(typeof(ViewPlan), "Lower Ref. Level"); // we have predefined ref plane: Left/Right/Front/Back // get the ref plane at Front, which is aligned to line 2-3 ReferencePlane refFront = (ReferencePlane)findElement(typeof(ReferencePlane), "Front"); // get the bubble and free ends from front ref plane and offset by td. // XYZ p1 = refFront.BubbleEnd; XYZ p2 = refFront.FreeEnd; XYZ pBubbleEnd = new XYZ(p1.X, p1.Y + td, p1.Z); XYZ pFreeEnd = new XYZ(p2.X, p2.Y + td, p2.Z); // create a new one reference plane and name it "OffsetH" // ReferencePlane refPlane = _doc.FamilyCreate.NewReferencePlane(pBubbleEnd, pFreeEnd, XYZ.BasisZ, pViewPlan); refPlane.Name = "OffsetH"; // // (2) do the same to add a vertical reference plane. // // find the ref plane at left, which is aligned to line 3-4 ReferencePlane refLeft = (ReferencePlane)findElement(typeof(ReferencePlane), "Left"); // get the bubble and free ends from front ref plane and offset by td. // p1 = refLeft.BubbleEnd; p2 = refLeft.FreeEnd; pBubbleEnd = new XYZ(p1.X + tw, p1.Y, p1.Z); pFreeEnd = new XYZ(p2.X + tw, p2.Y, p2.Z); // create a new reference plane and name it "OffsetV" // refPlane = _doc.FamilyCreate.NewReferencePlane(pBubbleEnd, pFreeEnd, XYZ.BasisZ, pViewPlan); refPlane.Name = "OffsetV"; }
/// <summary> /// The implementation of CreateFrame() /// </summary> public override void CreateFrame() { SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); //get the wall in the document and retrieve the exterior face List<Wall> walls = Utility.GetElements<Wall>(m_application, m_document); Face exteriorWallFace = GeoHelper.GetWallFace(walls[0], m_rightView, true); //create sash referenceplane and exterior referenceplane CreateRefPlane refPlaneCreator = new CreateRefPlane(); if(m_sashPlane==null) m_sashPlane = refPlaneCreator.Create(m_document, m_centerPlane, m_rightView, new Autodesk.Revit.DB.XYZ (0, m_wallThickness / 2 - m_windowInset, 0), new Autodesk.Revit.DB.XYZ (0, 0, 1), "Sash"); if (m_exteriorPlane==null) m_exteriorPlane = refPlaneCreator.Create(m_document, m_centerPlane, m_rightView, new Autodesk.Revit.DB.XYZ (0, m_wallThickness / 2, 0), new Autodesk.Revit.DB.XYZ (0, 0, 1), "MyExterior"); m_document.Regenerate(); //add dimension between sash reference plane and wall face,and add parameter "Window Inset",label the dimension with window-inset parameter Dimension windowInsetDimension = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, exteriorWallFace); FamilyParameter windowInsetPara = m_familyManager.AddParameter("Window Inset", BuiltInParameterGroup.INVALID, ParameterType.Length, false); m_familyManager.Set(windowInsetPara, m_windowInset); windowInsetDimension.Label = windowInsetPara; //create the exterior frame double frameCurveOffset1 = 0.075; CurveArray curveArr1 = m_extrusionCreator.CreateRectangle(m_width / 2, -m_width / 2, m_sillHeight + m_height, m_sillHeight, 0); CurveArray curveArr2 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr1, frameCurveOffset1); CurveArrArray curveArrArray1 = new CurveArrArray(); curveArrArray1.Append(curveArr1); curveArrArray1.Append(curveArr2); Extrusion extFrame = m_extrusionCreator.NewExtrusion(curveArrArray1, m_sashPlane, m_wallThickness / 2 + m_wallThickness/12, -m_windowInset); extFrame.SetVisibility( CreateVisibility()); m_document.Regenerate(); //add alignment between wall face and exterior frame face Face exteriorExtrusionFace1=GeoHelper.GetExtrusionFace(extFrame,m_rightView,true); Face interiorExtrusionFace1 = GeoHelper.GetExtrusionFace(extFrame,m_rightView,false); CreateAlignment alignmentCreator = new CreateAlignment(m_document); alignmentCreator.AddAlignment(m_rightView,exteriorWallFace,exteriorExtrusionFace1); //add dimension between sash referenceplane and exterior frame face and lock the dimension Dimension extFrameWithSashPlane = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, interiorExtrusionFace1); extFrameWithSashPlane.IsLocked = true; m_document.Regenerate(); //create the interior frame double frameCurveOffset2 = 0.125; CurveArray curveArr3 = m_extrusionCreator.CreateRectangle(m_width / 2, -m_width / 2, m_sillHeight + m_height, m_sillHeight, 0); CurveArray curveArr4 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr3, frameCurveOffset2); m_document.Regenerate(); CurveArrArray curveArrArray2 = new CurveArrArray(); curveArrArray2.Append(curveArr3); curveArrArray2.Append(curveArr4); Extrusion intFrame = m_extrusionCreator.NewExtrusion(curveArrArray2, m_sashPlane, m_wallThickness - m_windowInset, m_wallThickness / 2 + m_wallThickness / 12); intFrame.SetVisibility( CreateVisibility()); m_document.Regenerate(); //add alignment between interior face of wall and interior frame face Face interiorWallFace = GeoHelper.GetWallFace(walls[0], m_rightView, false); Face interiorExtrusionFace2 = GeoHelper.GetExtrusionFace(intFrame, m_rightView, false); Face exteriorExtrusionFace2 = GeoHelper.GetExtrusionFace(intFrame, m_rightView, true); alignmentCreator.AddAlignment(m_rightView, interiorWallFace, interiorExtrusionFace2); //add dimension between sash referenceplane and interior frame face and lock the dimension Dimension intFrameWithSashPlane = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, exteriorExtrusionFace2); intFrameWithSashPlane.IsLocked = true; //create the sill frame CurveArray sillCurs = m_extrusionCreator.CreateRectangle(m_width / 2, -m_width / 2, m_sillHeight + frameCurveOffset1, m_sillHeight, 0); CurveArrArray sillCurveArray = new CurveArrArray(); sillCurveArray.Append(sillCurs); Extrusion sillFrame= m_extrusionCreator.NewExtrusion(sillCurveArray, m_sashPlane, -m_windowInset, -m_windowInset - 0.1); m_document.Regenerate(); //add alignment between wall face and sill frame face Face sillExtFace = GeoHelper.GetExtrusionFace(sillFrame, m_rightView, false); alignmentCreator.AddAlignment(m_rightView, sillExtFace, exteriorWallFace); m_document.Regenerate(); //set subcategories of the frames if (m_frameCat != null) { extFrame.Subcategory = m_frameCat; intFrame.Subcategory = m_frameCat; sillFrame.Subcategory = m_frameCat; } subTransaction.Commit(); }
/// <summary> /// Utility method for to extract the geometry of a reference plane in a family. /// </summary> /// <param name="plane">The reference plane.</param> /// <returns>An unbounded line representing the location of the plane.</returns> private Line GetReferencePlaneLine(ReferencePlane plane) { // Reset the "elevation" of the plane's line to Z=0, since that's where the lines will be placed. // Otherwise, some intersection calculation may fail Autodesk.Revit.DB.XYZ origin = new XYZ( plane.BubbleEnd.X, plane.BubbleEnd.Y, 0.0); Line line = m_appCreator.NewLineUnbound(origin, plane.Direction); return line; }
public void ByStartPointEndPoint_NullInput1() { Assert.Throws(typeof(System.ArgumentNullException), () => ReferencePlane.ByStartPointEndPoint(Point.ByCoordinates(1, 1, 1), null)); }
/// <summary> /// The method is used to collect template information, specifying the New Window Parameters /// </summary> private void CollectTemplateInfo() { List<Wall> walls = Utility.GetElements<Wall>(m_application, m_document); m_wallThickness = walls[0].Width; ParameterMap paraMap = walls[0].ParametersMap; Parameter wallheightPara = paraMap.get_Item("Unconnected Height"); if (wallheightPara != null) { m_wallHeight = wallheightPara.AsDouble(); } Parameter wallwidthPara = paraMap.get_Item("Length"); if (wallwidthPara != null) { m_wallWidth = wallwidthPara.AsDouble(); } m_windowInset = m_wallThickness/10; FamilyType type = m_familyManager.CurrentType; FamilyParameter heightPara = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT); FamilyParameter widthPara = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH); FamilyParameter sillHeightPara = m_familyManager.get_Parameter("Default Sill Height"); if(type.HasValue(heightPara)) { switch(heightPara.StorageType) { case StorageType.Double: m_height=type.AsDouble(heightPara).Value; break; case StorageType.Integer: m_height = type.AsInteger(heightPara).Value; break; } } if (type.HasValue(widthPara)) { switch (widthPara.StorageType) { case StorageType.Double: m_width = type.AsDouble(widthPara).Value; break; case StorageType.Integer: m_width = type.AsDouble(widthPara).Value; break; } } if (type.HasValue(sillHeightPara)) { switch (sillHeightPara.StorageType) { case StorageType.Double: m_sillHeight = type.AsDouble(sillHeightPara).Value; break; case StorageType.Integer: m_sillHeight = type.AsDouble(sillHeightPara).Value; break; } } //set the height,width and sillheight parameter of the opening m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT), m_height); m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH), m_width); m_familyManager.Set(m_familyManager.get_Parameter("Default Sill Height"),m_sillHeight); //get materials FilteredElementCollector elementCollector = new FilteredElementCollector(m_document); elementCollector.WherePasses(new ElementClassFilter(typeof(Material))); IList<Element> materials= elementCollector.ToElements(); foreach (Element materialElement in materials) { Material material = materialElement as Material; m_para.GlassMaterials.Add(material.Name); m_para.FrameMaterials.Add(material.Name); } //get categories Categories categories = m_document.Settings.Categories; Category category = categories.get_Item(BuiltInCategory.OST_Windows); CategoryNameMap cnm = category.SubCategories; if (cnm.Contains("Frame/Mullion")) { m_frameCat = cnm.get_Item("Frame/Mullion"); } if (cnm.Contains("Glass")) { m_glassCat = cnm.get_Item("Glass"); } //get referenceplanes List<ReferencePlane> planes = Utility.GetElements<ReferencePlane>(m_application,m_document); foreach(ReferencePlane p in planes) { if (p.Name.Equals("Sash")) m_sashPlane = p; if (p.Name.Equals("Exterior")) m_exteriorPlane = p; if (p.Name.Equals("Center (Front/Back)")) m_centerPlane = p; if (p.Name.Equals("Top") || p.Name.Equals("Head")) m_topPlane = p; if (p.Name.Equals("Sill") || p.Name.Equals("Bottom")) m_sillPlane = p; } }
// ====================================== // (3.2) add dimensions // ====================================== void addDimensions() { // find the plan view // View pViewPlan = findElement(typeof(ViewPlan), "Lower Ref. Level") as View; // find reference planes // ReferencePlane refLeft = findElement(typeof(ReferencePlane), "Left") as ReferencePlane; ReferencePlane refFront = findElement(typeof(ReferencePlane), "Front") as ReferencePlane; ReferencePlane refOffsetV = findElement(typeof(ReferencePlane), "OffsetV") as ReferencePlane; // OffsetV is added for L-shape ReferencePlane refOffsetH = findElement(typeof(ReferencePlane), "OffsetH") as ReferencePlane; // OffsetH is added for L-shape // // (1) add dimension between the reference planes 'Left' and 'OffsetV', and label it as 'Tw' // // define a dimension line // XYZ p0 = refLeft.FreeEnd; XYZ p1 = refOffsetV.FreeEnd; //Line pLine = _app.Create.NewLineBound(p0, p1); // Revit 2013 Line pLine = Line.CreateBound(p0, p1); // define references // ReferenceArray pRefArray = new ReferenceArray(); pRefArray.Append(refLeft.GetReference()); pRefArray.Append(refOffsetV.GetReference()); // create a dimension // Dimension pDimTw = _doc.FamilyCreate.NewDimension(pViewPlan, pLine, pRefArray); // add label to the dimension // FamilyParameter paramTw = _doc.FamilyManager.get_Parameter("Tw"); //pDimTw.Label = paramTw; // Revit 2013 pDimTw.FamilyLabel = paramTw; // Revit 2014 // // (2) do the same for dimension between 'Front' and 'OffsetH', and lable it as 'Td' // // define a dimension line // p0 = refFront.FreeEnd; p1 = refOffsetH.FreeEnd; //pLine = _app.Create.NewLineBound(p0, p1); // Revit 2013 pLine = Line.CreateBound(p0, p1); // Revit 2014 // define references // pRefArray = new ReferenceArray(); pRefArray.Append(refFront.GetReference()); pRefArray.Append(refOffsetH.GetReference()); // create a dimension // Dimension pDimTd = _doc.FamilyCreate.NewDimension(pViewPlan, pLine, pRefArray); // add label to the dimension // FamilyParameter paramTd = _doc.FamilyManager.get_Parameter("Td"); //pDimTd.Label = paramTd; // Revit 2013 pDimTd.FamilyLabel = paramTd; }
public List <ApplicationPlaceholderObject> RoofToNative(Roof speckleRoof) { if (speckleRoof.outline == null) { throw new Speckle.Core.Logging.SpeckleException("Only outline based Floor are currently supported."); } DB.RoofBase revitRoof = null; DB.Level level = null; var outline = CurveToNative(speckleRoof.outline); var speckleRevitRoof = speckleRoof as RevitRoof; if (speckleRevitRoof != null) { level = LevelToNative(speckleRevitRoof.level); } else { level = LevelToNative(LevelFromCurve(outline.get_Item(0))); } var roofType = GetElementType <RoofType>((Base)speckleRoof); var docObj = GetExistingElementByApplicationId(((Base)speckleRoof).applicationId); if (docObj != null) { Doc.Delete(docObj.Id); } switch (speckleRoof) { case RevitExtrusionRoof speckleExtrusionRoof: { var referenceLine = LineToNative(speckleExtrusionRoof.referenceLine); var norm = GetPerpendicular(referenceLine.GetEndPoint(0) - referenceLine.GetEndPoint(1)).Negate(); ReferencePlane plane = Doc.Create.NewReferencePlane(referenceLine.GetEndPoint(0), referenceLine.GetEndPoint(1), norm, Doc.ActiveView); //create floor without a type var start = ScaleToNative(speckleExtrusionRoof.start, speckleExtrusionRoof.units); var end = ScaleToNative(speckleExtrusionRoof.end, speckleExtrusionRoof.units); revitRoof = Doc.Create.NewExtrusionRoof(outline, plane, level, roofType, start, end); break; } case RevitFootprintRoof speckleFootprintRoof: { ModelCurveArray curveArray = new ModelCurveArray(); var revitFootprintRoof = Doc.Create.NewFootPrintRoof(outline, level, roofType, out curveArray); var poly = speckleFootprintRoof.outline as Polycurve; bool hasSlopedSide = false; if (poly != null) { for (var i = 0; i < curveArray.Size; i++) { var isSloped = ((Base)poly.segments[i])["isSloped"] as bool?; var slopeAngle = ((Base)poly.segments[i])["slopeAngle"] as double?; var offset = ((Base)poly.segments[i])["offset"] as double?; if (isSloped != null) { revitFootprintRoof.set_DefinesSlope(curveArray.get_Item(i), isSloped == true); if (slopeAngle != null && isSloped == true) { revitFootprintRoof.set_SlopeAngle(curveArray.get_Item(i), (double)slopeAngle); hasSlopedSide = true; } } if (offset != null) { revitFootprintRoof.set_Offset(curveArray.get_Item(i), (double)offset); } } } //this is for schema builder specifically //if no roof edge has a slope defined but a slope angle is defined on the roof //set each edge to have that slope if (!hasSlopedSide && speckleFootprintRoof.slope != null) { for (var i = 0; i < curveArray.Size; i++) { revitFootprintRoof.set_DefinesSlope(curveArray.get_Item(i), true); } TrySetParam(revitFootprintRoof, BuiltInParameter.ROOF_SLOPE, (double)speckleFootprintRoof.slope); } if (speckleFootprintRoof.cutOffLevel != null) { var cutOffLevel = LevelToNative(speckleFootprintRoof.cutOffLevel); TrySetParam(revitFootprintRoof, BuiltInParameter.ROOF_UPTO_LEVEL_PARAM, cutOffLevel); } revitRoof = revitFootprintRoof; break; } default: ConversionErrors.Add(new Error("Cannot create Roof", "Roof type not supported")); throw new Speckle.Core.Logging.SpeckleException("Roof type not supported"); } Doc.Regenerate(); try { CreateVoids(revitRoof, speckleRoof); } catch (Exception ex) { ConversionErrors.Add(new Error($"Could not create openings in roof {speckleRoof.applicationId}", ex.Message)); } if (speckleRevitRoof != null) { SetInstanceParameters(revitRoof, speckleRevitRoof); } var placeholders = new List <ApplicationPlaceholderObject>() { new ApplicationPlaceholderObject { applicationId = speckleRevitRoof.applicationId, ApplicationGeneratedId = revitRoof.UniqueId, NativeObject = revitRoof } }; var hostedElements = SetHostedElements(speckleRoof, revitRoof); placeholders.AddRange(hostedElements); return(placeholders); }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="referencePlane"></param> /// <returns></returns> private static Revit.Element CloneElement(Autodesk.Revit.UI.UIApplication app, ReferencePlane referencePlane) { ReferencePlane referencePlaneClone = app.ActiveUIDocument.Document.Create.NewReferencePlane(referencePlane.BubbleEnd, referencePlane.FreeEnd, referencePlane.Normal, app.ActiveUIDocument.Document.ActiveView); // TBD: ReferencePlane.View dissappeared (jma - 12/05/06) Utils.ParamUtil.SetParameters(referencePlaneClone.Parameters, referencePlane.Parameters); return(referencePlaneClone); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; View activeView = doc.ActiveView; ISelectionFilter openingFilter = new CategorySelectionFilter("Structural Connections"); ISelectionFilter refPlanesFilter = new CategorySelectionFilter("Reference Planes"); IList <Reference> openings = uidoc.Selection.PickObjects(ObjectType.Element, openingFilter, "Select openings"); List <FamilyInstance> fa = new List <FamilyInstance>(); foreach (Reference refe in openings) { FamilyInstance fi = doc.GetElement(refe) as FamilyInstance; fa.Add(fi); } var grouped = fa.GroupBy(x => x.Host.Id); double offset = 315 / 304.8; //Reference refPlaneLine = uidoc.Selection.PickObjects(ObjectType.Element,refPlanesFilter, "Select a ref plane").First(); IList <Reference> refPlaneLine = uidoc.Selection.PickObjects(ObjectType.Element, refPlanesFilter, "Select a ref plane"); var enu = grouped.GetEnumerator(); using (Transaction t = new Transaction(doc, "Lock dim")) { t.Start(); while (enu.MoveNext()) { foreach (FamilyInstance item in enu.Current) { offset += 315 / 304.8; foreach (Reference refPlaneReference in refPlaneLine) { ReferencePlane refP = doc.GetElement(refPlaneReference) as ReferencePlane; #if REVIT2019 if (VoidByLineHelpers.IsParallel(item, refP)) { VoidByLineHelpers.DrawDimension(doc, refPlaneReference, item, offset); } #elif REVIT2017 #endif } } offset = 0; } t.Commit(); } return(Result.Succeeded); }
/// <summary> /// This method is used to create dimension among three reference planes /// </summary> /// <param name="view">the view</param> /// <param name="refPlane1">the first reference plane</param> /// <param name="refPlane2">the second reference plane</param> /// <param name="refPlane">the middle reference plane</param> /// <returns>the new dimension</returns> public Dimension AddDimension(View view, ReferencePlane refPlane1, ReferencePlane refPlane2, ReferencePlane refPlane) { Dimension dim; Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ(); Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ(); Line line; Reference ref1; Reference ref2; Reference ref3; ReferenceArray refArray = new ReferenceArray(); ref1 = refPlane1.GetReference(); ref2 = refPlane2.GetReference(); ref3 = refPlane.GetReference(); startPoint = refPlane1.FreeEnd; endPoint = refPlane2.FreeEnd; line = Line.CreateBound(startPoint, endPoint); if (null != ref1 && null != ref2 && null != ref3) { refArray.Append(ref1); refArray.Append(ref3); refArray.Append(ref2); } SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); dim = m_document.FamilyCreate.NewDimension(view, line, refArray); subTransaction.Commit(); return(dim); }
/// <summary> /// The method is used to create extrusion using FamilyItemFactory.NewExtrusion() /// </summary> /// <param name="curveArrArray">the CurveArrArray parameter</param> /// <param name="workPlane">the reference plane is used to create SketchPlane</param> /// <param name="startOffset">the extrusion's StartOffset property</param> /// <param name="endOffset">the extrusion's EndOffset property</param> /// <returns>the new extrusion</returns> public Extrusion NewExtrusion(CurveArrArray curveArrArray, ReferencePlane workPlane, double startOffset, double endOffset) { Extrusion rectExtrusion = null; try { SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); SketchPlane sketch = m_familyCreator.NewSketchPlane(workPlane.Plane); rectExtrusion = m_familyCreator.NewExtrusion(true, curveArrArray, sketch, Math.Abs(endOffset - startOffset)); rectExtrusion.StartOffset = startOffset; rectExtrusion.EndOffset = endOffset; subTransaction.Commit(); return rectExtrusion; } catch { return null; } }
/// <summary> /// The method is used to collect template information, specifying the New Window Parameters /// </summary> private void CollectTemplateInfo() { List <Wall> walls = Utility.GetElements <Wall>(m_application, m_document); m_wallThickness = walls[0].Width; ParameterMap paraMap = walls[0].ParametersMap; Parameter wallheightPara = walls[0].get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);//paraMap.get_Item("Unconnected Height"); if (wallheightPara != null) { m_wallHeight = wallheightPara.AsDouble(); } LocationCurve location = walls[0].Location as LocationCurve; m_wallWidth = location.Curve.Length; m_windowInset = m_wallThickness / 10; FamilyType type = m_familyManager.CurrentType; FamilyParameter heightPara = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT); FamilyParameter widthPara = m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH); FamilyParameter sillHeightPara = m_familyManager.get_Parameter("Default Sill Height"); if (type.HasValue(heightPara)) { switch (heightPara.StorageType) { case StorageType.Double: m_height = type.AsDouble(heightPara).Value; break; case StorageType.Integer: m_height = type.AsInteger(heightPara).Value; break; } } if (type.HasValue(widthPara)) { switch (widthPara.StorageType) { case StorageType.Double: m_width = type.AsDouble(widthPara).Value; break; case StorageType.Integer: m_width = type.AsDouble(widthPara).Value; break; } } if (type.HasValue(sillHeightPara)) { switch (sillHeightPara.StorageType) { case StorageType.Double: m_sillHeight = type.AsDouble(sillHeightPara).Value; break; case StorageType.Integer: m_sillHeight = type.AsDouble(sillHeightPara).Value; break; } } //set the height,width and sillheight parameter of the opening m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_HEIGHT), m_height); m_familyManager.Set(m_familyManager.get_Parameter(BuiltInParameter.WINDOW_WIDTH), m_width); m_familyManager.Set(m_familyManager.get_Parameter("Default Sill Height"), m_sillHeight); //get materials FilteredElementCollector elementCollector = new FilteredElementCollector(m_document); elementCollector.WherePasses(new ElementClassFilter(typeof(Material))); IList <Element> materials = elementCollector.ToElements(); foreach (Element materialElement in materials) { Material material = materialElement as Material; m_para.GlassMaterials.Add(material.Name); m_para.FrameMaterials.Add(material.Name); } //get categories Categories categories = m_document.Settings.Categories; Category category = categories.get_Item(BuiltInCategory.OST_Windows); CategoryNameMap cnm = category.SubCategories; m_frameCat = categories.get_Item(BuiltInCategory.OST_WindowsFrameMullionProjection); m_glassCat = categories.get_Item(BuiltInCategory.OST_WindowsGlassProjection); //get referenceplanes List <ReferencePlane> planes = Utility.GetElements <ReferencePlane>(m_application, m_document); foreach (ReferencePlane p in planes) { if (p.Name.Equals("Sash")) { m_sashPlane = p; } if (p.Name.Equals("Exterior")) { m_exteriorPlane = p; } if (p.Name.Equals("Center (Front/Back)")) { m_centerPlane = p; } if (p.Name.Equals("Top") || p.Name.Equals("Head")) { m_topPlane = p; } if (p.Name.Equals("Sill") || p.Name.Equals("Bottom")) { m_sillPlane = p; } if (p.Name.Equals("Left")) { m_leftPlane = p; } if (p.Name.Equals("Right")) { m_rightPlane = p; } } }
/// <summary> /// Example demonstrating truss creation in the Autodesk Revit API. This example constructs /// a "mono" truss aligned with the reference planes in the (already loaded) truss family /// document. /// </summary> private void MakeNewTruss() { // Constants for arranging the angular truss members double webAngle = 35.0; double webAngleRadians = (180 - webAngle) * Math.PI / 180.0; Autodesk.Revit.DB.XYZ angleDirection = new Autodesk.Revit.DB.XYZ(Math.Cos(webAngleRadians), Math.Sin(webAngleRadians), 0); // Look up the reference planes and view in which to sketch ReferencePlane top = null, bottom = null, left = null, right = null, center = null; View level1 = null; List <Autodesk.Revit.DB.Element> elements = new List <Autodesk.Revit.DB.Element>(); ElementClassFilter refPlaneFilter = new ElementClassFilter(typeof(ReferencePlane)); ElementClassFilter viewFilter = new ElementClassFilter(typeof(View)); LogicalOrFilter filter = new LogicalOrFilter(refPlaneFilter, viewFilter); FilteredElementCollector collector = new FilteredElementCollector(m_document); elements.AddRange(collector.WherePasses(filter).ToElements()); foreach (Element e in elements) { // skip view templates because they're invisible invalid for truss creation View view = e as View; if (null != view && view.IsTemplate) { continue; } // switch (e.Name) { case "Top": top = e as ReferencePlane; break; case "Bottom": bottom = e as ReferencePlane; break; case "Right": right = e as ReferencePlane; break; case "Left": left = e as ReferencePlane; break; case "Center": center = e as ReferencePlane; break; case "Level 1": level1 = e as View; break; } } if (top == null || bottom == null || left == null || right == null || center == null || level1 == null) { throw new InvalidOperationException("Could not find prerequisite named reference plane or named view."); } SketchPlane sPlane = level1.SketchPlane; // Extract the geometry of each reference plane Line bottomLine = GetReferencePlaneLine(bottom); Line leftLine = GetReferencePlaneLine(left); Line rightLine = GetReferencePlaneLine(right); Line topLine = GetReferencePlaneLine(top); Line centerLine = GetReferencePlaneLine(center); // Create bottom chord along "bottom" from "left" to "right" Autodesk.Revit.DB.XYZ bottomLeft = GetIntersection(bottomLine, leftLine); Autodesk.Revit.DB.XYZ bottomRight = GetIntersection(bottomLine, rightLine); ModelCurve bottomChord = MakeTrussCurve(bottomLeft, bottomRight, sPlane, TrussCurveType.BottomChord); if (null != bottomChord) { // Add the alignment constraint to the bottom chord. Curve geometryCurve = bottomChord.GeometryCurve; // Lock the bottom chord to bottom reference plan m_familyCreator.NewAlignment(level1, bottom.GetReference(), geometryCurve.Reference); } // Create web connecting top and bottom chords on the right side Autodesk.Revit.DB.XYZ topRight = GetIntersection(topLine, rightLine); ModelCurve rightWeb = MakeTrussCurve(bottomRight, topRight, sPlane, TrussCurveType.Web); if (null != rightWeb) { // Add the alignment constraint to the right web chord. Curve geometryCurve = rightWeb.GeometryCurve; // Lock the right web chord to right reference plan m_familyCreator.NewAlignment(level1, right.GetReference(), geometryCurve.Reference); } // Create top chord diagonally from bottom-left to top-right ModelCurve topChord = MakeTrussCurve(bottomLeft, topRight, sPlane, TrussCurveType.TopChord); if (null != topChord) { // Add the alignment constraint to the top chord. Curve geometryCurve = topChord.GeometryCurve; // Lock the start point of top chord to the Intersection of left and bottom reference plan m_familyCreator.NewAlignment(level1, geometryCurve.GetEndPointReference(0), left.GetReference()); m_familyCreator.NewAlignment(level1, geometryCurve.GetEndPointReference(0), bottom.GetReference()); // Lock the end point of top chord to the Intersection of right and top reference plan m_familyCreator.NewAlignment(level1, geometryCurve.GetEndPointReference(1), top.GetReference()); m_familyCreator.NewAlignment(level1, geometryCurve.GetEndPointReference(1), right.GetReference()); } // Create angled web from midpoint to the narrow end of the truss Autodesk.Revit.DB.XYZ bottomMidPoint = GetIntersection(bottomLine, centerLine); Line webDirection = Line.CreateUnbound(bottomMidPoint, angleDirection); Autodesk.Revit.DB.XYZ endOfWeb = GetIntersection(topChord.GeometryCurve as Line, webDirection); ModelCurve angledWeb = MakeTrussCurve(bottomMidPoint, endOfWeb, sPlane, TrussCurveType.Web); // Add a dimension to force the angle to be stable even when truss length and height are modified Arc dimensionArc = Arc.Create( bottomMidPoint, angledWeb.GeometryCurve.Length / 2, webAngleRadians, Math.PI, Autodesk.Revit.DB.XYZ.BasisX, Autodesk.Revit.DB.XYZ.BasisY); Dimension createdDim = m_familyCreator.NewAngularDimension( level1, dimensionArc, angledWeb.GeometryCurve.Reference, bottomChord.GeometryCurve.Reference); if (null != createdDim) { createdDim.IsLocked = true; } // Create angled web from corner to top of truss Autodesk.Revit.DB.XYZ bottomRight2 = GetIntersection(bottomLine, rightLine); webDirection = Line.CreateUnbound(bottomRight2, angleDirection); endOfWeb = GetIntersection(topChord.GeometryCurve as Line, webDirection); ModelCurve angledWeb2 = MakeTrussCurve(bottomRight, endOfWeb, sPlane, TrussCurveType.Web); // Add a dimension to force the angle to be stable even when truss length and height are modified dimensionArc = Arc.Create( bottomRight, angledWeb2.GeometryCurve.Length / 2, webAngleRadians, Math.PI, Autodesk.Revit.DB.XYZ.BasisX, Autodesk.Revit.DB.XYZ.BasisY); createdDim = m_familyCreator.NewAngularDimension( level1, dimensionArc, angledWeb2.GeometryCurve.Reference, bottomChord.GeometryCurve.Reference); if (null != createdDim) { createdDim.IsLocked = true; } //Connect bottom midpoint to end of the angled web ModelCurve braceWeb = MakeTrussCurve(bottomMidPoint, endOfWeb, sPlane, TrussCurveType.Web); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; using (Transaction tx = new Transaction(doc)) { tx.Start("NewExtrusionRoof"); RoofType fs = new FilteredElementCollector(doc) .OfClass(typeof(RoofType)) .Cast <RoofType>() .FirstOrDefault <RoofType>(a => null != a); Level lvl = new FilteredElementCollector(doc) .OfClass(typeof(Level)) .Cast <Level>() .FirstOrDefault <Level>(a => null != a); double x = 1; XYZ origin = new XYZ(x, 0, 0); XYZ vx = XYZ.BasisY; XYZ vy = XYZ.BasisZ; SketchPlane sp = SketchPlane.Create(doc, //new Autodesk.Revit.DB.Plane( vx, vy, origin ) // 2016 Plane.CreateByOriginAndBasis(origin, vx, vy)); // 2017 //Plane.CreateByOriginAndBasis( origin, vy, vx ) ); // 2019 CurveArray ca = new CurveArray(); // This stair shape causes NewExtrusionRoof to // throw an exception in Revit 2019.1. XYZ[] pts = new XYZ[] { new XYZ(x, 1, 0), new XYZ(x, 1, 1), new XYZ(x, 2, 1), new XYZ(x, 2, 2), new XYZ(x, 3, 2), new XYZ(x, 3, 3), new XYZ(x, 4, 3), new XYZ(x, 4, 4) }; // Try a simple and closed rectangular shape. // This throws an invalid operation exception // saying "Invalid profile." pts = new XYZ[] { new XYZ(x, 1, 0), new XYZ(x, 1, 1), new XYZ(x, 2, 1), new XYZ(x, 2, 0) }; int n = pts.Length; for (int i = 1; i < n; ++i) { ca.Append(Line.CreateBound( pts[i - 1], pts[i])); } ca.Append(Line.CreateBound( pts[n - 1], pts[0])); doc.Create.NewModelCurveArray(ca, sp); View v = doc.ActiveView; ReferencePlane rp = doc.Create.NewReferencePlane2( origin, origin + vx, origin + vy, v); rp.Name = "MyRoofPlane"; ExtrusionRoof er = doc.Create.NewExtrusionRoof( ca, rp, lvl, fs, 0, 3); Debug.Print("Extrusion roof element id: " + er.Id.ToString()); 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; ISelectionFilter beamFilter = new CategorySelectionFilter("Structural Framing"); ISelectionFilter refPlaneFilter = new RefPlaneFilter(); IList <Reference> refsBeams = uidoc.Selection.PickObjects(ObjectType.Element, beamFilter, "Select Beams"); IList <Reference> refsLines = uidoc.Selection.PickObjects(ObjectType.Element, refPlaneFilter, "Select Reference Planes"); Debug.WriteLine($"{refsBeams.Count} beams selected"); Debug.WriteLine("Reference plances selected"); int countRectangular = 0; int countCircular = 0; string errors = ""; //revit family name string webPenoRectangular = "Web_Peno_Rectangular"; string webPenoCircular = "Web_Peno_Circular"; List <Dimension> lockDimensions = new List <Dimension>(); using (Transaction t = new Transaction(doc, "Place Dummy Opening")) { t.Start(); foreach (Reference beamRef in refsBeams) { FamilyInstance tempPeno = Helpers.PlaceOpening(doc, beamRef, 0, webPenoRectangular, "mid", 100, 100); doc.Delete(tempPeno.Id); } t.Commit(); } using (Transaction t = new Transaction(doc, "Place Opening")) { t.Start(); foreach (Reference beamRef in refsBeams) { //List<double> distances = PlaceOpeningIntersect.IntersectionPoint(doc, beamRef, refsLines); // dictionary of distances from start, penos [width, depth] Debug.WriteLine($"***Beam reference {beamRef.ElementId}***"); List <Tuple <double, int[], ReferencePlane> > penoSizes = VoidByLineHelpers.IntersectionLinePlane(doc, beamRef, refsLines); foreach (var item in penoSizes) { try { // remove beams without openings if (item.Item1 > 0) { double d = item.Item1; Debug.WriteLine($"Distance from start: {d.ToString()}"); Debug.WriteLine($"Peno sizes: {item.Item2[0]}x{item.Item2[1]}"); Debug.WriteLine($"Reference plane Id: {item.Item3.Id}"); FamilyInstance openingInstance = null; if (item.Item2[0] > 0) { openingInstance = Helpers.PlaceOpening(doc, beamRef, Convert.ToInt16(d), webPenoRectangular, "start", item.Item2[0], item.Item2[1]); Debug.WriteLine($"Opening Instance id: {openingInstance.Id}"); countRectangular += 1; } else { openingInstance = Helpers.PlaceOpening(doc, beamRef, Convert.ToInt16(d), webPenoCircular, "start", item.Item2[0], item.Item2[1]); countCircular += 1; } //if (VoidByLineHelpers.IsParallel(openingInstance, item.Item3)) //{ // VoidByLineHelpers.DrawDimension(doc, item.Item3, openingInstance, 0); //} FamilyInstance fi = openingInstance; ReferencePlane rp = item.Item3; Element ln = doc.GetElement(beamRef); LocationCurve lc = ln.Location as LocationCurve; #if REVIT2017 #endif #if REVIT2019 IList <Reference> fir1 = fi.GetReferences(FamilyInstanceReferenceType.WeakReference); ReferenceArray rea = new ReferenceArray(); rea.Append(fir1.First()); rea.Append(rp.GetReference()); Line lnie = lc.Curve as Line; //Dimension align = doc.Create.NewAlignment(doc.ActiveView, rp.GetReference(), fir1.First()); lockDimensions.Add(doc.Create.NewDimension(doc.ActiveView, lnie, rea)); //dim.IsLocked = true; #endif } else if (penoSizes.Count == 0) { errors += beamRef.ElementId + Environment.NewLine; } } catch { TaskDialog.Show("Error", "Uh-oh something went wrong"); } } } t.Commit(); }//close transaction using (Transaction t = new Transaction(doc, "Lock dimensions")) { t.Start(); if (lockDimensions.Count > 0) { foreach (Dimension d in lockDimensions) { d.IsLocked = true; } } t.Commit(); } if (errors == "") { TaskDialog.Show("result", string.Format("{0} rectangular voids created \n {1} circular voids created", countRectangular, countCircular)); } else { TaskDialog.Show("result", string.Format("{0} rectangular voids created \n{1} circular voids created \n" + "Intersection not found between the lines and the beams Id:\n{2}" + "Is the Subcategory parameter empty? Are they placed at the same level?", countRectangular, countCircular, errors)); } return(Result.Succeeded); }
/// <summary> /// Create a extrusion roof. /// </summary> /// <param name="refPlane">The reference plane for the extrusion roof.</param> /// <param name="level">The reference level of the roof to be created.</param> /// <param name="roofType">The type of the newly created roof.</param> /// <param name="extrusionStart">The extrusion start point.</param> /// <param name="extrusionEnd">The extrusion end point.</param> /// <returns>Return a new created extrusion roof.</returns> public ExtrusionRoof CreateExtrusionRoof(ReferencePlane refPlane, Level level, RoofType roofType, double extrusionStart, double extrusionEnd) { ExtrusionRoof roof = null; roof = m_extrusionRoofManager.CreateExtrusionRoof(m_profile, refPlane, level, roofType, extrusionStart, extrusionEnd); if (roof != null) { m_extrusionRoofs.Insert(roof); } return roof; }
/// <summary> /// The implementation of CreateSash(),and creating the Window Sash Solid Geometry /// </summary> public override void CreateSash() { double frameCurveOffset1 = 0.075; double frameDepth = 7 * m_wallThickness / 12 + m_windowInset; double sashCurveOffset = 0.075; double sashDepth = (frameDepth - m_windowInset) / 2; //get the exterior view and sash referenceplane which are used in this process Autodesk.Revit.DB.View exteriorView = Utility.GetViewByName("Exterior", m_application, m_document); SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); //add a middle reference plane between the top referenceplane and sill referenceplane CreateRefPlane refPlaneCreator = new CreateRefPlane(); ReferencePlane middlePlane = refPlaneCreator.Create(m_document, m_topPlane, exteriorView, new Autodesk.Revit.DB.XYZ(0, 0, -m_height / 2), new Autodesk.Revit.DB.XYZ(0, -1, 0), "tempmiddle"); m_document.Regenerate(); //add dimension between top, sill, and middle reference plane, make the dimension segment equal Dimension dim = m_dimensionCreator.AddDimension(exteriorView, m_topPlane, m_sillPlane, middlePlane); dim.AreSegmentsEqual = true; //create first sash CurveArray curveArr5 = m_extrusionCreator.CreateRectangle(m_width / 2 - frameCurveOffset1, -m_width / 2 + frameCurveOffset1, m_sillHeight + m_height / 2 + sashCurveOffset / 2, m_sillHeight + frameCurveOffset1, 0); CurveArray curveArr6 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr5, sashCurveOffset); m_document.Regenerate(); CurveArrArray curveArrArray3 = new CurveArrArray(); curveArrArray3.Append(curveArr5); curveArrArray3.Append(curveArr6); Extrusion sash1 = m_extrusionCreator.NewExtrusion(curveArrArray3, m_sashPlane, 2 * sashDepth, sashDepth); m_document.Regenerate(); Face esashFace1 = GeoHelper.GetExtrusionFace(sash1, m_rightView, true); Face isashFace1 = GeoHelper.GetExtrusionFace(sash1, m_rightView, false); Dimension sashDim1 = m_dimensionCreator.AddDimension(m_rightView, esashFace1, isashFace1); sashDim1.IsLocked = true; Dimension sashWithPlane1 = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, isashFace1); sashWithPlane1.IsLocked = true; sash1.SetVisibility(CreateVisibility()); //create second sash CurveArray curveArr7 = m_extrusionCreator.CreateRectangle(m_width / 2 - frameCurveOffset1, -m_width / 2 + frameCurveOffset1, m_sillHeight + m_height - frameCurveOffset1, m_sillHeight + m_height / 2 - sashCurveOffset / 2, 0); CurveArray curveArr8 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr7, sashCurveOffset); m_document.Regenerate(); CurveArrArray curveArrArray4 = new CurveArrArray(); curveArrArray4.Append(curveArr7); curveArrArray4.Append(curveArr8); Extrusion sash2 = m_extrusionCreator.NewExtrusion(curveArrArray4, m_sashPlane, sashDepth, 0); sash2.SetVisibility(CreateVisibility()); m_document.Regenerate(); Face esashFace2 = GeoHelper.GetExtrusionFace(sash2, m_rightView, true); Face isashFace2 = GeoHelper.GetExtrusionFace(sash2, m_rightView, false); Dimension sashDim2 = m_dimensionCreator.AddDimension(m_rightView, esashFace2, isashFace2); sashDim2.IsLocked = true; Dimension sashWithPlane2 = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, isashFace2); m_document.Regenerate(); sashWithPlane2.IsLocked = true; //set category of the sash extrusions if (m_frameCat != null) { sash1.Subcategory = m_frameCat; sash2.Subcategory = m_frameCat; } Autodesk.Revit.DB.ElementId id = new ElementId(m_sashMatID); sash1.get_Parameter(BuiltInParameter.MATERIAL_ID_PARAM).Set(id); sash2.get_Parameter(BuiltInParameter.MATERIAL_ID_PARAM).Set(id); subTransaction.Commit(); }
private void Stream( ArrayList data, ReferencePlane refPlane ) { data.Add( new Snoop.Data.ClassSeparator( typeof( ReferencePlane ) ) ); data.Add( new Snoop.Data.String( "Name", refPlane.Name ) ); // TBD: overridden but not using keyword! data.Add( new Snoop.Data.Xyz( "Bubble end", refPlane.BubbleEnd ) ); data.Add( new Snoop.Data.Xyz( "Free end", refPlane.FreeEnd ) ); data.Add( new Snoop.Data.Xyz( "Direction", refPlane.Direction ) ); data.Add( new Snoop.Data.Xyz( "Normal", refPlane.Normal ) ); data.Add( new Snoop.Data.Object( "Plane", refPlane.GetPlane() ) ); data.Add( new Snoop.Data.Object( "Reference", refPlane.GetReference() ) ); }
public void ByLine_NullInput() { Assert.Throws(typeof(System.ArgumentNullException), () => ReferencePlane.ByLine(null)); }
// =============================================================== // helper function: given a solid, find a planar // face with the given normal (version 2) // this is a slightly enhaced version of the previous // version and checks if the face is on the given reference plane. // =============================================================== PlanarFace findFace(Extrusion pBox, XYZ normal, ReferencePlane refPlane) { // get the geometry object of the given element // Options op = new Options(); op.ComputeReferences = true; GeometryElement geomElem = pBox.get_Geometry(op); // loop through the array and find a face with the given normal // foreach (GeometryObject geomObj in geomElem) { if (geomObj is Solid) // solid is what we are interested in. { Solid pSolid = geomObj as Solid; FaceArray faces = pSolid.Faces; foreach (Face pFace in faces) { PlanarFace pPlanarFace = (PlanarFace)pFace; // check to see if they have same normal if ((pPlanarFace != null) && pPlanarFace.FaceNormal.IsAlmostEqualTo(normal)) { // additionally, we want to check if the face is on the reference plane // XYZ p0 = refPlane.BubbleEnd; XYZ p1 = refPlane.FreeEnd; //Line pCurve = _app.Create.NewLineBound(p0, p1); // Revit 2013 Line pCurve = Line.CreateBound(p0, p1); // Revit 2014 if (pPlanarFace.Intersect(pCurve) == SetComparisonResult.Subset) { return pPlanarFace; // we found the face } } } } // will come back later as needed. // //else if (geomObj is Instance) //{ //} //else if (geomObj is Curve) //{ //} //else if (geomObj is Mesh) //{ //} } // if we come here, we did not find any. return null; }
/// <summary> /// The method is used to create dimension between referenceplane and face /// </summary> /// <param name="view">the view in which the dimension is created</param> /// <param name="refPlane">the reference plane</param> /// <param name="face">the face</param> /// <returns>the new dimension</returns> public Dimension AddDimension(View view, ReferencePlane refPlane, Face face) { Dimension dim; Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ (); Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ (); Line line; Reference ref1; Reference ref2; ReferenceArray refArray = new ReferenceArray(); ref1 = refPlane.Reference; PlanarFace pFace = face as PlanarFace; ref2 = pFace.Reference; if (null != ref1 && null != ref2) { refArray.Append(ref1); refArray.Append(ref2); } startPoint = refPlane.FreeEnd; endPoint = new Autodesk.Revit.DB.XYZ (startPoint.X, pFace.Origin.Y, startPoint.Z ); SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); line = m_application.Create.NewLineBound(startPoint, endPoint); dim = m_document.FamilyCreate.NewDimension(view, line, refArray); subTransaction.Commit(); return dim; }