예제 #1
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            DB.HostObject host = null;
            if (!DA.GetData("Host", ref host) || host is null)
            {
                return;
            }

            var doc = host.Document;
            {
                var bottom = DB.HostObjectUtils.GetBottomFaces(host).Select(reference => new Types.Face(doc, reference));
                DA.SetDataList("Bottom", bottom);
            }

            {
                var top = DB.HostObjectUtils.GetTopFaces(host).Select(reference => new Types.Face(doc, reference));
                DA.SetDataList("Top", top);
            }

            {
                var interior = DB.HostObjectUtils.GetSideFaces(host, DB.ShellLayerType.Interior).Select(reference => new Types.Face(doc, reference));
                DA.SetDataList("Interior", interior);
            }

            {
                var exterior = DB.HostObjectUtils.GetSideFaces(host, DB.ShellLayerType.Exterior).Select(reference => new Types.Face(doc, reference));
                DA.SetDataList("Exterior", exterior);
            }
        }
예제 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var location = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(double.NaN, double.NaN, double.NaN), new Rhino.Geometry.Vector3d(double.NaN, double.NaN, double.NaN));

            DA.GetData("Position", ref location);

            FamilySymbol familySymbol = null;

            DA.GetData("Type", ref familySymbol);

            Autodesk.Revit.DB.Level level = null;
            DA.GetData("Level", ref level);
            if (level == null)
            {
                level = Revit.ActiveDBDocument.FindLevelByElevation(location.Origin.Z / Revit.ModelUnits);
            }

            Autodesk.Revit.DB.HostObject host = null;
            DA.GetData("Host", ref host);

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, location, familySymbol, host, level));
        }
예제 #3
0
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            DB.HostObject host = null;
            if (!DA.GetData("Host", ref host) || host is null)
            {
                return;
            }

            var doc = host.Document;

            var inserts = new HashSet <DB.ElementId>(host.FindInserts(false, false, false, false));

            DA.SetDataList("Inserts", inserts.Select(x => Types.Element.FromElementId(doc, x)));

            var shared = new HashSet <DB.ElementId>(host.FindInserts(false, false, false, true));

            shared.ExceptWith(inserts);
            DA.SetDataList("Shared", shared.Select(x => Types.Element.FromElementId(doc, x)));

            var openings = new HashSet <DB.ElementId>(host.FindInserts(true, false, false, false));

            openings.ExceptWith(inserts);
            DA.SetDataList("Openings", openings.Select(x => Types.Element.FromElementId(doc, x)));

            var shadows = new HashSet <DB.ElementId>(host.FindInserts(false, true, false, false));

            shadows.ExceptWith(inserts);
            DA.SetDataList("Shadows", shadows.Select(x => Types.Element.FromElementId(doc, x)));

            var walls = new HashSet <DB.ElementId>(host.FindInserts(false, false, true, false));

            walls.ExceptWith(inserts);
            DA.SetDataList("Walls", walls.Select(x => Types.Element.FromElementId(doc, x)));
        }
예제 #4
0
        /// <summary>
        /// This node will return the bottom face or faces for the input host object. This particular method works for ceilings, roofs, or floors.
        /// </summary>
        /// <param name="hostObject">The host object to retrieve bottom faces for.</param>
        /// <returns></returns>
        public static IEnumerable <List <Surface> > BottomSurface(global::Revit.Elements.Element hostObject)
        {
            Autodesk.Revit.DB.HostObject internalHost = hostObject.InternalElement as Autodesk.Revit.DB.HostObject;

            IList <Reference> sideRefs = HostObjectUtils.GetBottomFaces(internalHost);

            List <Autodesk.Revit.DB.Face> exteriorGeometryObjects = new List <Autodesk.Revit.DB.Face>(sideRefs.Select(r => internalHost.GetGeometryObjectFromReference(r)).Cast <Autodesk.Revit.DB.Face>());

            return(exteriorGeometryObjects.Select(g => g.ToProtoType(true).ToList()));
        }
        protected override void TrySolveInstance(IGH_DataAccess DA)
        {
            DB.HostObject host = null;
            if (!DA.GetData("Host", ref host) || host is null)
            {
                return;
            }

            using (var filter = new DB.ElementClassFilter(typeof(DB.Sketch)))
            {
                var sketckIds = host.GetDependentElements(filter);
                if (sketckIds.Select(x => host.Document.GetElement(x)).FirstOrDefault() is DB.Sketch sketch)
                {
                    DA.SetData("Plane", sketch.SketchPlane.GetPlane().ToPlane());
                    DA.SetDataList("Profile", sketch.Profile.ToPolyCurves());
                }
            }
        }
예제 #6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Autodesk.Revit.DB.HostObject host = null;
            if (!DA.GetData("Host", ref host) || host is null)
            {
                return;
            }

            var doc = Revit.ActiveDBDocument;

            try
            {
                var bottom = HostObjectUtils.GetBottomFaces(host).Select(reference => new Types.Face(reference, doc));
                DA.SetDataList("Bottom", bottom);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException) { }

            try
            {
                var top = HostObjectUtils.GetTopFaces(host).Select(reference => new Types.Face(reference, doc));
                DA.SetDataList("Top", top);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException) { }

            try
            {
                var interior = HostObjectUtils.GetSideFaces(host, ShellLayerType.Interior).Select(reference => new Types.Face(reference, doc));
                DA.SetDataList("Interior", interior);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException) { }

            try
            {
                var exterior = HostObjectUtils.GetSideFaces(host, ShellLayerType.Exterior).Select(reference => new Types.Face(reference, doc));
                DA.SetDataList("Exterior", exterior);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException) { }
        }
예제 #7
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Plane location,
            Autodesk.Revit.DB.FamilySymbol familySymbol,
            Autodesk.Revit.DB.HostObject host,
            Autodesk.Revit.DB.Level level
        )
        {
            var element = PreviousElement(doc, Iteration);

            if (!element?.Pinned ?? false)
            {
                ReplaceElement(doc, DA, Iteration, element);
            }
            else
            {
                try
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        location = location.Scale(scaleFactor);
                    }

                    if (!location.IsValid)
                    {
                        throw new Exception(string.Format("Parameter '{0}' must be a valid point.", Params.Input[0].Name));
                    }

                    if (familySymbol == null)
                    {
                        throw new Exception(string.Format("Parameter '{0}' must be a FamilySymbol point.", Params.Input[1].Name));
                    }

                    if (level == null)
                    {
                        throw new Exception(string.Format("Parameter '{0}' must be a valid Level.", Params.Input[2].Name));
                    }

                    if (host == null && familySymbol.Family.FamilyPlacementType == FamilyPlacementType.OneLevelBasedHosted)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, string.Format("Parameter '{0}' must be a valid HostObject.", Params.Input[3].Name));
                    }

                    if (!familySymbol.IsActive)
                    {
                        familySymbol.Activate();
                    }

                    if (element is FamilyInstance && familySymbol.Id != element.GetTypeId())
                    {
                        var newElmentId = element.ChangeTypeId(familySymbol.Id);
                        if (newElmentId != ElementId.InvalidElementId)
                        {
                            element = doc.GetElement(newElmentId);
                        }
                    }

                    bool hasSameHost = false;
                    if (element is FamilyInstance familyInstance)
                    {
                        hasSameHost = (familyInstance.Host?.Id ?? ElementId.InvalidElementId) == (host?.Id ?? ElementId.InvalidElementId);
                        if (familyInstance.Host == null)
                        {
                            if (element?.get_Parameter(BuiltInParameter.INSTANCE_FREE_HOST_PARAM) is Parameter freeHostParam)
                            {
                                var freeHostName = freeHostParam.AsString();
                                hasSameHost = freeHostName.EndsWith(host?.Name ?? level.Name);
                            }
                        }
                    }

                    if
                    (
                        hasSameHost &&
                        element is FamilyInstance &&
                        element.Location is LocationPoint locationPoint
                    )
                    {
                        using (var levelParam = element.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM))
                            if (levelParam.AsElementId() != level.Id)
                            {
                                levelParam.Set(level.Id);
                                doc.Regenerate();
                            }

                        var newOrigin = location.Origin.ToHost();
                        if (!newOrigin.IsAlmostEqualTo(locationPoint.Point))
                        {
                            element.Pinned      = false;
                            locationPoint.Point = newOrigin;
                            element.Pinned      = true;
                        }
                    }
                    else
                    {
                        var creationDataList = new List <Autodesk.Revit.Creation.FamilyInstanceCreationData>()
                        {
                            new Autodesk.Revit.Creation.FamilyInstanceCreationData(location.Origin.ToHost(), familySymbol, host, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural)
                        };

                        ICollection <ElementId> newElementIds = null;

                        if (doc.IsFamilyDocument)
                        {
                            newElementIds = doc.FamilyCreate.NewFamilyInstances2(creationDataList);
                        }
                        else
                        {
                            newElementIds = doc.Create.NewFamilyInstances2(creationDataList);
                        }

                        if (newElementIds.Count == 1)
                        {
                            element = CopyParametersFrom(doc.GetElement(newElementIds.First()), element);
                            element?.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM).Set(level.Id);
                        }
                        else
                        {
                            element = null;
                        }
                    }

                    if (element is FamilyInstance instance && instance.Host == null)
                    {
                        element.Pinned = false;
                        SetTransform(instance, location.Origin.ToHost(), location.XAxis.ToHost(), location.YAxis.ToHost());
                        element.Pinned = true;
                    }

                    ReplaceElement(doc, DA, Iteration, element);
                }
                catch (Exception e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                    ReplaceElement(doc, DA, Iteration, null);
                }
            }
        }
 protected internal HostObject(DB.HostObject host) : base(host)
 {
 }
예제 #9
0
 public HostObject(DB.HostObject host) : base(host)
 {
 }
예제 #10
0
 public HostObject(Autodesk.Revit.DB.HostObject host) : base(host)
 {
 }