/// <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 Methods ****/ /***************************************************/ public static ModelInstance ModelInstanceFromRevit(this FamilyInstance adaptiveComponent, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null) { settings = settings.DefaultIfNull(); ModelInstance modelInstance = refObjects.GetValue <ModelInstance>(adaptiveComponent.Id); if (modelInstance != null) { return(modelInstance); } ElementType elementType = adaptiveComponent.Document.GetElement(adaptiveComponent.GetTypeId()) as ElementType; InstanceProperties instanceProperties = elementType.InstancePropertiesFromRevit(settings, refObjects) as InstanceProperties; IEnumerable <BH.oM.Geometry.Point> pts = AdaptiveComponentInstanceUtils.GetInstancePointElementRefIds(adaptiveComponent).Select(x => ((ReferencePoint)adaptiveComponent.Document.GetElement(x)).Position.PointFromRevit()); modelInstance = new ModelInstance { Properties = instanceProperties, Location = new CompositeGeometry { Elements = new List <IGeometry>(pts) } }; modelInstance.Name = adaptiveComponent.Name; //Set identifiers, parameters & custom data modelInstance.SetIdentifiers(adaptiveComponent); modelInstance.CopyParameters(adaptiveComponent, settings.ParameterSettings); modelInstance.SetProperties(adaptiveComponent, settings.ParameterSettings); refObjects.AddOrReplace(adaptiveComponent.Id, modelInstance); return(modelInstance); }
void ReconstructAdaptiveComponentByPoints ( Document doc, ref Autodesk.Revit.DB.Element element, IList <Rhino.Geometry.Point3d> points, Autodesk.Revit.DB.FamilySymbol type ) { var adaptivePoints = points.ConvertAll(GeometryEncoder.ToXYZ); if (!type.IsActive) { type.Activate(); } // Type ChangeElementTypeId(ref element, type.Id); if (element is FamilyInstance instance && AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(instance)) { var adaptivePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); if (adaptivePointIds.Count == adaptivePoints.Count) { int index = 0; foreach (var vertex in adaptivePointIds.Select(id => doc.GetElement(id)).Cast <ReferencePoint>()) { vertex.Position = adaptivePoints[index++]; } return; } } { var creationData = new List <Autodesk.Revit.Creation.FamilyInstanceCreationData> { Revit.ActiveUIApplication.Application.Create.NewFamilyInstanceCreationData(type, adaptivePoints) }; var newElementIds = doc.IsFamilyDocument ? doc.FamilyCreate.NewFamilyInstances2(creationData) : doc.Create.NewFamilyInstances2(creationData); if (newElementIds.Count != 1) { doc.Delete(newElementIds); throw new InvalidOperationException(); } var parametersMask = new BuiltInParameter[] { BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM, BuiltInParameter.ELEM_FAMILY_PARAM, BuiltInParameter.ELEM_TYPE_PARAM }; ReplaceElement(ref element, doc.GetElement(newElementIds.First()), parametersMask); } }
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(); } }
/***************************************************/ /**** 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); }
/// <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 void Move(XYZ transVect) { foreach (var id in AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(this.RevitInstance)) { MovePointById(id, transVect); } }
/// <summary> /// Set the positions of the InternalFamilyInstace from an array of uvs /// </summary> /// <param name="uvs"></param> /// <param name="faceReference"></param> private void InternalSetUvsAndFace(Autodesk.Revit.DB.UV[] uvs, Autodesk.Revit.DB.Reference faceReference) { TransactionManager.Instance.EnsureInTransaction(Document); var placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(InternalFamilyInstance); if (placePointIds.Count() != uvs.Length) { 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 (var id in placePointIds) { var uv = uvs[i]; var point = Document.GetElement(id) as Autodesk.Revit.DB.ReferencePoint; var peref = Document.Application.Create.NewPointOnFace(faceReference, uv); point.SetPointElementReference(peref); i++; } TransactionManager.Instance.TransactionTaskDone(); }
/// <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); }
/***************************************************/ private static Element ToRevitElement(this ModelInstance modelInstance, FamilySymbol familySymbol, RevitSettings settings) { Document doc = familySymbol.Document; if (AdaptiveComponentInstanceUtils.IsAdaptiveFamilySymbol(familySymbol)) { List <IGeometry> pts = (modelInstance.Location as CompositeGeometry)?.Elements; if (pts == null || !pts.All(x => x is BH.oM.Geometry.Point)) { BH.Engine.Reflection.Compute.RecordError($"A family could not be created based on the given ModelInstance because its family type is adaptive, but location was not a collection of points. BHoM_Guid: {modelInstance.BHoM_Guid}"); return(null); } return(Create.AdaptiveComponent(doc, familySymbol, pts.Select(x => ((BH.oM.Geometry.Point)x).ToRevit()).ToList(), settings)); } if (modelInstance.Location is BH.oM.Geometry.Point) { return(Create.FamilyInstance(doc, familySymbol, ((BH.oM.Geometry.Point)modelInstance.Location).ToRevit(), modelInstance.Orientation.ToRevit(), doc.GetElement(new ElementId(modelInstance.HostId)), settings)); } else if (modelInstance.Location is ICurve) { return(Create.FamilyInstance(doc, familySymbol, ((ICurve)modelInstance.Location).IToRevit(), doc.GetElement(new ElementId(modelInstance.HostId)), settings)); } else { BH.Engine.Reflection.Compute.RecordError($"A family could not be created based on the given ModelInstance because its location was neither a point nor a curve. BHoM_Guid: {modelInstance.BHoM_Guid}"); return(null); } }
//点的内插 private XYZ Interpolation(FamilyInstance chordInstance, XYZ hangerRodDownPoint, ExternalCommandData commandData) { Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档 Application revitApp = commandData.Application.Application; //取得应用程序 UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 IList <ElementId> chordPointIDs = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(chordInstance); List <XYZ> chordPoints = new List <XYZ>(); foreach (ElementId elementId in chordPointIDs) { Element e = uiDoc.Document.GetElement(elementId); ReferencePoint referencePoint = e as ReferencePoint; chordPoints.Add(referencePoint.Position); } XYZ p1 = new XYZ(chordPoints[0].X, chordPoints[0].Y, 0); XYZ p2 = new XYZ(chordPoints[1].X, chordPoints[1].Y, 0); XYZ p3 = new XYZ(hangerRodDownPoint.X, hangerRodDownPoint.Y, 0); Line line = Line.CreateBound(chordPoints[0], chordPoints[1]); //三维线 Line line1 = Line.CreateBound(p1, p2); //投影线 double L = Line.CreateBound(p1, p3).Length; //到起点的距离 double ratio = L / line1.Length; XYZ UPPoint = line.Evaluate(ratio, true); return(UPPoint); }
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> /// Set the positions of the InternalFamilyInstace from an array of parameters and curve /// </summary> /// <param name="parms"></param> /// <param name="c"></param> private void InternalSetParamsAndCurve(double[] parms, Autodesk.Revit.DB.Reference c) { TransactionManager.Instance.EnsureInTransaction(Document); var placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(InternalFamilyInstance); if (placePointIds.Count() != parms.Length) { throw new Exception("The input list of parameters 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 = parms[i]; var point = Document.GetElement(id) as Autodesk.Revit.DB.ReferencePoint; var ploc = new PointLocationOnCurve(PointOnCurveMeasurementType.NormalizedCurveParameter, t, PointOnCurveMeasureFrom.Beginning); var peref = Document.Application.Create.NewPointOnEdge(c, ploc); point.SetPointElementReference(peref); i++; } TransactionManager.Instance.TransactionTaskDone(); }
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; } }
/// <summary> /// Set the positions of the InternalFamilyInstace from an array of uvs /// </summary> /// <param name="uvs"></param> /// <param name="faceReference"></param> private void InternalSetUvsAndFace(Autodesk.Revit.DB.UV[] uvs, Autodesk.Revit.DB.Reference faceReference) { TransactionManager.Instance.EnsureInTransaction(Document); var placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(InternalFamilyInstance); if (placePointIds.Count() != uvs.Length) { throw new Exception(Properties.Resources.InputUVParamsMismatch); } // Set the position of each placement point int i = 0; foreach (var id in placePointIds) { var uv = uvs[i]; var point = Document.GetElement(id) as Autodesk.Revit.DB.ReferencePoint; var peref = Document.Application.Create.NewPointOnFace(faceReference, uv); point.SetPointElementReference(peref); i++; } 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 static object Wrap(Autodesk.Revit.DB.Panel ele, bool isRevitOwned) { if (AdaptiveComponentInstanceUtils.IsAdaptiveFamilySymbol(ele.Symbol)) { return(AdaptiveComponent.FromExisting(ele, isRevitOwned)); } return(CurtainPanel.FromExisting(ele, isRevitOwned)); }
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 }); }
private List <Point> GetAdaptivePoints(DB.FamilyInstance revitAc) { var pointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(revitAc).ToList(); var points = new List <Point>(); for (int i = 0; i < pointIds.Count; i++) { var point = Doc.GetElement(pointIds[i]) as ReferencePoint; points.Add(PointToSpeckle(point.Position)); } return(points); }
public List <XYZ> GetInternalPoints(FamilyInstance adaptiveComponent) { var pts = new List <XYZ>(); var ids = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(adaptiveComponent); foreach (var id in ids) { var p = DocumentManager.Instance.CurrentDBDocument.GetElement(id) as Autodesk.Revit.DB.ReferencePoint; pts.Add(p.Position); } return(pts); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var doc = commandData.Application.ActiveUIDocument.Document; //select adaptive family instance var elementid = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, new AdaptiveComponentSelectionFilter(), "Select adaptive component to project:").ElementId; var familyInstance = doc.GetElement(elementid) as FamilyInstance; //select target ElementId targetElementId = commandData.Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element, "Select targert element:").ElementId; //the reference intersector requires a 3d view. Find first 3d view. //Note: If the 3d view found has elements hidden the projection many not work as expected. View3D view3d = Utils.GetFirstView3d(doc); //start a transaction and do projection using (Transaction transaction = new Transaction(doc)) { transaction.Start("Project adaptive component"); //get placement points var placementPoints = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(familyInstance); foreach (ElementId id in placementPoints) { //get current location var placementPoint = doc.GetElement(id) as ReferencePoint; var currentLocation = placementPoint.Position; //do projection IEnumerable <XYZ> points = Utils.GetPointProjectedVertically(view3d, targetElementId, currentLocation); //Find lowest point var lowestPoint = Utils.GetLowestXYZ(points); //move point placementPoint.Position = lowestPoint; } transaction.Commit(); } return(Result.Succeeded); }
private AdaptiveComponent AdaptiveComponentToSpeckle(DB.FamilyInstance revitAc) { var speckleAc = new AdaptiveComponent(); speckleAc.type = Doc.GetElement(revitAc.GetTypeId()).Name; speckleAc.basePoints = GetAdaptivePoints(revitAc); speckleAc.flipped = AdaptiveComponentInstanceUtils.IsInstanceFlipped(revitAc); speckleAc.displayMesh = GetElementMesh(revitAc); GetAllRevitParamsAndIds(speckleAc, revitAc); return(speckleAc); }
public XYZ GetAdaptivePointLocation(Document document, Reference elementReference) { // Get the family instance of the selected element Autodesk.Revit.DB.FamilyInstance instance = document.GetElement(elementReference.ElementId) as Autodesk.Revit.DB.FamilyInstance; // Get the placement points of this instance ElementId placePointIds = (AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance)).First(); ReferencePoint point = document.GetElement(placePointIds) as ReferencePoint; return(point.Position); }
public bool AllowElement(Element e) { //try cast element to familyInstance var familyInstance = e as FamilyInstance; //if cast succeeds, check if it is an adaptive component if (familyInstance != null) { return(AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(familyInstance)); } //cast failed, therefore not an adaptive component return(false); }
public static AbstractFamilyInstance Wrap(Autodesk.Revit.DB.FamilyInstance ele, bool isRevitOwned) { if (AdaptiveComponentInstanceUtils.HasAdaptiveFamilySymbol(ele)) { return(AdaptiveComponent.FromExisting(ele, isRevitOwned)); } if (ele.StructuralType != Autodesk.Revit.DB.Structure.StructuralType.NonStructural) { return(StructuralFraming.FromExisting(ele, isRevitOwned)); } return(FamilyInstance.FromExisting(ele, isRevitOwned)); }
public override Value Evaluate(FSharpList <Value> args) { var instance = (FamilyInstance)((Value.Container)args[0]).Item; // ADAPTIVE COMPONENT if (AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(instance)) { var refPtIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(instance); FSharpList <Value> refPts = FSharpList <Value> .Empty; foreach (var id in refPtIds) { var pt = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint; refPts = FSharpList <Value> .Cons(Value.NewContainer(pt.Position), refPts); } return(Value.NewList(Utils.SequenceToFSharpList(refPts.Reverse()))); } // INSTANCE WITH PLACEMENT POINT var ptRefs = instance.GetFamilyPointPlacementReferences(); if (ptRefs.Any()) { var pts = ptRefs.Select(x => x.Location.Origin); var containers = pts.Select(Value.NewContainer); return(Value.NewList(Utils.SequenceToFSharpList(containers))); } LocationPoint point = null; LocationCurve c = null; // INSTANCE WITH LOCATION POINT point = instance.Location as LocationPoint; if (point != null) { return(Value.NewContainer(point.Point)); } //INSTANCE WITH LOCATION CURVE c = instance.Location as LocationCurve; if (c != null) { return(Value.NewContainer(c.Curve)); } throw new Exception("A location could not be found for the selected family instance(s)."); }
/// <summary> /// Update the placement points of the adaptive component instance to the given points /// </summary> /// <param name="fi"></param> /// <param name="pnt"></param> private static void UpdatePlacementPoints(Autodesk.Revit.DB.FamilyInstance fi, XYZ[] pnts) { IList <ElementId> placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(fi); if (placePointIds.Count() != pnts.Count()) { throw new Exception(Properties.Resources.InputPointParamsMismatch); } int count = placePointIds.Count; for (int i = 0; i < count; i++) { var point = (Autodesk.Revit.DB.ReferencePoint)Document.GetElement(placePointIds[i]); point.Position = pnts[i]; } }
private void SetAdaptivePoints(DB.FamilyInstance revitAc, List <Point> points) { var pointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(revitAc).ToList(); if (pointIds.Count != points.Count) { ConversionErrors.Add(new Exception("Adaptive family error\nWrong number of points supplied to adaptive family")); return; } //set adaptive points for (int i = 0; i < pointIds.Count; i++) { var point = Doc.GetElement(pointIds[i]) as ReferencePoint; point.Position = PointToNative(points[i]); } }
internal void AssertValidSpeckleElement(DB.Element elem, Base spkElem) { Assert.NotNull(elem); Assert.NotNull(spkElem); Assert.NotNull(spkElem["parameters"]); Assert.NotNull(spkElem["elementId"]); // HACK: This is not reliable or acceptable as a testing strategy. if (!(elem is DB.Architecture.Room || elem is DB.Mechanical.Duct || AdaptiveComponentInstanceUtils.IsAdaptiveComponentInstance(elem as FamilyInstance))) { Assert.Equal(elem.Name, spkElem["type"]); } //Assert.NotNull(spkElem.baseGeometry); //Assert.NotNull(spkElem.level); //Assert.NotNull(spkRevit.displayMesh); }
/// <summary> /// Construct from an existing instance of an AdaptiveComponent. /// </summary> /// <param name="familyInstance"></param> /// <param name="isRevitOwned"></param> /// <returns></returns> internal static AdaptiveComponent FromExisting(Autodesk.Revit.DB.FamilyInstance familyInstance, bool isRevitOwned) { if (familyInstance == null) { throw new ArgumentNullException("familyInstance"); } // Not all family instances are adaptive components if (!AdaptiveComponentInstanceUtils.HasAdaptiveFamilySymbol(familyInstance)) { throw new Exception("The FamilyInstance is not an adaptive component"); } return(new AdaptiveComponent(familyInstance) { IsRevitOwned = isRevitOwned }); }