//Create the Note Block Schedule public static void CreateDNoteLegend(Document doc, ElementId symbolId) { ViewSchedule vs = null; using (Transaction transaction = new Transaction(doc, "Creating Note BLock")) { if (!symbolId.Equals(ElementId.InvalidElementId)) { transaction.Start(); //Create a note-block view schedule. vs = ViewSchedule.CreateNoteBlock(doc, symbolId); AddRegularFieldToSchedule(doc, vs); } if (null != vs) { transaction.Commit(); } else { transaction.RollBack(); } } }
public bool Equals(Section section) { if (section == null) { return(false); } if (section == this) { return(true); } return(ElementId.Equals(section.ElementId) && Type == section.Type); }
/// <summary> /// Determine if the newly created opening is valid to udpate its parameter. /// Handle the case when revit pops up warning ( opening is completely inside a larger one, /// opening does not intersect host...) that allow user to cancel operation or /// delete newly created opening. /// </summary> /// <param name="doc"></param> /// <param name="openingCreatingTransaction"></param> /// <param name="openingId"></param> /// <returns></returns> public static bool CanUpdateNewOpening(Document doc, Transaction openingCreatingTransaction, ElementId openingId) { // when user cancel operation if (openingCreatingTransaction.GetStatus() != TransactionStatus.Committed) { return(false); } // when user delete new opening if (openingId == null || openingId.Equals(ElementId.InvalidElementId)) { return(false); } Element opening = doc.GetElement(openingId); return(opening != null); }
public bool Equals(Decision decision) { if (decision == this) { return(true); } if (decision == null) { return(false); } if (ElementId != null) { return(ElementId.Equals(decision.ElementId) && Id == decision.Id); } else { return(Id == decision.Id); } }
public static void equality() { ElementId t1 = 3; ElementId t2 = 3; ElementId t3 = 5; ElementId?t4 = 3; ElementId?tn = null; Assert.AreEqual(t1, t2); Assert.AreEqual(t1, t4); Assert.AreEqual(t1, 3); Assert.AreEqual(t4, 3); Assert.AreEqual(tn, tn); Assert.AreNotEqual(t1, t3); Assert.AreNotEqual(t1, tn); Assert.AreNotEqual(t1, 5); Assert.AreNotEqual(t4, tn); Assert.AreNotEqual(t4, "asdf"); Assert.That(t1.Equals((object)t2)); Assert.That(t1.Equals((object)t4)); Assert.That(t1.Equals((object)3)); Assert.That(t4.Equals((object)3)); Assert.That(!t1.Equals((object)t3)); Assert.That(!t1.Equals((object)tn)); Assert.That(!t1.Equals((object)5)); Assert.That(!t4.Equals((object)tn)); Assert.That(t1 == t2); Assert.That(t1 == t4); Assert.That(t1 == 3); Assert.That(t4 == 3); Assert.That(tn == tn); Assert.That(t1 != t3); Assert.That(t1 != tn); Assert.That(t1 != 6); Assert.That(t4 != 6); Assert.That(t4 != tn); Assert.That(t2 == t1); Assert.That(t4 == t1); Assert.That(3 == t1); Assert.That(3 == t4); Assert.That(t3 != t1); Assert.That(tn != t1); Assert.That(6 != t1); Assert.That(6 != t4); Assert.That(tn != t4); }
public bool Equals(Section section) { if (section == this) { return(true); } if (section == null) { return(false); } if (ElementId != null) { return(ElementId.Equals(section.ElementId) && Title == section.Title); } else { return(Title == section.Title); } }
private Result SlopeSelectedBuildingPad(UIDocument targetUIdoc, ref string message, double maxPointDistInFeet, double targetAngleInRadians) { Document doc = targetUIdoc.Document; Selection sel = targetUIdoc.Selection; View3D current3dView = doc.ActiveView as View3D; if (current3dView == null) { message = Properties.Messages.SlopeGradingFromPads_Not3DView; return(Result.Failed); } BuildingPad selectedBuildingPad = doc.GetElement(sel.PickObject(ObjectType.Element, new PadSelectionFilter(), Properties.Messages.SlopeGradingFromPads_SelectPad)) as BuildingPad; //Check if the Pad is associate with a Surface (never seen one doesnt, but anyways) ElementId topoElementID = selectedBuildingPad.HostId; if (topoElementID.Equals(ElementId.InvalidElementId)) { message = Properties.Messages.SlopeGradingFromPads_NoTopoAssociate; return(Result.Failed); } TopographySurface currentTopo = doc.GetElement(topoElementID) as TopographySurface; if (currentTopo == null) { message = Properties.Messages.SlopeGradingFromPads_NoTopoAssociate;; return(Result.Failed); } IList <CurveLoop> PadBoundaryLoops = new List <CurveLoop>(); CurveLoop outerLoop = null; IList <Reference> TopFacesReferences = HostObjectUtils.GetTopFaces(selectedBuildingPad); if (TopFacesReferences.Count > 1) { message = Properties.Messages.SlopeGradingFromPads_PadsWithMoreThanOneUpperFace; return(Result.Failed); } XYZ plannarDirection = XYZ.BasisZ; XYZ plannarOrigin = XYZ.Zero; // interate on the only face foreach (Reference currentFaceRef in TopFacesReferences) { GeometryObject currentFaceObj = selectedBuildingPad.GetGeometryObjectFromReference(currentFaceRef); if (currentFaceObj is PlanarFace) { PlanarFace currentPlanarFace = currentFaceObj as PlanarFace; plannarDirection = currentPlanarFace.FaceNormal; plannarOrigin = currentPlanarFace.Origin; PadBoundaryLoops = currentPlanarFace.GetEdgesAsCurveLoops(); } else { message = Properties.Messages.SlopeGradingFromPads_UpperFaceNotPlanar; return(Result.Failed); } } //Sort the curves so the outer loop comes first IList <IList <CurveLoop> > curveLoopLoop = ExporterIFCUtils.SortCurveLoops(PadBoundaryLoops); if (curveLoopLoop.Count > 0) { IList <CurveLoop> firstList = curveLoopLoop.First(); if (firstList.Count > 0) { outerLoop = firstList.First(); } } if (outerLoop == null) { message = Properties.Messages.SlopeGradingFromPads_OuterLoopIssue; return(Result.Failed); } //This will be the list of elements that the ReferenceIntersector will shoot the rays //If we try to shoot the rays only in the toposurface and the it has subregions, the reference //intersection will not recognize these regions, so its necessary to shoot rays to the surface and its subregions IList <ElementId> currentSubRegionsAndSurface = currentTopo.GetHostedSubRegionIds(); currentSubRegionsAndSurface.Add(topoElementID); //Search for the max distance from the Pad to the topography //Doesnt matter if it is upwards or downwards, but we will check that, since the ray has to go to one direction //This is to estabilish what the distance will be using to create the slope to the right amount ReferenceIntersector topoRefIntersec = new ReferenceIntersector(currentSubRegionsAndSurface, FindReferenceTarget.Mesh, current3dView); double maxDist = double.NegativeInfinity; foreach (Curve currentCurve in outerLoop) { int numberOfInteractions = 0; double increaseAmount = 0; double currentParameter = 0; EstabilishInteractionPoints(currentCurve, maxPointDistInFeet, out numberOfInteractions, out increaseAmount); for (int i = 0; i < numberOfInteractions; i++) { if (i == 0) { currentParameter = 0; } else { currentParameter += increaseAmount; } XYZ currentPointToEvaluate = currentCurve.Evaluate(currentParameter, true); ReferenceWithContext currentRefContext = topoRefIntersec.FindNearest(currentPointToEvaluate, XYZ.BasisZ); if (currentRefContext == null) { currentRefContext = topoRefIntersec.FindNearest(currentPointToEvaluate, XYZ.BasisZ.Negate()); } if (currentRefContext == null) { continue; } double currentDist = currentRefContext.Proximity; if (currentDist > maxDist) { maxDist = currentDist; } } } // if we haven't changed the maxdist yet, something went wrong if (maxDist == double.NegativeInfinity) { message = Properties.Messages.SlopeGradingFromPads_NoTopoAssociate; return(Result.Failed); } //Estabilish the offset from the pad double offsetDist = maxDist / Math.Tan(targetAngleInRadians); using (TopographyEditScope topoEditGroup = new TopographyEditScope(doc, Properties.Messages.SlopeGradingFromPads_Transaction)) { topoEditGroup.Start(topoElementID); using (Transaction t = new Transaction(doc, Properties.Messages.SlopeGradingFromPads_Transaction)) { t.Start(); CurveLoop offsetLoop = null; try { offsetLoop = CurveLoop.CreateViaOffset(outerLoop, offsetDist, plannarDirection); } catch { message += Properties.Messages.SlopeGradingFromPads_OuterOffsetLoopIssue; return(Result.Failed); } #region DebugCurve Loop //Plane p = new Plane(plannarDirection, plannarOrigin); //SketchPlane sktP = SketchPlane.Create(doc, p); //foreach (Curve currentOffsetCurve in offsetLoop) //{ // doc.Create.NewModelCurve(currentOffsetCurve, sktP); //} #endregion foreach (Curve currentOffsetCurve in offsetLoop) { int numberOfInteractions = 0; double increaseAmount = 0; double currentParameter = 0; EstabilishInteractionPoints(currentOffsetCurve, maxPointDistInFeet, out numberOfInteractions, out increaseAmount); for (int i = 0; i < numberOfInteractions; i++) { if (i == 0) { currentParameter = 0; } else { currentParameter += increaseAmount; } XYZ currentPointOffset = currentOffsetCurve.Evaluate(currentParameter, true); ReferenceWithContext currentRefContext = topoRefIntersec.FindNearest(currentPointOffset, XYZ.BasisZ); if (currentRefContext == null) { currentRefContext = topoRefIntersec.FindNearest(currentPointOffset, XYZ.BasisZ.Negate()); } //if we couldn't find points upwards and downwards, the topo is near the border, so we cant add points if (currentRefContext == null) { continue; } Reference currentReference = currentRefContext.GetReference(); XYZ currentPointToAdd = currentReference.GlobalPoint; if (currentTopo.ContainsPoint(currentPointToAdd)) { continue; } IList <XYZ> ListPointToAdd = new List <XYZ>(); ListPointToAdd.Add(currentPointToAdd); currentTopo.AddPoints(ListPointToAdd); } } foreach (Curve currentCurve in outerLoop) { int numberOfInteractions = 0; double increaseAmount = 0; double currentParameter = 0; EstabilishInteractionPoints(currentCurve, maxPointDistInFeet, out numberOfInteractions, out increaseAmount); for (int i = 0; i < numberOfInteractions; i++) { if (i == 0) { currentParameter = 0; } else { currentParameter += increaseAmount; } XYZ currentPointToAdd = currentCurve.Evaluate(currentParameter, true); if (currentTopo.ContainsPoint(currentPointToAdd)) { continue; } IList <XYZ> ListPointToAdd = new List <XYZ>(); ListPointToAdd.Add(currentPointToAdd); currentTopo.AddPoints(ListPointToAdd); } } t.Commit(); } topoEditGroup.Commit(new TopographyFailurePreprocessor()); return(Result.Succeeded); } }
private void CreateBeams() { Element selectedElement = null; try { while (true) { #region MinMaxDimentions double BeamMinHeight = Utils.ConvertM.cmToFeet(20); double BeamMaxHeight = Utils.ConvertM.cmToFeet(150); double BeamMinWidth = Utils.ConvertM.cmToFeet(14); double BeamMaxWidth = Utils.ConvertM.cmToFeet(40); #endregion selectedElement = doc.GetElement(sel.PickObject(ObjectType.Element, new BeamSelectionFilter(), "Selecione uma viga.")); FamilyInstance selectedBeam = selectedElement as FamilyInstance; if (selectedBeam == null) { continue; } Wall selectedWall = GetMainWallAssociateWithBeam(selectedBeam); if (selectedWall == null) { if (currentUI.BeamHeightMode == BeamFromWallHeightMode.HighestOpening || currentUI.BeamWidthMode == BeamFromWallWidthMode.WallWidth) { continue; } } using (Transaction beamTransation = new Transaction(doc, "Atualizar viga")) { beamTransation.Start(); ElementId beamGroupId = selectedBeam.GroupId; if (!beamGroupId.Equals(ElementId.InvalidElementId)) { Group groupToUngroup = doc.GetElement(beamGroupId) as Group; groupToUngroup.UngroupMembers(); } #region BeamParameters //Levels Level beamLevel = doc.GetElement(selectedBeam.get_Parameter(BuiltInParameter.INSTANCE_REFERENCE_LEVEL_PARAM).AsElementId()) as Level; //Offsets double end0Offset = selectedBeam.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).AsDouble(); double end1Offset = selectedBeam.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).AsDouble(); //Unconnected Height double wallUncHeight = selectedWall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble(); //Height and Width double beamHeight = Utils.ConvertM.cmToFeet(60); double beamWidth = Utils.ConvertM.cmToFeet(14); //Get Information about the UI and the Geometry and set the variables beamWidth and beamHeight accordingly DefineBeamParameters(selectedWall, doc, beamLevel, wallUncHeight, ref beamWidth, ref beamHeight); //Curve Curve wallCurve = (selectedBeam.Location as LocationCurve).Curve; #endregion Family currentFamily = doc.GetElement(new ElementId(currentUI.SelectedBeamFamilyID)) as Family; FamilySymbol currentFamilySymbol = doc.GetElement(currentFamily.GetFamilySymbolIds().First()) as FamilySymbol; if (currentFamilySymbol == null) { throw new Exception("Erro na separação do tipo de família."); } //Verify if the dimentions is bettween min an max if (beamHeight < BeamMinHeight) { beamHeight = BeamMinHeight; } if (beamHeight > BeamMaxHeight) { beamHeight = BeamMaxHeight; } if (beamWidth < BeamMinWidth) { beamWidth = BeamMinWidth; } if (beamWidth > BeamMaxWidth) { beamWidth = BeamMaxWidth; } //Round the dimensions in cm const double roundNumber = 5; double beamHeightInCM = Math.Round(Utils.ConvertM.feetToCm(beamHeight)); double beamWidthInCM = Math.Round(Utils.ConvertM.feetToCm(beamWidth)); beamHeight = Utils.ConvertM.cmToFeet((beamHeightInCM / roundNumber) * roundNumber); beamWidth = Utils.ConvertM.cmToFeet((beamWidthInCM / roundNumber) * roundNumber); //Build the Name of the Future FamilySymbol and checks if we have another with the same name, if we have another one use that instead string newTypeName = beamWidthInCM.ToString() + " x " + beamHeightInCM.ToString() + "cm"; if (!Utils.FindElements.thisTypeExist(newTypeName, currentFamily.Name, BuiltInCategory.OST_StructuralFraming, doc)) { currentFamilySymbol = currentFamilySymbol.Duplicate(newTypeName) as FamilySymbol; Parameter parameterB = currentFamilySymbol.LookupParameter("b"); Parameter parameterH = currentFamilySymbol.LookupParameter("h"); parameterB.Set(beamWidth); parameterH.Set(beamHeight); } else { currentFamilySymbol = Utils.FindElements.findElement(newTypeName, currentFamily.Name, BuiltInCategory.OST_StructuralFraming, doc) as FamilySymbol; } currentFamilySymbol.Activate(); selectedBeam.Symbol = currentFamilySymbol; beamTransation.Commit(); } } } catch (Exception excep) { ExceptionManager eManager = new ExceptionManager(excep); } finally { currentUI.UnFreezeCreateButton(); } }
public Result Execute2( ExternalCommandData commandData, ref string message, ElementSet elements, bool storeOnType) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = Util.GetActiveDocument(uidoc, true); if (null == doc) { return(Result.Failed); } Selection sel = uidoc.Selection; //int n = sel.Elements.Size; // 2014 int n = sel.GetElementIds().Count; // 2015 if (1 < n) { Util.InfoMessage(string.Format( "{0} element{1} selected. Please select one " + "single element to store file data on.", n, Util.PluralSuffix(n))); return(Result.Failed); } OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Store File Data in Revit Extensible Storage"; dlg.CheckFileExists = true; if (null != _initial_directory) { dlg.InitialDirectory = _initial_directory; } if (DialogResult.OK != dlg.ShowDialog()) { return(Result.Cancelled); } Element e = null; if (0 < n) { Debug.Assert(1 == n, "we already checked for 1 < n above"); //foreach( Element e2 in sel.Elements ) // 2014 foreach (ElementId id in sel.GetElementIds()) // 2015 { e = doc.GetElement(id); } } else { try { Reference r = sel.PickObject( ObjectType.Element, "Please pick an element to store the file on: "); e = doc.GetElement(r.ElementId); } catch (RvtOperationCanceledException) { return(Result.Cancelled); } } if (storeOnType) { ElementId id = e.GetTypeId(); if (null == id || id.Equals(ElementId.InvalidElementId)) { Util.InfoMessage("The selected element " + "does not have an element type."); return(Result.Failed); } e = doc.GetElement(id); } Transaction t = new Transaction(doc); t.Start("Estore File"); EstoreFile(dlg.FileName, e); t.Commit(); return(Result.Succeeded); }