Ejemplo n.º 1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;
            Selection  sel   = uidoc.Selection;

            try
            {
                Element tTypeElement = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(fsy => fsy is TrussType).ToList().FirstOrDefault();
                if (tTypeElement == null)
                {
                    message = "Nenhum tipo de treliça foi encontrada no projeto, por favor, carregue um tipo e rode este comando novamente";
                    return(Result.Failed);
                }
                TrussType tType = tTypeElement as TrussType;

                ISelectionFilter ridgeSelectionFilter = new RoofClasses.SelectionFilters.StraightLinesAndFacesRidgeSelectionFilter(doc);
                Reference        currentReference     = sel.PickObject(ObjectType.Edge, ridgeSelectionFilter);

                FootPrintRoof        currentFootPrintRoof = doc.GetElement(currentReference) as FootPrintRoof;
                RoofClasses.EdgeInfo currentRidgeInfo     = Support.GetMostSimilarEdgeInfo(currentReference, doc);

                if (currentRidgeInfo == null)
                {
                    message = "Nenhuma linha inferior pode ser obtida a partir da seleção";
                    return(Result.Failed);
                }

                //                #region DEBUG ONLY
                //#if DEBUG
                //                using (Transaction ta = new Transaction(doc, "Line test"))
                //                {
                //                    ta.Start();

                //                    Frame fr = new Frame(currentRidgeInfo.Curve.Evaluate(0.5, true), XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);
                //                    SketchPlane skp = SketchPlane.Create(doc, Plane.Create(fr));
                //                    doc.Create.NewModelCurve(currentRidgeInfo.Curve, skp);


                //                    ta.Commit();
                //                }
                //#endif
                //                #endregion

                Line currentRidgeLine = currentRidgeInfo.Curve as Line;

                if (currentRidgeLine == null)
                {
                    message = "Ridge must be a straight line";
                    return(Result.Failed);
                }

                ISelectionFilter currentTrussBaseSupportFilter = new RoofClasses.SelectionFilters.SupportsSelectionFilter(currentRidgeLine.Direction.CrossProduct(XYZ.BasisZ));
                XYZ baseSupportPoint = null;
                try
                {
                    Reference currentTrussBaseRef  = sel.PickObject(ObjectType.Element, currentTrussBaseSupportFilter, "Selecione uma base para a treliça ou (ESC) para ignorar");
                    Element   currentTrussBaseElem = doc.GetElement(currentTrussBaseRef.ElementId);

                    //We can safely convert because the selection filter does not select anything that is not a curve locatated
                    Curve currentElementCurve = (currentTrussBaseElem.Location as LocationCurve).Curve;

                    if (currentRidgeLine != null)
                    {
                        if (currentElementCurve is Line)
                        {
                            Line   currentSupportLine = currentElementCurve as Line;
                            double height             = currentRidgeInfo.GetCurrentRoofHeight();
                            currentRidgeLine   = currentRidgeLine.Flatten(height);
                            currentSupportLine = currentSupportLine.Flatten(height);

                            IntersectionResultArray iResutArr  = new IntersectionResultArray();
                            SetComparisonResult     compResult = currentRidgeLine.Intersect(currentSupportLine, out iResutArr);

                            if (iResutArr.Size == 1)
                            {
                                IntersectionResult iResult = iResutArr.get_Item(0);
                                if (iResult != null)
                                {
                                    baseSupportPoint = currentRidgeInfo.Curve.Project(iResult.XYZPoint).XYZPoint;
                                }
                            }
                        }
                    }
                }
                catch
                {
                }

                if (baseSupportPoint == null)
                {
                    baseSupportPoint = currentRidgeLine.Project(currentReference.GlobalPoint).XYZPoint;
                }


                Managers.TrussRidgeManager currentTrussManager = new Managers.TrussRidgeManager();

                Line currentSupport0ElemLine = null;
                Line currentSupport1ElemLine = null;

                currentTrussBaseSupportFilter = new RoofClasses.SelectionFilters.SupportsSelectionFilter(currentRidgeLine.Direction);

                if (currentRidgeInfo.RoofLineType == RoofClasses.RoofLineType.Ridge)
                {
                    try
                    {
                        Reference currentSupport0Ref       = sel.PickObject(ObjectType.Element, currentTrussBaseSupportFilter, "O primeiro suporte para a treliça");
                        Element   currentSupport0Elem      = doc.GetElement(currentSupport0Ref.ElementId);
                        Curve     currentSupport0ElemCurve = (currentSupport0Elem.Location as LocationCurve).Curve;
                        currentSupport0ElemLine = currentSupport0ElemCurve as Line;

                        Reference currentSupport1Ref       = sel.PickObject(ObjectType.Element, currentTrussBaseSupportFilter, "O segundo suporte para a treliça");
                        Element   currentSupport1Elem      = doc.GetElement(currentSupport1Ref.ElementId);
                        Curve     currentSupport1ElemCurve = (currentSupport1Elem.Location as LocationCurve).Curve;
                        currentSupport1ElemLine = currentSupport1ElemCurve as Line;
                    }
                    catch
                    {
                        currentSupport0ElemLine = null;
                        currentSupport1ElemLine = null;
                    }
                }
                else if (currentRidgeInfo.RoofLineType == RoofClasses.RoofLineType.RidgeSinglePanel)
                {
                    try
                    {
                        Reference currentSupport0Ref       = sel.PickObject(ObjectType.Element, currentTrussBaseSupportFilter, "O suporte para a treliça");
                        Element   currentSupport0Elem      = doc.GetElement(currentSupport0Ref.ElementId);
                        Curve     currentSupport0ElemCurve = (currentSupport0Elem.Location as LocationCurve).Curve;
                        currentSupport0ElemLine = currentSupport0ElemCurve as Line;
                    }
                    catch
                    {
                        currentSupport0ElemLine = null;
                    }
                }

                RoofClasses.TrussInfo currentTrussInfo = currentTrussManager.CreateTrussFromRidgeWithSupports(baseSupportPoint, currentRidgeInfo, tType, currentSupport0ElemLine, currentSupport1ElemLine);

                //#region DEBUG ONLY

                //if (currentReference != null)
                //    DEBUG.CreateDebugPoint(doc, baseSupportPoint);

                //#endregion
            }
            catch (Exception e)
            {
                if (!(e is Autodesk.Revit.Exceptions.OperationCanceledException))
                {
                    throw e;
                }
            }

            return(Result.Succeeded);
        }
Ejemplo n.º 2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;
            Selection  sel   = uidoc.Selection;

            ISelectionFilter hipSelFilter  = new RoofClasses.SelectionFilters.StraightLinesAndFacesHipSelectionFilter(doc);
            Reference        currentHipRef = sel.PickObject(ObjectType.Edge, hipSelFilter, "Selecione um rincão para posicionar as treliças");

            RoofClasses.EdgeInfo currentEdgeInfo = Support.GetMostSimilarEdgeInfo(currentHipRef, doc);

            //if (currentHipRef.GlobalPoint != null)
            //    DEBUG.CreateDebugPoint(doc, currentHipRef.GlobalPoint);

            //DEBUG.CreateDebugPoint(doc, currentEdgeInfo.Curve.Evaluate(0.5, true));

            if (currentEdgeInfo == null)
            {
                message = "Nenhuma linha inferior pode ser obtida a partir da seleção";
                return(Result.Failed);
            }

            if (currentEdgeInfo.Curve as Line == null)
            {
                message = "Rincão deve ser uma linha reta";
                return(Result.Failed);
            }

            Line             currentHipLine      = currentEdgeInfo.Curve as Line;
            ISelectionFilter firstSupportFilter  = new RoofClasses.SelectionFilters.SupportsSelectionFilter(currentHipLine.Flatten().Direction.Rotate(45));
            ISelectionFilter secondSupportFilter = new RoofClasses.SelectionFilters.SupportsSelectionFilter(currentHipLine.Flatten().Direction.Rotate(-45));
            Element          firstSupport        = null;
            Element          secondSupport       = null;

            try
            {
                Reference firstSupportRef  = sel.PickObject(ObjectType.Element, firstSupportFilter);
                Reference SecondSupportRef = sel.PickObject(ObjectType.Element, secondSupportFilter);

                firstSupport  = doc.GetElement(firstSupportRef);
                secondSupport = doc.GetElement(SecondSupportRef);
            }
            catch
            {
            }

            if (firstSupport == null || secondSupport == null)
            {
                message = "Nenhum suporte foi selecionado";
                return(Result.Failed);
            }

            Element tTypeElement = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Where(fsy => fsy is TrussType).ToList().FirstOrDefault();

            if (tTypeElement == null)
            {
                message = "Nenhum tipo de treliça foi encontrada no projeto, por favor, carregue um tipo e rode este comando novamente";
                return(Result.Failed);
            }
            TrussType tType = tTypeElement as TrussType;

            Managers.TrussHipManager trussHipManager = new Managers.TrussHipManager();
            trussHipManager.CreateTrussInfo(doc, currentHipLine.Evaluate(0.5, true), currentEdgeInfo, firstSupport, secondSupport, tType);

            return(Result.Succeeded);
        }