/***************************************************/ /**** Public methods ****/ /***************************************************/ public static FamilyInstance AdaptiveComponent(Document document, FamilySymbol familySymbol, List <XYZ> points, RevitSettings settings = null) { if (document == null || familySymbol == null || points == null) { return(null); } settings = settings.DefaultIfNull(); FamilyInstance adaptiveComponent = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(document, familySymbol); IList <ElementId> pointIds = AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds(adaptiveComponent); if (pointIds.Count != points.Count) { pointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(adaptiveComponent); } if (pointIds.Count != points.Count) { BH.Engine.Reflection.Compute.RecordError($"An adaptive component could not be created based on the given ModelInstance because its definition requires different number of points than provided."); document.Delete(adaptiveComponent.Id); return(null); } for (int i = 0; i < pointIds.Count; i++) { ReferencePoint rp = (ReferencePoint)document.GetElement(pointIds[i]); Transform t = Transform.CreateTranslation(points[i]); rp.SetCoordinateSystem(t); } return(adaptiveComponent); }
public void CreateOrMoveAdaptiveComponent(Autodesk.Revit.DB.Document document, XYZ placementPoint, Autodesk.Revit.DB.FamilySymbol symbol = null, ElementId elementToMove = null) { Autodesk.Revit.DB.FamilyInstance instance = null; if (elementToMove == null) { // Create a new instance of an adaptive component family instance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(document, symbol); } else { instance = document.GetElement(elementToMove) as Autodesk.Revit.DB.FamilyInstance; } // Get the placement points of this instance IList <Autodesk.Revit.DB.ElementId> placePointIds = new List <Autodesk.Revit.DB.ElementId>(); placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); // Set the position of each placement point foreach (Autodesk.Revit.DB.ElementId id in placePointIds) { ReferencePoint point = document.GetElement(id) as ReferencePoint; point.Position = placementPoint; } }
public static void CreateAdaptiveComponentFamily(XYZ[] pts, string fName) { FilteredElementCollector temc = new FilteredElementCollector(_doc); List <Element> guanPian = temc.OfClass(typeof(FamilySymbol)).ToElements() as List <Element>; FamilySymbol symbol = null; foreach (Element element in guanPian) { if (element.Name == fName) { symbol = element as FamilySymbol; } } //创建自适应族 using (Transaction tr = new Transaction(_doc)) { tr.Start("自适应族"); FamilyInstance instance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(_doc, symbol); //获取实例的放置点 IList <ElementId> placePointIds = new List <ElementId>(); placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); //设置每个放置点的位置 for (int i = 0; i < placePointIds.Count; i++) { ReferencePoint point = _doc.GetElement(placePointIds[i]) as ReferencePoint; point.Position = pts[i]; } tr.Commit(); } }
/// <summary> /// This method is used to place an adaptive family which helps in debugging /// </summary> /// <param name="typeName"></param> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> public static FamilyInstance PlaceAdaptiveFamilyInstance(string famAndTypeName, XYZ p1, XYZ p2) { //Get the symbol ElementParameterFilter filter = Filter.ParameterValueFilter(famAndTypeName, BuiltInParameter.SYMBOL_FAMILY_AND_TYPE_NAMES_PARAM); //Hardcoded until implements FamilySymbol markerSymbol = new FilteredElementCollector(PCFImport.doc).WherePasses(filter) .Cast <FamilySymbol>() .FirstOrDefault(); // Create a new instance of an adaptive component family FamilyInstance instance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(PCFImport.doc, markerSymbol); // Get the placement points of this instance IList <ElementId> placePointIds = new List <ElementId>(); placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); // Set the position of each placement point ReferencePoint point1 = PCFImport.doc.GetElement(placePointIds[0]) as ReferencePoint; point1.Position = p1; ReferencePoint point2 = PCFImport.doc.GetElement(placePointIds[1]) as ReferencePoint; point2.Position = p2; return(instance); }
/// <summary> /// Creates a new instance of an adaptive component family. /// </summary> /// <param name="doc"></param> /// <param name="symbol"></param> /// <param name="pts"></param> /// <returns></returns> public static FamilyInstance CreateFamilyInstance(this Document doc, FamilySymbol symbol, IEnumerable <XYZ> pts) { if (doc == null) { throw new ArgumentNullException(nameof(doc)); } if (symbol == null) { throw new ArgumentNullException(nameof(symbol)); } if (pts == null) { throw new ArgumentNullException(nameof(pts)); } var tmpPts = pts.ToList(); // Creates a new instance of an adaptive component family. var result = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, symbol); // Gets the placement points of this instance. var placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(result); for (var i = 0; i < placePointIds.Count; i++) { if (doc.GetElement(placePointIds[i]) is ReferencePoint point) { point.Position = tmpPts[i]; } } return(result); }
public static GCAdaptiveComponent CreateComponentByPoints(GCRevitDocument doc, FamilySymbol sym, List <XYZ> locPts) { using (var subTrans = new SubTransaction(doc.Document)) { if (TransactionStatus.Started == subTrans.Start()) { var inst = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc.Document, sym); var comp = GCAdaptiveComponent.CreateGCAdaptiveComponent(inst); var ids = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(inst); if (ids.Count == locPts.Count) { for (var i = 0; i < ids.Count; i++) { var pt = doc.Document.GetElement(ids[i]); var trans = locPts[i] - (pt.Location as LocationPoint).Point; comp.MovePointById(ids[i], trans); } subTrans.Commit(); return(comp); } else { subTrans.RollBack(); throw new GCElementCreationException("The given point count does not match the instance point count"); } } else { throw new GCElementCreationException("Could not start subtransaction for adaptive component creation"); } } }
/// <summary> /// Internal constructor for the AdaptiveComponent wrapper /// </summary> /// <param name="pts">Points to use as reference</param> /// <param name="f">Face to use as reference</param> /// <param name="fs">FamilySymbol to place</param> private AdaptiveComponent(double[][] pts, ElementFaceReference f, FamilySymbol fs) { // if the family instance is present in trace... var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document); // just mutate it... if (oldFam != null) { InternalSetFamilyInstance(oldFam); if (fs.InternalFamilySymbol.Id != oldFam.Symbol.Id) { InternalSetFamilySymbol(fs); } InternalSetUvsAndFace(pts.ToUvs(), f.InternalReference); return; } // otherwise create a new family instance... TransactionManager.Instance.EnsureInTransaction(Document); var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, fs.InternalFamilySymbol); if (fam == null) { throw new Exception("An adaptive component could not be found or created."); } InternalSetFamilyInstance(fam); InternalSetUvsAndFace(pts.ToUvs(), f.InternalReference); TransactionManager.Instance.TransactionTaskDone(); }
public override Value Evaluate(FSharpList <Value> args) { FSharpList <Value> pts = ((Value.List)args[0]).Item; FamilySymbol fs = (FamilySymbol)((Value.Container)args[1]).Item; FamilyInstance ac = null; //if the adapative component already exists, then move the points if (Elements.Any()) { //mutate Element e; //...we attempt to fetch it from the document... if (dynUtils.TryGetElement(this.Elements[0], typeof(FamilyInstance), out e)) { ac = e as FamilyInstance; ac.Symbol = fs; } else { //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements[0] = ac.Id; } } else { //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements.Add(ac.Id); } if (ac == null) { throw new Exception("An adaptive component could not be found or created."); } IList <ElementId> placePointIds = new List <ElementId>(); placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac); if (placePointIds.Count() != pts.Count()) { throw new Exception("The input list of points does not have the same number of values required by the adaptive component."); } // Set the position of each placement point int i = 0; foreach (ElementId id in placePointIds) { ReferencePoint point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint; XYZ pt = (XYZ)((Value.Container)pts.ElementAt(i)).Item; point.Position = pt; i++; } return(Value.NewContainer(ac)); }
public ApplicationPlaceholderObject AdaptiveComponentToNative(AdaptiveComponent speckleAc) { var docObj = GetExistingElementByApplicationId(speckleAc.applicationId); string familyName = speckleAc["family"] as string != null ? speckleAc["family"] as string : ""; DB.FamilySymbol familySymbol = GetElementType <DB.FamilySymbol>(speckleAc); DB.FamilyInstance revitAc = null; //try update existing if (docObj != null) { try { var revitType = Doc.GetElement(docObj.GetTypeId()) as ElementType; // if family changed, tough luck. delete and let us create a new one. if (familyName != revitType.FamilyName) { Doc.Delete(docObj.Id); } else { revitAc = (DB.FamilyInstance)docObj; // check for a type change if (speckleAc.type != null && speckleAc.type != revitType.Name) { revitAc.ChangeTypeId(familySymbol.Id); } } } catch { //something went wrong, re-create it } } //create family instance if (revitAc == null) { revitAc = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Doc, familySymbol); } SetAdaptivePoints(revitAc, speckleAc.basePoints); AdaptiveComponentInstanceUtils.SetInstanceFlipped(revitAc, speckleAc.flipped); SetInstanceParameters(revitAc, speckleAc); return(new ApplicationPlaceholderObject { applicationId = speckleAc.applicationId, ApplicationGeneratedId = revitAc.UniqueId, NativeObject = revitAc }); }
/// <summary> /// Creates a new instance of an adaptive component family. /// </summary> /// <param name="doc"></param> /// <param name="symbol"></param> /// <param name="pts"></param> /// <returns></returns> public static FamilyInstance CreateFamilyInstance(this Document doc, FamilySymbol symbol, List <XYZ> pts) { // Creates a new instance of an adaptive component family. var result = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, symbol); // Gets the placement points of this instance. var placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(result); for (var i = 0; i < placePointIds.Count; i++) { if (doc.GetElement(placePointIds[i]) is ReferencePoint point) { point.Position = pts[i]; } } return(result); }
/// <summary> /// Initialize an AdaptiveComponent element /// </summary> /// <param name="pts">Points to use as reference</param> /// <param name="fs">FamilySymbol to place</param> private void InitAdaptiveComponent(Point[] pts, FamilySymbol fs) { // if the family instance is present in trace... var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document); // just mutate it... if (oldFam != null) { InternalSetFamilyInstance(oldFam); if (fs.InternalFamilySymbol.Id != oldFam.Symbol.Id) { InternalSetFamilySymbol(fs); } InternalSetPositions(pts.ToXyzs()); return; } // otherwise create a new family instance... TransactionManager.Instance.EnsureInTransaction(Document); using (Autodesk.Revit.DB.SubTransaction st = new SubTransaction(Document)) { try { st.Start(); var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, fs.InternalFamilySymbol); InternalSetFamilyInstance(fam); InternalSetPositions(pts.ToXyzs()); st.Commit(); } catch (Exception ex) { st.RollBack(); throw new ArgumentException(Revit.Properties.Resources.Adaptive_Component_Creation_Failed + ex.Message); } } TransactionManager.Instance.TransactionTaskDone(); // remember this value ElementBinder.SetElementForTrace(this.InternalElement); }
/// <summary> /// Initialize an AdaptiveComponent element /// </summary> /// <param name="uvParams">Parameters to use as reference</param> /// <param name="f">Face to use as reference</param> /// <param name="ft">familyType to place</param> private void InitAdaptiveComponent(double[][] uvParams, ElementFaceReference f, FamilyType ft) { // if the family instance is present in trace... var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document); // just mutate it... if (oldFam != null) { InternalSetFamilyInstance(oldFam); if (ft.InternalFamilySymbol.Id != oldFam.Symbol.Id) { InternalSetFamilySymbol(ft); } InternalSetUvsAndFace(uvParams.ToUvs(), f.InternalReference); return; } // otherwise create a new family instance... TransactionManager.Instance.EnsureInTransaction(Document); using (Autodesk.Revit.DB.SubTransaction st = new SubTransaction(Document)) { try { st.Start(); var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, ft.InternalFamilySymbol); InternalSetFamilyInstance(fam); InternalSetUvsAndFace(uvParams.ToUvs(), f.InternalReference); st.Commit(); } catch (Exception ex) { st.RollBack(); throw new ArgumentException(Revit.Properties.Resources.Adaptive_Component_Creation_Failed + ex.Message); } } TransactionManager.Instance.TransactionTaskDone(); ElementBinder.SetElementForTrace(InternalElement); }
//创建族实例 private void CreateFamilyInstance(List <XYZ> points1, List <XYZ> points2, FamilySymbol FamilySymbol, ExternalCommandData commandData, bool v) { //最后这个bool设定是为了设定两个list是否错开,是一一对应,还是错开一个相加 UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 if (v) { //如果不错开 for (int i = 0; i < points1.Count; i += 1) { FamilyInstance familyInstance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(uiDoc.Document, FamilySymbol); IList <ElementId> adaptivePoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance); //取得的参照点 ReferencePoint referencePoint1 = uiDoc.Document.GetElement(adaptivePoints[0]) as ReferencePoint; ReferencePoint referencePoint2 = uiDoc.Document.GetElement(adaptivePoints[1]) as ReferencePoint; //设置参照点坐标 referencePoint1.Position = points1[i]; referencePoint2.Position = points2[i]; } } else { //错开一个相加 for (int i = 0; i < points1.Count - 1; i += 1) { FamilyInstance familyInstance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(uiDoc.Document, FamilySymbol); IList <ElementId> adaptivePoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance); //取得的参照点 ReferencePoint referencePoint1 = uiDoc.Document.GetElement(adaptivePoints[0]) as ReferencePoint; ReferencePoint referencePoint2 = uiDoc.Document.GetElement(adaptivePoints[1]) as ReferencePoint; //设置参照点坐标 referencePoint1.Position = points1[i]; referencePoint2.Position = points2[i + 1]; } } }
/// <summary> /// Internal constructor for the AdaptiveComponent wrapper /// </summary> /// <param name="pts">Points to use as reference</param> /// <param name="fs">FamilySymbol to place</param> private AdaptiveComponent(Point[] pts, FamilySymbol fs) { // if the family instance is present in trace... var oldFam = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.FamilyInstance>(Document); // just mutate it... if (oldFam != null) { InternalSetFamilyInstance(oldFam); if (fs.InternalFamilySymbol.Id != oldFam.Symbol.Id) { InternalSetFamilySymbol(fs); } InternalSetPositions(pts.ToXyzs()); return; } // otherwise create a new family instance... TransactionManager.Instance.EnsureInTransaction(Document); var fam = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Element.Document, fs.InternalFamilySymbol); if (fam == null) { throw new Exception("An adaptive component could not be found or created."); } InternalSetFamilyInstance(fam); InternalSetPositions(pts.ToXyzs()); TransactionManager.Instance.TransactionTaskDone(); // remember this value ElementBinder.SetElementForTrace(this.InternalElement); }
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); }
public static Autodesk.Revit.DB.FamilyInstance ToNative(this SpeckleElementsClasses.AdaptiveComponent myAdaptiveComponent) { var(docObj, stateObj) = GetExistingElementByApplicationId(myAdaptiveComponent.ApplicationId, myAdaptiveComponent.Type); var familySymbol = GetFamilySymbolByFamilyNameAndType(myAdaptiveComponent.familyName, myAdaptiveComponent.familyType); if (familySymbol == null) { ConversionErrors.Add(new SpeckleConversionError { Message = $"Missing family: {myAdaptiveComponent.familyName} {myAdaptiveComponent.familyType}" }); throw new RevitFamilyNotFoundException($"No 'AdaptiveComponent' family found in the project"); } if (!familySymbol.IsActive) { familySymbol.Activate(); } if (myAdaptiveComponent.points == null) { ConversionErrors.Add(new SpeckleConversionError { Message = $"Wrong number of points supplied to adapive family" }); return(null); } if (docObj != null) // we have a document object already, so check if we can edit it. { var type = Doc.GetElement(docObj.GetTypeId()) as ElementType; // if family changed, tough luck - delete and rewind if (myAdaptiveComponent.familyName != type.FamilyName) { //delete and continue crating it Doc.Delete(docObj.Id); } // edit element else { var existingFamilyInstance = (Autodesk.Revit.DB.FamilyInstance)docObj; // check if type changed, and try and change it if (myAdaptiveComponent.familyType != null && (myAdaptiveComponent.familyType != type.Name)) { existingFamilyInstance.ChangeTypeId(familySymbol.Id); } SetAdaptiveComponentPoints(existingFamilyInstance, myAdaptiveComponent.points); SetElementParams(existingFamilyInstance, myAdaptiveComponent.parameters); return(existingFamilyInstance); } } // if we don't have a document object else { var component = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(Doc, familySymbol); SetAdaptiveComponentPoints(component, myAdaptiveComponent.points); SetElementParams(component, myAdaptiveComponent.parameters); return(component); } return(null); }
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; if (doc.IsFamilyDocument) { TaskDialog.Show("ОТМЕНЕНО", "Данная команда предназначена для запуска в документе проекта"); return(Result.Cancelled); } try { //Выбрать несколько файлов CSV с координатами Transform projectTransform = Utils.GetProjectCoordinatesTransform(doc); string[] filenames = null; WinForms.OpenFileDialog openFileDialog1 = new WinForms.OpenFileDialog(); string curDocPath = doc.PathName; if (!String.IsNullOrEmpty(curDocPath)) { openFileDialog1.InitialDirectory = Path.GetDirectoryName(curDocPath); } openFileDialog1.Filter = "csv files (*.csv)|*.csv"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; openFileDialog1.Title = "Выберите таблицы CSV с координатами 3d-полилиний"; if (openFileDialog1.ShowDialog() == WinForms.DialogResult.OK) { filenames = openFileDialog1.FileNames; List <List <XYZ> > lines3d = new List <List <XYZ> >(); if (Utils.ReadCoordinatesFromCSV(filenames, projectTransform, lines3d)) { //Загрузить семейство 3d линии если нет Family line3dFamily = Utils.GetFamily(doc, "3d line"); ElementId symId = line3dFamily.GetFamilySymbolIds().First(); FamilySymbol familySymbol = (FamilySymbol)doc.GetElement(symId); //Вывести форму для выбора семейств Categories categories = doc.Settings.Categories; ElementId IdGeneric = categories.get_Item(BuiltInCategory.OST_GenericModel).Id; SelectTypeWindow selectTypeWindow = new SelectTypeWindow(doc, IdGeneric); bool? result = selectTypeWindow.ShowDialog(); if (result != null && result.Value && selectTypeWindow.SelectedFamilySymbols.Count > 0) { familySymbol = selectTypeWindow.SelectedFamilySymbols.First(); } //Расставить линии по координатам using (Transaction tr = new Transaction(doc)) { tr.Start("Draw 3D line"); //активировать типоразмер if (!familySymbol.IsActive) { familySymbol.Activate(); doc.Regenerate(); } foreach (List <XYZ> ptList in lines3d) { for (int i = 0; i < ptList.Count - 1; i++) { FamilyInstance instance = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(doc, familySymbol); IList <ElementId> placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); ReferencePoint point1 = (ReferencePoint)doc.GetElement(placePointIds[0]); point1.Position = ptList[i]; ReferencePoint point2 = (ReferencePoint)doc.GetElement(placePointIds[1]); point2.Position = ptList[i + 1]; } } tr.Commit(); } } } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { } catch (Exception ex) { CommonException(ex, "Ошибка при вычерчивании 3d линии в Revit"); } return(Result.Succeeded); }
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 override Value Evaluate(FSharpList <Value> args) { if (!args[0].IsList) { throw new Exception("A list of UVs is required to place the Adaptive Component."); } FSharpList <Value> parameters = ((Value.List)args[0]).Item; var curveRef = ((Value.Container)args[1]).Item as Reference; var c = curveRef == null ? (Curve)((Value.Container)args[1]).Item : (Curve)dynRevitSettings.Doc.Document.GetElement(curveRef.ElementId).GetGeometryObjectFromReference(curveRef); var fs = (FamilySymbol)((Value.Container)args[2]).Item; FamilyInstance ac = null; //if the adapative component already exists, then move the points if (Elements.Any()) { //...we attempt to fetch it from the document... if (dynUtils.TryGetElement(this.Elements[0], out ac)) { ac.Symbol = fs; } else { //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements[0] = ac.Id; } } else { //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements.Add(ac.Id); } if (ac == null) { throw new Exception("An adaptive component could not be found or created."); } IList <ElementId> placePointIds = new List <ElementId>(); placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac); if (placePointIds.Count() != parameters.Count()) { throw new Exception("The input list of UVs does not have the same number of values required by the adaptive component."); } // Set the position of each placement point int i = 0; foreach (ElementId id in placePointIds) { var t = ((Value.Number)parameters.ElementAt(i)).Item; var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint; var ploc = new PointLocationOnCurve(PointOnCurveMeasurementType.NonNormalizedCurveParameter, t, PointOnCurveMeasureFrom.Beginning); var peref = dynRevitSettings.Revit.Application.Create.NewPointOnEdge(c.Reference, ploc); point.SetPointElementReference(peref); i++; } return(Value.NewContainer(ac)); }
public override Value Evaluate(FSharpList <Value> args) { if (!args[0].IsList) { throw new Exception("A list of UVs is required to place the Adaptive Component."); } FSharpList <Value> uvs = ((Value.List)args[0]).Item; var faceRef = ((Value.Container)args[1]).Item as Reference; var f = faceRef == null ? (Face)((Value.Container)args[1]).Item : (Face)dynRevitSettings.Doc.Document.GetElement(faceRef.ElementId).GetGeometryObjectFromReference(faceRef); var fs = (FamilySymbol)((Value.Container)args[2]).Item; FamilyInstance ac = null; //if the adapative component already exists, then move the points if (Elements.Any()) { //mutate Element e; //...we attempt to fetch it from the document... if (dynUtils.TryGetElement(this.Elements[0], typeof(FamilyInstance), out e)) { ac = e as FamilyInstance; ac.Symbol = fs; } else { //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements[0] = ac.Id; } } else { //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements.Add(ac.Id); } if (ac == null) { throw new Exception("An adaptive component could not be found or created."); } IList <ElementId> placePointIds = new List <ElementId>(); placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac); if (placePointIds.Count() != uvs.Count()) { throw new Exception("The input list of UVs does not have the same number of values required by the adaptive component."); } // Set the position of each placement point int i = 0; foreach (ElementId id in placePointIds) { var uv = (UV)((Value.Container)uvs.ElementAt(i)).Item; var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint; var peref = dynRevitSettings.Revit.Application.Create.NewPointOnFace(f.Reference, uv); point.SetPointElementReference(peref); i++; } return(Value.NewContainer(ac)); }
public override Value Evaluate(FSharpList <Value> args) { FSharpList <Value> pts = ((Value.List)args[0]).Item; var fs = (FamilySymbol)((Value.Container)args[1]).Item; FamilyInstance ac; var instData = new List <FamilyInstanceCreationData>(); var sw = new Stopwatch(); //if the adapative component already exists, then move the points if (Elements.Any()) { //mutate //...we attempt to fetch it from the document... if (dynUtils.TryGetElement(Elements[0], out ac)) { sw.Start(); ac.Symbol = fs; sw.Stop(); Debug.WriteLine(string.Format("{0} elapsed for updating family type on AC.", sw.Elapsed)); sw.Reset(); } else { sw.Start(); //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements[0] = ac.Id; sw.Stop(); Debug.WriteLine(string.Format("{0} elapsed for creating an AC.", sw.Elapsed)); sw.Reset(); } } else { sw.Start(); //create ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs); Elements.Add(ac.Id); sw.Stop(); Debug.WriteLine(string.Format("{0} elapsed for creating an AC.", sw.Elapsed)); sw.Reset(); } if (ac == null) { throw new Exception("An adaptive component could not be found or created."); } IList <ElementId> placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac); if (placePointIds.Count() != pts.Count()) { throw new Exception("The input list of points does not have the same number of values required by the adaptive component."); } sw.Start(); // Set the position of each placement point int i = 0; foreach (ElementId id in placePointIds) { var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint; var pt = (XYZ)((Value.Container)pts.ElementAt(i)).Item; point.Position = pt; i++; } sw.Stop(); Debug.WriteLine(string.Format("{0} elapsed for updating placement points of the AC.", sw.Elapsed)); sw.Reset(); return(Value.NewContainer(ac)); }