public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var doc = commandData.Application.ActiveUIDocument.Document; //create point list List <XYZ> pointList = new List <XYZ>(); pointList.Add(new XYZ(0, 0, 0)); pointList.Add(new XYZ(0, 20, 0)); //Collect all adaptive component family symbols with 2 placement points var collector = new FilteredElementCollector(doc); var filter = new ElementClassFilter(typeof(FamilySymbol)); var adaptiveComponents = from fs in collector.WherePasses(filter).Cast <FamilySymbol>() where AdaptiveComponentFamilyUtils.IsAdaptiveComponentFamily(fs.Family) && AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(fs.Family) == 2 select fs; //Display dialog and prompt for selection FormFamilySymbolSelector selector = new FormFamilySymbolSelector(adaptiveComponents); selector.ShowDialog(); if (selector.DialogResult.Equals(DialogResult.OK)) { //get the selected family var selectedFamilySymbol = selector.SelectedElement(); //activate familySymbol selectedFamilySymbol.Activate(); //create family using (Transaction transaction = new Transaction(doc)) { transaction.Start("Create Family"); var familyInstance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, selectedFamilySymbol); //adjust placment point locations var placementPoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance); for (int i = 0; i < placementPoints.Count; i++) { var p = doc.GetElement(placementPoints[i]) as ReferencePoint; p.Position = pointList[i]; } transaction.Commit(); } } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var doc = commandData.Application.ActiveUIDocument.Document; //Collect all adaptive component family symbols with more than 1 placement point var collector = new FilteredElementCollector(doc); var filter = new ElementClassFilter(typeof(FamilySymbol)); var adaptiveComponents = from fs in collector.WherePasses(filter).Cast <FamilySymbol>() where AdaptiveComponentFamilyUtils.IsAdaptiveComponentFamily(fs.Family) && AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(fs.Family) > 1 select fs; //Display dialog and prompt for selection FormFamilySymbolSelector selector = new FormFamilySymbolSelector(adaptiveComponents); selector.ShowDialog(); //select edge reference Reference hostEdge = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Edge, "Select edge:"); var selectedId = hostEdge.ElementId; Element e = doc.GetElement(selectedId); //get the selected family var selectedFamilySymbol = selector.SelectedElement(); //activate familySymbol selectedFamilySymbol.Activate(); using (TransactionGroup transGroup = new TransactionGroup(doc)) { transGroup.Start("Place Dimensions"); //hack join the element to a wall ElementId wallId = null; if (e is FamilyInstance & JoinGeometryUtils.GetJoinedElements(doc, e).Count < 1) { using (Transaction transaction = new Transaction(doc)) { transaction.Start("Create wall"); //////setup a failure handler to handle any warnings ////FailureHandlingOptions failOpts = transaction.GetFailureHandlingOptions(); ////failOpts.SetFailuresPreprocessor(new WarningSwallower()); ////transaction.SetFailureHandlingOptions(failOpts); wallId = Utils.CreateJoinedWall(doc, wallId, e as FamilyInstance); doc.Regenerate(); transaction.Commit(); } } using (Transaction transaction = new Transaction(doc)) { transaction.Start("Create Family"); //get number of placement point var numberOfPoints = AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(selectedFamilySymbol.Family); double numberOfSpaces = numberOfPoints - 1; //create family var familyInstance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, selectedFamilySymbol); //adjust placment point locations var placementPoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance); for (int i = 0; i < placementPoints.Count; i++) { double interval = i / numberOfSpaces; var location = new PointLocationOnCurve(PointOnCurveMeasurementType.NormalizedCurveParameter, interval, PointOnCurveMeasureFrom.Beginning); var pointOnEdge = doc.Application.Create.NewPointOnEdge(hostEdge, location); var p = doc.GetElement(placementPoints[i]) as ReferencePoint; p.SetPointElementReference(pointOnEdge); } transaction.Commit(); } transGroup.Assimilate(); } return(Result.Succeeded); }
static public string CreateRoof(Dyn.Element roofElement, IList <Dyn.FamilyType> listOfFamilyTypes, Dyn.FamilyType ridgeFamilyType) { Document doc = DocumentManager.Instance.CurrentDBDocument; RoofStorage.revitApp = doc.Application; FootPrintRoof currentRoof = roofElement.InternalElement as FootPrintRoof; if (currentRoof == null) { throw new Exception("Error, element is not a footprint roof."); } Parameter selectedRoofSlopeParameter = currentRoof.get_Parameter(BuiltInParameter.ROOF_SLOPE); double selectedRoofSlope = selectedRoofSlopeParameter.AsDouble(); //Verify if the roof has all the same slopes if (selectedRoofSlope <= 0) { throw new Exception("Error, it was not possible to estabilish a unique slope for the roof, please, make sure all eaves have the same slope."); } //Verify if the roof has the minimal slope if (selectedRoofSlope < 0.098) { throw new Exception("Error, please make sure the roof has a minimum of 10% slope."); } IList <Reference> faceRefList = HostObjectUtils.GetTopFaces(currentRoof); IList <PlanarFace> planarFaceList = new List <PlanarFace>(); if (!IsListOfPlanarFaces(faceRefList, currentRoof, out planarFaceList)) { throw new Exception("Error, invalid roof selected, please make sure all faces of the roof are flat."); } FamilySymbol ridgeFamilySymbol = ridgeFamilyType.InternalElement as FamilySymbol; if (ridgeFamilySymbol == null) { throw new Exception("Error, ridgeFamilyType is not a valid Family Type."); } if (!AdaptiveComponentFamilyUtils.IsAdaptiveComponentFamily(ridgeFamilySymbol.Family)) { throw new Exception("Error, ridgeFamilyType is not a valid Adaptive component type"); } if (AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(ridgeFamilySymbol.Family) != 2) { throw new Exception("Error, ridgeFamilyType must have two insertion points"); } IList <FamilySymbol> listOfFamilySymbols = ConvertDynFamilyTypeListToRevitFamilySymbolList(listOfFamilyTypes); if (listOfFamilySymbols.Count() < 1) { throw new Exception("Error, no adaptive family types were found on the input list"); } if (doc.ActiveView as View3D == null) { throw new Exception("Error, please use this command on a 3d view"); } //currentPointSymbol.Activate(); string results = ""; results += "Number of Roof Instances " + planarFaceList.Count() + "\n"; foreach (PlanarFace currentFace in planarFaceList) { int numberOfCurves = GetOuterCurveLoop(currentFace).Count(); FamilySymbol currentFamilySymbol = listOfFamilySymbols.Where(fs => AdaptiveComponentFamilyUtils.GetNumberOfPlacementPoints(fs.Family) == numberOfCurves).FirstOrDefault(); if (currentFamilySymbol == null) { continue; } CreateAdaptiveComponent(doc, currentFace, currentFamilySymbol); } IList <Curve> ridgeCurves = GetListOfRidgesHipsAndValleys(planarFaceList); results += "Number of Ridge Instances " + ridgeCurves.Count(); foreach (Curve currentCurve in ridgeCurves) { curveInfo curvI = GetCurveInformation(currentRoof, currentCurve, planarFaceList); if (curvI.roofLineType == RoofLineType.Ridge || curvI.roofLineType == RoofLineType.Hip) { CreateAdaptiveComponentFromLine(doc, currentCurve, ridgeFamilySymbol); } } return(results); }