public static Face SelectFace(UIApplication uiapp)
        {
            Document doc = uiapp.ActiveUIDocument.Document;

            IEnumerable <Document> doc2 = GetLinkedDocuments(
                doc);

            Autodesk.Revit.UI.Selection.Selection sel
                = uiapp.ActiveUIDocument.Selection;

            Reference pickedRef = sel.PickObject(
                Autodesk.Revit.UI.Selection.ObjectType.PointOnElement,
                "Please select a Face");

            Element elem = doc.GetElement(pickedRef.ElementId);

            Type et = elem.GetType();

            if (typeof(RevitLinkType) == et ||
                typeof(RevitLinkInstance) == et ||
                typeof(Instance) == et)
            {
                foreach (Document d in doc2)
                {
                    if (elem.Name.Contains(d.Title))
                    {
                        Reference pickedRefInLink = pickedRef
                                                    .CreateReferenceInLink();

                        Element myElement = d.GetElement(
                            pickedRefInLink.ElementId);

                        Face myGeometryObject = myElement
                                                .GetGeometryObjectFromReference(
                            pickedRefInLink) as Face;

                        return(myGeometryObject);
                    }
                }
            }
            else
            {
                Element myElement = doc.GetElement(
                    pickedRef.ElementId);

                Face myGeometryObject = myElement
                                        .GetGeometryObjectFromReference(pickedRef)
                                        as Face;

                return(myGeometryObject);
            }
            return(null);
        }
Exemple #2
0
        public bool AllowReference(Reference reference, XYZ position)
        {
            RevitLinkInstance linkedInst     = uidoc.Document.GetElement(reference) as RevitLinkInstance;
            Document          linkedDoc      = linkedInst.GetLinkDocument();
            Element           currentElement = linkedDoc.GetElement(reference.CreateReferenceInLink());

            if (currentElement != null)
            {
                if (currentElement is Wall)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        private void CreateBeams()
        {
            Element selectedElement = null;

            try
            {
                while (true)
                {
                    RevitLinkInstance linkedInst = null;
                    //We initially create and set a variable currentDoc to be the document that will be using to getParameters later
                    //If the we are working with a linked document, this document will be changing for the corresponding document
                    Document currentDoc = doc;

                    View currentView          = ONBOXApplication.onboxApp.uiApp.ActiveUIDocument.ActiveView;
                    View currentGraphicalView = ONBOXApplication.onboxApp.uiApp.ActiveUIDocument.ActiveGraphicalView;

                    if (currentView.Id != currentGraphicalView.Id)
                    {
                        TaskDialog.Show(Properties.Messages.Common_Error, Properties.Messages.BeamsFromWalls_NotGraphicalView);
                        return;
                    }

                    #region MinMaxDimentions
                    double BeamMinHeight = Utils.ConvertM.cmToFeet(20);
                    double BeamMaxHeight = Utils.ConvertM.cmToFeet(150);
                    double BeamMinWidth  = Utils.ConvertM.cmToFeet(10);
                    double BeamMaxWidth  = Utils.ConvertM.cmToFeet(50);
                    #endregion

                    if (currentUI.UseLinks)
                    {
                        Reference linkedRef = sel.PickObject(ObjectType.LinkedElement, new LinkedWallsSelectionFilter(uidoc), Properties.Messages.BeamsFromWalls_SelectWallFromLink);
                        linkedInst = doc.GetElement(linkedRef) as RevitLinkInstance;
                        //change the current document to be the linked one
                        currentDoc      = linkedInst.GetLinkDocument();
                        selectedElement = currentDoc.GetElement(linkedRef.CreateReferenceInLink().ElementId);
                    }
                    else
                    {
                        selectedElement = doc.GetElement(sel.PickObject(ObjectType.Element, new WallsSelectionFilter(), Properties.Messages.BeamsFromWalls_SelectArchitecturalWall));
                    }


                    Wall selectedWall = selectedElement as Wall;
                    if (selectedWall == null)
                    {
                        continue;
                    }

                    using (Transaction beamTransation = new Transaction(doc, Properties.Messages.BeamsFromWalls_Transaction))
                    {
                        beamTransation.Start();

                        #region WallParameters

                        //Levels
                        Level wallBottomLevel = currentDoc.GetElement(selectedWall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId()) as Level;
                        Level wallTopLevel    = currentDoc.GetElement(selectedWall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId()) as Level;

                        //try to find the corresponding levels in this doc if exists
                        if (currentUI.UseLinks)
                        {
                            double linkedDocumentHeight = linkedInst.GetTotalTransform().Origin.Z;

                            wallBottomLevel = Utils.GetInformation.GetCorrespondingLevelInthisDoc(doc, wallBottomLevel, linkedDocumentHeight);
                            wallTopLevel    = Utils.GetInformation.GetCorrespondingLevelInthisDoc(doc, wallTopLevel, linkedDocumentHeight);
                        }

                        //Offsets
                        double wallTopOffset    = selectedWall.get_Parameter(BuiltInParameter.WALL_TOP_OFFSET).AsDouble();
                        double wallBottomOffset = selectedWall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble();

                        //Unconnected Height
                        double wallUncHeight = selectedWall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble();

                        //Height and Width
                        double beamHeight = Utils.ConvertM.cmToFeet(60);
                        double beamWidth  = Utils.ConvertM.cmToFeet(14);

                        DefineBeamParameters(selectedWall, currentDoc, wallBottomLevel, wallUncHeight, ref beamWidth, ref beamHeight);

                        //Curve
                        Curve wallCurve = (selectedWall.Location as LocationCurve).Curve;
                        if (currentUI.UseLinks)
                        {
                            wallCurve = wallCurve.CreateTransformed(linkedInst.GetTotalTransform());
                        }

                        #endregion

                        Family currentFamily = doc.GetElement(new ElementId(currentUI.SelectedBeamFamilyID)) as Family;

                        if (currentFamily == null)
                        {
                            TaskDialog.Show(Properties.Messages.Common_Error, Properties.Messages.BeamsFromWalls_DeletedBeamFamily);
                            return;
                        }

                        FamilySymbol currentFamilySymbol = null;

                        currentFamilySymbol = doc.GetElement(currentFamily.GetFamilySymbolIds().First()) as FamilySymbol;

                        //Verify if the dimentions is bettween min an max
                        if (beamHeight < BeamMinHeight)
                        {
                            beamHeight = BeamMinHeight;
                        }
                        if (beamHeight > BeamMaxHeight)
                        {
                            beamHeight = BeamMaxHeight;
                        }

                        if (beamWidth < BeamMinWidth)
                        {
                            beamWidth = BeamMinWidth;
                        }
                        if (beamWidth > BeamMaxWidth)
                        {
                            beamWidth = BeamMaxWidth;
                        }

                        //Round the dimensions in cm
                        const double roundNumber = 5;

                        double beamHeightInCM = Math.Ceiling((Utils.ConvertM.feetToCm(beamHeight) / roundNumber)) * roundNumber;
                        double beamWidthInCM  = Math.Ceiling((Utils.ConvertM.feetToCm(beamWidth) / roundNumber)) * roundNumber;

                        beamHeight = Utils.ConvertM.cmToFeet((beamHeightInCM));
                        beamWidth  = Utils.ConvertM.cmToFeet((beamWidthInCM));

                        //Build the Name of the Future FamilySymbol and checks if we have another with the same name, if we have another one use that instead
                        string newTypeName = beamWidthInCM.ToString() + " x " + beamHeightInCM.ToString() + "cm";

                        if (!Utils.FindElements.thisTypeExist(newTypeName, currentFamily.Name, BuiltInCategory.OST_StructuralFraming, doc))
                        {
                            currentFamilySymbol = currentFamilySymbol.Duplicate(newTypeName) as FamilySymbol;

                            Parameter parameterB = currentFamilySymbol.LookupParameter("b");
                            Parameter parameterH = currentFamilySymbol.LookupParameter("h");

                            parameterB.Set(beamWidth);
                            parameterH.Set(beamHeight);
                        }
                        else
                        {
                            currentFamilySymbol = Utils.FindElements.findElement(newTypeName, currentFamily.Name, BuiltInCategory.OST_StructuralFraming, doc) as FamilySymbol;
                        }

                        //Create the Beams
                        FamilyInstance UpperBeamInstance = null;
                        FamilyInstance LowerBeamInstance = null;
                        currentFamilySymbol.Activate();

                        if (currentUI.UpperBeam)
                        {
                            bool isInvertedUpperBeam = false;

                            if (currentUI.InvertedUpperBeam)
                            {
                                isInvertedUpperBeam = true;
                            }

                            UpperBeamInstance = doc.Create.NewFamilyInstance(wallCurve, currentFamilySymbol, wallBottomLevel, Autodesk.Revit.DB.Structure.StructuralType.Beam);

                            //Regenerate the document so we can adjust the parameters
                            doc.Regenerate();
                            AdjustBeamParameters(UpperBeamInstance, wallTopLevel, wallBottomLevel, wallUncHeight, isInvertedUpperBeam);
                        }
                        if (currentUI.LowerBeam)
                        {
                            LowerBeamInstance = doc.Create.NewFamilyInstance(wallCurve, currentFamilySymbol, wallBottomLevel, Autodesk.Revit.DB.Structure.StructuralType.Beam);
                            doc.Regenerate();
                            AdjustBeamParameters(LowerBeamInstance, wallTopLevel, wallBottomLevel, wallUncHeight, false, true);
                        }

                        if (UpperBeamInstance != null)
                        {
                            CheckBeamsDistancesWithouSupports(UpperBeamInstance, currentFamily, currentFamilySymbol, roundNumber, beamWidth);
                            doc.Regenerate();
                            Utils.CheckFamilyInstanceForIntersection.checkForDuplicates(UpperBeamInstance, doc);
                            doc.Regenerate();
                            if (currentUI.JoinWall)
                            {
                                //we dont need to check if its linked because the UI blocks join walls when is linked
                                Utils.CheckFamilyInstanceForIntersection.JoinBeamToWalls(UpperBeamInstance, doc);
                            }
                        }
                        if (LowerBeamInstance != null)
                        {
                            Utils.CheckFamilyInstanceForIntersection.checkForDuplicates(LowerBeamInstance, doc);
                            if (currentUI.JoinWall)
                            {
                                //we dont need to check if its linked because the UI blocks join walls when is linked
                                Utils.CheckFamilyInstanceForIntersection.JoinBeamToWalls(LowerBeamInstance, doc);
                            }
                        }


                        //continue to code
                        //////////////////

                        beamTransation.Commit();
                    }
                }
            }
            catch (Exception excep)
            {
                ExceptionManager eManager = new ExceptionManager(excep);
            }
            finally
            {
                currentUI.UnFreezeCreateButton();
            }
        }