Пример #1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            try
            {
                Selection selection = uidoc.Selection;

                // Pick a light fixture.

                var pickedLightReference = selection.PickObject(
                    ObjectType.Element, new LightPickFilter(),
                    "Please select lighting fixture to place");

                if (null == pickedLightReference)
                {
                    return(Result.Failed);
                }

                // Get Family Instance of the selected light reference.

                FamilyInstance lightFamilyInstance
                    = doc.GetElement(pickedLightReference)
                      as FamilyInstance;

                // Get FamilySymbol of the family instance.

                if (lightFamilyInstance == null)
                {
                    return(Result.Failed);
                }

                FamilySymbol lightFamilySymbol
                    = lightFamilyInstance.Symbol;

                // Determine this family's placement type.
                // This is an important step towards determining
                // which NewFamilyInstance overload to use to
                // place new instances of it.

                FamilyPlacementType placementType
                    = lightFamilySymbol.Family
                      .FamilyPlacementType;

                // Placement type is WorkPlaneBased, so determine
                // the host face that defines the work plane.

                Reference hostFace = lightFamilyInstance.HostFace;

                // Prompt for placement point of copy.

                XYZ placeXyzPoint = selection.PickPoint(
                    "Select point to place new light:");

                // The location point gives Z elevation value.

                LocationPoint lp = lightFamilyInstance.Location
                                   as LocationPoint;

                // Assuming the ceiling is horizontal, set
                // the location point Z value for the copy
                // equal to the original.

                placeXyzPoint = new XYZ(placeXyzPoint.X,
                                        placeXyzPoint.Y, lp.Point.Z);

                using (var trans = new Transaction(doc))
                {
                    trans.Start("LightArray");

                    FamilyInstance lightFamilyInstance2
                        = doc.Create.NewFamilyInstance(
                              hostFace, placeXyzPoint, XYZ.BasisX,
                              lightFamilySymbol);

                    trans.Commit();
                }
            }
            catch (OperationCanceledException)
            {
                return(Result.Cancelled);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
            return(Result.Succeeded);
        }
Пример #2
0
        /***************************************************/

        internal static void HostIgnoredWarning(this FamilyInstance familyInstance)
        {
            FamilyPlacementType fpt = ((FamilySymbol)familyInstance.Document.GetElement(familyInstance.GetTypeId())).Family.FamilyPlacementType;

            BH.Engine.Reflection.Compute.RecordWarning($"Family with placement type {fpt} does not need a host element, therefore the input host has been ignored. ElementId: {familyInstance?.Id.IntegerValue}");
        }
Пример #3
0
        /***************************************************/

        internal static void ProjectedOnXYWarning(this FamilyInstance familyInstance)
        {
            FamilyPlacementType fpt = ((FamilySymbol)familyInstance.Document.GetElement(familyInstance.GetTypeId())).Family.FamilyPlacementType;

            BH.Engine.Reflection.Compute.RecordWarning($"Family with placement type {fpt} needs to be placed vertically, therefore transform out of XY plane has been ignored. ElementId: {familyInstance?.Id.IntegerValue}");
        }
Пример #4
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static FamilyInstance ToRevitFamilyInstance(this Column framingElement, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (framingElement == null || document == null)
            {
                return(null);
            }

            FamilyInstance familyInstance = refObjects.GetValue <FamilyInstance>(document, framingElement.BHoM_Guid);

            if (familyInstance != null)
            {
                return(familyInstance);
            }

            settings = settings.DefaultIfNull();

            if (framingElement.Location == null)
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Revit element could not be created because the driving curve of a BHoM object is null. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            if (framingElement.Location as BH.oM.Geometry.Line == null)
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Revit does only support line-based columns. Try pushing your element as a beam instead. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            if (((BH.oM.Geometry.Line)framingElement.Location).Start.Z >= ((BH.oM.Geometry.Line)framingElement.Location).End.Z)
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Start point of Revit columns need to have lower elevation than the end point. Have a look at flipping your location curves. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            Level level = document.LevelBelow(framingElement.Location, settings);

            if (level == null)
            {
                return(null);
            }

            Line columnLine = framingElement.Location.IToRevit() as Line;

            FamilySymbol familySymbol = framingElement.Property.ToRevitElementType(document, framingElement.BuiltInCategories(document), settings, refObjects);

            if (familySymbol == null)
            {
                familySymbol = framingElement.ElementType(document, settings) as FamilySymbol;
            }

            if (familySymbol == null)
            {
                Compute.ElementTypeNotFoundWarning(framingElement);
                return(null);
            }

            FamilyPlacementType familyPlacementType = familySymbol.Family.FamilyPlacementType;

            if (familyPlacementType != FamilyPlacementType.CurveBased && familyPlacementType != FamilyPlacementType.CurveBasedDetail && familyPlacementType != FamilyPlacementType.CurveDrivenStructural && familyPlacementType != FamilyPlacementType.TwoLevelsBased)
            {
                Compute.InvalidFamilyPlacementTypeError(framingElement, familySymbol);
                return(null);
            }

            familyInstance = document.Create.NewFamilyInstance(columnLine, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Column);
            document.Regenerate();

            familyInstance.CheckIfNullPush(framingElement);
            if (familyInstance == null)
            {
                return(null);
            }

            oM.Physical.FramingProperties.ConstantFramingProperty barProperty = framingElement.Property as oM.Physical.FramingProperties.ConstantFramingProperty;
            if (barProperty != null)
            {
                //TODO: if the material does not get assigned an error should be thrown?
                if (barProperty.Material != null)
                {
                    Autodesk.Revit.DB.Material material = document.GetElement(new ElementId(BH.Engine.Adapters.Revit.Query.ElementId(barProperty.Material))) as Autodesk.Revit.DB.Material;
                    if (material != null)
                    {
                        Parameter param = familyInstance.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
                        if (param != null && param.HasValue && !param.IsReadOnly)
                        {
                            familyInstance.StructuralMaterialId = material.Id;
                        }
                        else
                        {
                            BH.Engine.Reflection.Compute.RecordWarning(string.Format("The BHoM material has been correctly converted, but the property could not be assigned to the Revit element. ElementId: {0}", familyInstance.Id));
                        }
                    }
                }
            }

            // Make sure the top is above base, otherwise Revit will complain for no reason.
            familyInstance.get_Parameter((BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM)).Set(-1e+3);
            familyInstance.get_Parameter((BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM)).Set(1e+3);

            familyInstance.CopyParameters(framingElement, settings);
            familyInstance.SetLocation(framingElement, settings);

            refObjects.AddOrReplace(framingElement, familyInstance);
            return(familyInstance);
        }
Пример #5
0
        /***************************************************/

        public static FamilyInstance ToRevitFamilyInstance(this IFramingElement framingElement, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (framingElement == null || document == null)
            {
                return(null);
            }

            FamilyInstance familyInstance = refObjects.GetValue <FamilyInstance>(document, framingElement.BHoM_Guid);

            if (familyInstance != null)
            {
                return(familyInstance);
            }

            settings = settings.DefaultIfNull();

            if (framingElement.Location == null)
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Revit element could not be created because the driving curve of a BHoM object is null. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            if (!framingElement.Location.IIsPlanar())
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Revit framing does only support planar curves, element could not be created. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            Curve revitCurve = framingElement.Location.IToRevit();

            if (revitCurve == null)
            {
                BH.Engine.Reflection.Compute.RecordError(string.Format("Revit element could not be created because of curve conversion issues. BHoM_Guid: {0}", framingElement.BHoM_Guid));
                return(null);
            }

            Level level = document.LevelBelow(framingElement.Location, settings);

            FamilySymbol familySymbol = framingElement.Property.ToRevitElementType(document, framingElement.BuiltInCategories(document), settings, refObjects);

            if (familySymbol == null)
            {
                familySymbol = framingElement.ElementType(document, settings) as FamilySymbol;
            }

            if (familySymbol == null)
            {
                Compute.ElementTypeNotFoundWarning(framingElement);
                return(null);
            }

            FamilyPlacementType familyPlacementType = familySymbol.Family.FamilyPlacementType;

            if (familyPlacementType != FamilyPlacementType.CurveBased && familyPlacementType != FamilyPlacementType.CurveBasedDetail && familyPlacementType != FamilyPlacementType.CurveDrivenStructural && familyPlacementType != FamilyPlacementType.TwoLevelsBased)
            {
                Compute.InvalidFamilyPlacementTypeError(framingElement, familySymbol);
                return(null);
            }

            if (framingElement is Beam)
            {
                familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Beam);
            }
            else if (framingElement is Bracing || framingElement is Cable)
            {
                familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Brace);
            }
            else
            {
                familyInstance = document.Create.NewFamilyInstance(revitCurve, familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming);
            }

            document.Regenerate();

            familyInstance.CheckIfNullPush(framingElement);
            if (familyInstance == null)
            {
                return(null);
            }

            oM.Physical.FramingProperties.ConstantFramingProperty barProperty = framingElement.Property as oM.Physical.FramingProperties.ConstantFramingProperty;
            if (barProperty != null)
            {
                //TODO: if the material does not get assigned an error should be thrown?
                if (barProperty.Material != null)
                {
                    Material material = document.GetElement(new ElementId(BH.Engine.Adapters.Revit.Query.ElementId(barProperty.Material))) as Material;
                    if (material != null)
                    {
                        Parameter param = familyInstance.get_Parameter(BuiltInParameter.STRUCTURAL_MATERIAL_PARAM);
                        if (param != null && param.HasValue && !param.IsReadOnly)
                        {
                            familyInstance.StructuralMaterialId = material.Id;
                        }
                        else
                        {
                            BH.Engine.Reflection.Compute.RecordWarning(string.Format("The BHoM material has been correctly converted, but the property could not be assigned to the Revit element. ElementId: {0}", familyInstance.Id));
                        }
                    }
                }
            }

            //Set the insertion point to centroid.
            Parameter zJustification = familyInstance.get_Parameter(BuiltInParameter.Z_JUSTIFICATION);

            if (zJustification != null && !zJustification.IsReadOnly)
            {
                zJustification.Set((int)Autodesk.Revit.DB.Structure.ZJustification.Origin);
            }

            familyInstance.CopyParameters(framingElement, settings);
            familyInstance.SetLocation(framingElement, settings);

            if (familyInstance.StructuralMaterialType != StructuralMaterialType.Concrete && familyInstance.StructuralMaterialType != StructuralMaterialType.PrecastConcrete)
            {
                StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 0);
                StructuralFramingUtils.DisallowJoinAtEnd(familyInstance, 1);
            }

            refObjects.AddOrReplace(framingElement, familyInstance);
            return(familyInstance);
        }
Пример #6
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            // Revit application documents.
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            try
            {
                Element        el = SelectElement(uidoc, doc);
                FamilyInstance lightFamilyInstance = el as FamilyInstance;

                FamilySymbol        lightFamilySymbol = lightFamilyInstance.Symbol;
                FamilyPlacementType placementType     = lightFamilySymbol.Family.FamilyPlacementType;


                Reference hostFace = lightFamilyInstance.HostFace;



                //XYZ Bo1 = uidoc.Selection.PickPoint();
                XYZ Po1 = uidoc.Selection.PickPoint("Select point to place new light:");



                XYZ           Bo2 = uidoc.Selection.PickPoint();
                LocationPoint lp  = lightFamilyInstance.Location as LocationPoint;
                Po1 = new XYZ(Po1.X, Po1.Y, lp.Point.Z);
                Bo2 = new XYZ(Bo2.X, Bo2.Y, lp.Point.Z);


                // Modify document within a transaction

                int  N;
                bool retN = CollectDataInput("Please input an integer:", out N);
                int  M;
                bool retM = CollectDataInput("Please input an integer:", out M);


                using (Transaction tx = new Transaction(doc))
                {
                    // int N = 2, M = 2;
                    double z, x1, x2, xt, x, xp, xs, y1, y2, yt, y, yp;
                    z = Po1.Z;

                    x1 = Po1.X; y1 = Po1.Y;
                    x2 = Bo2.X; y2 = Bo2.Y;
                    xt = x2 - x1;
                    yt = y2 - y1;
                    y  = yt / (2 * N);
                    x  = xt / (2 * M);
                    xp = x1 + x;
                    xs = xp;
                    yp = y1 + y;


                    int i = 1, j = 1;
                    for (i = 1; i <= N; i++)
                    {
                        xp = xs;
                        for (j = 1; j <= M; j++)
                        {
                            XYZ pickPoint = new XYZ(xp, yp, z);

                            tx.Start("Placing Light");
                            FamilyInstance lightFamilyInstance2 = doc.Create.
                                                                  NewFamilyInstance(hostFace, pickPoint, XYZ.BasisX, lightFamilySymbol);
                            tx.Commit();

                            xp = xp + 2 * x;
                        }
                        yp = yp + 2 * y;
                    }
                }
            }
            catch (OperationCanceledException) { }



            return(Result.Succeeded);
        }