示例#1
0
        /***************************************************/

        private static List <ISurface> GetOpeningGeometry(Transaction t, Document doc, List <HostObject> hosts, List <ElementId> inserts, FamilyInstance familyInstance, RevitSettings settings = null)
        {
            List <List <Solid> > solidsWithOpening = new List <List <Solid> >();

            foreach (HostObject h in hosts)
            {
                solidsWithOpening.Add(h.Solids(new Options()).Select(x => SolidUtils.Clone(x)).ToList());
            }

            // Rollback and restart of the transaction is needed because otherwise the object, to which familyInstance is pointing can become invalidated.
            FailureHandlingOptions failureHandlingOptions = t.GetFailureHandlingOptions().SetClearAfterRollback(true);

            t.RollBack(failureHandlingOptions);
            t.Start();

            List <ISurface>  surfaces = new List <ISurface> ();
            List <CurveLoop> loops    = new List <CurveLoop>();

            try
            {
                doc.Delete(inserts);
                doc.Regenerate();

                for (int i = 0; i < hosts.Count; i++)
                {
                    HostObject h = hosts[i];

                    List <Autodesk.Revit.DB.Plane> planes = h.IPanelPlanes();
                    if (planes.Count == 0)
                    {
                        continue;
                    }

                    List <Solid> fullSolids = h.Solids(new Options()).SelectMany(x => SolidUtils.SplitVolumes(x)).ToList();
                    if (h is Wall)
                    {
                        fullSolids = fullSolids.Select(x => BooleanOperationsUtils.CutWithHalfSpace(x, planes[0])).ToList();
                        planes[0]  = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-planes[0].Normal, planes[0].Origin);
                    }

                    foreach (Solid s in fullSolids)
                    {
                        foreach (Solid s2 in solidsWithOpening[i])
                        {
                            BooleanOperationsUtils.ExecuteBooleanOperationModifyingOriginalSolid(s, s2, BooleanOperationsType.Difference);
                        }

                        foreach (Autodesk.Revit.DB.Face f in s.Faces)
                        {
                            PlanarFace pf = f as PlanarFace;
                            if (pf == null)
                            {
                                continue;
                            }

                            if (planes.Any(x => Math.Abs(1 - pf.FaceNormal.DotProduct(x.Normal)) <= settings.DistanceTolerance && Math.Abs((pf.Origin - x.Origin).DotProduct(x.Normal)) <= settings.AngleTolerance))
                            {
                                loops.AddRange(pf.GetEdgesAsCurveLoops());
                            }
                        }
                    }
                }
            }
            catch
            {
                loops = null;
            }

            t.RollBack(failureHandlingOptions);

            if (loops != null)
            {
                surfaces.AddRange(loops.Select(x => new PlanarSurface(x.FromRevit(), null)));
            }
            else if (surfaces.Count != 0)
            {
                BH.Engine.Reflection.Compute.RecordWarning(String.Format("Geometrical processing of a Revit element failed due to an internal Revit error. Converted opening might be missing one or more of its surfaces. Revit ElementId: {0}", familyInstance.Id));
            }

            return(surfaces);
        }
        // In Revit API discussion forum thread
        // https://forums.autodesk.com/t5/revit-api-forum/outer-loops-of-planar-face-with-separate-parts/m-p/7461348

        public Result GetPlanarFaceOuterLoops(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication IntApp   = commandData.Application;
            UIDocument    IntUIDoc = IntApp.ActiveUIDocument;

            if (IntUIDoc == null)
            {
                return(Result.Failed);
            }
            Document IntDoc = IntUIDoc.Document;

            Reference R = null;

            try
            {
                R = IntUIDoc.Selection.PickObject(ObjectType.Face);
            }
            catch
            {
            }
            if (R == null)
            {
                return(Result.Cancelled);
            }

            Element F_El = IntDoc.GetElement(R.ElementId);

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

            PlanarFace F = F_El.GetGeometryObjectFromReference(R)
                           as PlanarFace;

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

            //Create individual CurveLoops to compare from
            // the orginal CurveLoopArray
            //If floor has separate parts these will now be
            // separated out into individual faces rather
            // than one face with multiple loops.
            List <Tuple <PlanarFace, CurveLoop, int> > CLoop
                = new List <Tuple <PlanarFace, CurveLoop, int> >();

            int Ix = 0;

            foreach (CurveLoop item in F.GetEdgesAsCurveLoops())
            {
                List <CurveLoop> CLL = new List <CurveLoop>();
                CLL.Add(item);
                //Create a solid extrusion for each CurveLoop
                // ( we want to get the planarFace from this
                // to use built in functionality (.PlanarFace.IsInside).
                //Would be nice if you could skip this step and
                // create PlanarFaces directly from CuveLoops?
                // Does not appear to be possible, I only looked
                // in GeometryCreationUtilities.
                //Below creates geometry in memory rather than
                // actual geometry in the document, therefore
                // no transaction required.
                Solid S = GeometryCreationUtilities
                          .CreateExtrusionGeometry(CLL, F.FaceNormal, 1);

                foreach (Face Fx in S.Faces)
                {
                    PlanarFace PFx = Fx as PlanarFace;
                    if (PFx == null)
                    {
                        continue;
                    }
                    if (PFx.FaceNormal.IsAlmostEqualTo(
                            F.FaceNormal))
                    {
                        Ix += 1;
                        CLoop.Add(new Tuple <PlanarFace,
                                             CurveLoop, int>(PFx, item, Ix));
                    }
                }
            }

            List <CurveLoop> OuterLoops = new List <CurveLoop>();
            //If there is more than one outerloop we know the
            // original face has separate parts.
            //We could therefore stop the creation of floors
            // with separate parts via posting failures etc.
            // or more passively create a geometry checking
            // utility to identify them.
            List <CurveLoop> InnerLoops = new List <CurveLoop>();

            foreach (Tuple <PlanarFace, CurveLoop, int> item in CLoop)
            {
                //To identify an inner loop we just need to see
                // if any of it's points are inside another face.
                //The exception to this is a loop compared to the
                // face it was taken from. This will also be
                // considered inside as the points are on the boundary.
                //Therefore give each item an integer ID to ensure
                // it isn't self comparing. An alternative would
                // be to look for J=1 instead of J=0 below (perhaps).

                int J = CLoop.ToList().FindAll(z
                                               => FirstPointIsInsideFace(item.Item2, z.Item1)
                                               == true && z.Item3 != item.Item3).Count;

                if (J == 0)
                {
                    OuterLoops.Add(item.Item2);
                }
                else
                {
                    InnerLoops.Add(item.Item2);
                }
            }

            using (Transaction Tx = new Transaction(IntDoc,
                                                    "Outer loops"))
            {
                if (Tx.Start() == TransactionStatus.Started)
                {
                    SketchPlane SKP = SketchPlane.Create(IntDoc,
                                                         Plane.CreateByThreePoints(F.Origin,
                                                                                   F.Origin + F.XVector, F.Origin + F.YVector));

                    foreach (CurveLoop Crv in OuterLoops)
                    {
                        foreach (Curve C in Crv)
                        {
                            IntDoc.Create.NewModelCurve(C, SKP);
                        }
                    }
                    Tx.Commit();
                }
            }
            return(Result.Succeeded);
        }
示例#3
0
        /***************************************************/
        /****              Private Methods              ****/
        /***************************************************/

        private static Dictionary <PlanarSurface, List <PlanarSurface> > PanelSurfaces_HostDocument(this HostObject hostObject, IEnumerable <ElementId> insertsToIgnore = null, RevitSettings settings = null)
        {
            List <Autodesk.Revit.DB.Plane> planes = hostObject.IPanelPlanes();

            if (planes.Count == 0)
            {
                return(null);
            }

            Document doc = hostObject.Document;
            Dictionary <PlanarSurface, List <PlanarSurface> > result = new Dictionary <PlanarSurface, List <PlanarSurface> >();

            IList <ElementId> inserts = hostObject.FindInserts(true, true, true, true);

            if (insertsToIgnore != null)
            {
                inserts = inserts.Where(x => insertsToIgnore.All(y => x.IntegerValue != y.IntegerValue)).ToList();
            }

            Transaction            t = new Transaction(doc);
            FailureHandlingOptions failureHandlingOptions = t.GetFailureHandlingOptions().SetClearAfterRollback(true);

            t.Start("Temp Delete Inserts And Unjoin Geometry");

            try
            {
                foreach (ElementId id in JoinGeometryUtils.GetJoinedElements(doc, hostObject))
                {
                    JoinGeometryUtils.UnjoinGeometry(doc, hostObject, doc.GetElement(id));
                }

                if (hostObject is Wall)
                {
                    WallUtils.DisallowWallJoinAtEnd((Wall)hostObject, 0);
                    WallUtils.DisallowWallJoinAtEnd((Wall)hostObject, 1);
                }

                if (insertsToIgnore != null)
                {
                    doc.Delete(insertsToIgnore.ToList());
                }

                doc.Regenerate();

                List <Solid> solidsWithOpenings = hostObject.Solids(new Options());
                List <Solid> fullSolids;

                if (inserts.Count != 0)
                {
                    solidsWithOpenings = solidsWithOpenings.Select(x => SolidUtils.Clone(x)).ToList();

                    doc.Delete(inserts);
                    doc.Regenerate();

                    fullSolids = hostObject.Solids(new Options());
                }
                else
                {
                    fullSolids = solidsWithOpenings;
                }

                fullSolids = fullSolids.SelectMany(x => SolidUtils.SplitVolumes(x)).ToList();
                if (hostObject is Wall)
                {
                    fullSolids.ForEach(x => BooleanOperationsUtils.CutWithHalfSpaceModifyingOriginalSolid(x, planes[0]));
                    Autodesk.Revit.DB.Plane flippedPlane = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-planes[0].Normal, planes[0].Origin + planes[0].Normal * 1e-3);
                    fullSolids.ForEach(x => BooleanOperationsUtils.CutWithHalfSpaceModifyingOriginalSolid(x, flippedPlane));
                    fullSolids = fullSolids.SelectMany(x => SolidUtils.SplitVolumes(x)).ToList();
                    planes[0]  = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(-planes[0].Normal, planes[0].Origin);
                }


                foreach (Autodesk.Revit.DB.Plane plane in planes)
                {
                    foreach (Solid s in fullSolids)
                    {
                        List <CurveLoop> loops = new List <CurveLoop>();
                        foreach (Autodesk.Revit.DB.Face f in s.Faces)
                        {
                            PlanarFace pf = f as PlanarFace;
                            if (pf == null)
                            {
                                continue;
                            }

                            if (Math.Abs(1 - pf.FaceNormal.DotProduct(plane.Normal)) <= settings.DistanceTolerance && Math.Abs((pf.Origin - plane.Origin).DotProduct(plane.Normal)) <= settings.AngleTolerance)
                            {
                                loops.AddRange(pf.GetEdgesAsCurveLoops());
                            }
                        }

                        CurveLoop            outline  = loops.FirstOrDefault(x => x.IsCounterclockwise(plane.Normal));
                        PlanarSurface        surface  = new PlanarSurface(outline.FromRevit(), null);
                        List <PlanarSurface> openings = new List <PlanarSurface>();
                        foreach (CurveLoop loop in loops.Where(x => x != outline))
                        {
                            openings.Add(new PlanarSurface(loop.FromRevit(), null));
                        }

                        if (inserts.Count != 0)
                        {
                            List <Solid> openingVolumes = new List <Solid>();
                            foreach (Solid s2 in solidsWithOpenings)
                            {
                                openingVolumes.Add(BooleanOperationsUtils.ExecuteBooleanOperation(s, s2, BooleanOperationsType.Difference));
                            }

                            foreach (Solid s2 in openingVolumes)
                            {
                                foreach (Autodesk.Revit.DB.Face f in s2.Faces)
                                {
                                    PlanarFace pf = f as PlanarFace;
                                    if (pf == null)
                                    {
                                        continue;
                                    }

                                    if (Math.Abs(1 - pf.FaceNormal.DotProduct(plane.Normal)) <= settings.DistanceTolerance && Math.Abs((pf.Origin - plane.Origin).DotProduct(plane.Normal)) <= settings.AngleTolerance)
                                    {
                                        foreach (CurveLoop cl in pf.GetEdgesAsCurveLoops())
                                        {
                                            openings.Add(new PlanarSurface(cl.FromRevit(), null));
                                        }
                                    }
                                }
                            }
                        }

                        result.Add(surface, openings);
                    }
                }
            }
            catch
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Geometrical processing of a Revit element failed due to an internal Revit error. Converted panel might be missing one or more of its surfaces. Revit ElementId: {0}", hostObject.Id));
            }

            t.RollBack(failureHandlingOptions);

            return(result);
        }
示例#4
0
        static private CurveLoop GetOuterCurveLoop(PlanarFace targetFace)
        {
            CurveLoop currentCurveLoop = new CurveLoop();

            if (targetFace != null)
            {
                IList <XYZ> Points = new List <XYZ>();
                IList <IList <CurveLoop> > currentListOfListOfCurveLoops = ExporterIFCUtils.SortCurveLoops(targetFace.GetEdgesAsCurveLoops());

                if (currentListOfListOfCurveLoops != null)
                {
                    if (currentListOfListOfCurveLoops.Count > 0)
                    {
                        IList <CurveLoop> currentOuterLoop = currentListOfListOfCurveLoops[0];
                        if (currentOuterLoop != null)
                        {
                            if (currentOuterLoop.Count > 0)
                            {
                                currentCurveLoop = currentOuterLoop[0];
                            }
                        }
                    }
                }
            }
            return(currentCurveLoop);
        }
示例#5
0
        private Result SlopeSelectedBuildingPad(UIDocument targetUIdoc, ref string message, double maxPointDistInFeet, double targetAngleInRadians)
        {
            Document  doc = targetUIdoc.Document;
            Selection sel = targetUIdoc.Selection;

            View3D current3dView = doc.ActiveView as View3D;

            if (current3dView == null)
            {
                message = Properties.Messages.SlopeGradingFromPads_Not3DView;
                return(Result.Failed);
            }

            BuildingPad selectedBuildingPad = doc.GetElement(sel.PickObject(ObjectType.Element, new PadSelectionFilter(), Properties.Messages.SlopeGradingFromPads_SelectPad)) as BuildingPad;

            //Check if the Pad is associate with a Surface (never seen one doesnt, but anyways)
            ElementId topoElementID = selectedBuildingPad.HostId;

            if (topoElementID.Equals(ElementId.InvalidElementId))
            {
                message = Properties.Messages.SlopeGradingFromPads_NoTopoAssociate;
                return(Result.Failed);
            }

            TopographySurface currentTopo = doc.GetElement(topoElementID) as TopographySurface;

            if (currentTopo == null)
            {
                message = Properties.Messages.SlopeGradingFromPads_NoTopoAssociate;;
                return(Result.Failed);
            }

            IList <CurveLoop> PadBoundaryLoops = new List <CurveLoop>();
            CurveLoop         outerLoop        = null;

            IList <Reference> TopFacesReferences = HostObjectUtils.GetTopFaces(selectedBuildingPad);

            if (TopFacesReferences.Count > 1)
            {
                message = Properties.Messages.SlopeGradingFromPads_PadsWithMoreThanOneUpperFace;
                return(Result.Failed);
            }

            XYZ plannarDirection = XYZ.BasisZ;
            XYZ plannarOrigin    = XYZ.Zero;

            // interate on the only face
            foreach (Reference currentFaceRef in TopFacesReferences)
            {
                GeometryObject currentFaceObj = selectedBuildingPad.GetGeometryObjectFromReference(currentFaceRef);
                if (currentFaceObj is PlanarFace)
                {
                    PlanarFace currentPlanarFace = currentFaceObj as PlanarFace;
                    plannarDirection = currentPlanarFace.FaceNormal;
                    plannarOrigin    = currentPlanarFace.Origin;
                    PadBoundaryLoops = currentPlanarFace.GetEdgesAsCurveLoops();
                }
                else
                {
                    message = Properties.Messages.SlopeGradingFromPads_UpperFaceNotPlanar;
                    return(Result.Failed);
                }
            }

            //Sort the curves so the outer loop comes first
            IList <IList <CurveLoop> > curveLoopLoop = ExporterIFCUtils.SortCurveLoops(PadBoundaryLoops);

            if (curveLoopLoop.Count > 0)
            {
                IList <CurveLoop> firstList = curveLoopLoop.First();
                if (firstList.Count > 0)
                {
                    outerLoop = firstList.First();
                }
            }

            if (outerLoop == null)
            {
                message = Properties.Messages.SlopeGradingFromPads_OuterLoopIssue;
                return(Result.Failed);
            }

            //This will be the list of elements that the ReferenceIntersector will shoot the rays
            //If we try to shoot the rays only in the toposurface and the it has subregions, the reference
            //intersection will not recognize these regions, so its necessary to shoot rays to the surface and its subregions
            IList <ElementId> currentSubRegionsAndSurface = currentTopo.GetHostedSubRegionIds();

            currentSubRegionsAndSurface.Add(topoElementID);

            //Search for the max distance from the Pad to the topography
            //Doesnt matter if it is upwards or downwards, but we will check that, since the ray has to go to one direction
            //This is to estabilish what the distance will be using to create the slope to the right amount
            ReferenceIntersector topoRefIntersec = new ReferenceIntersector(currentSubRegionsAndSurface, FindReferenceTarget.Mesh, current3dView);

            double maxDist = double.NegativeInfinity;

            foreach (Curve currentCurve in outerLoop)
            {
                int    numberOfInteractions = 0;
                double increaseAmount       = 0;
                double currentParameter     = 0;
                EstabilishInteractionPoints(currentCurve, maxPointDistInFeet, out numberOfInteractions, out increaseAmount);

                for (int i = 0; i < numberOfInteractions; i++)
                {
                    if (i == 0)
                    {
                        currentParameter = 0;
                    }
                    else
                    {
                        currentParameter += increaseAmount;
                    }

                    XYZ currentPointToEvaluate = currentCurve.Evaluate(currentParameter, true);

                    ReferenceWithContext currentRefContext = topoRefIntersec.FindNearest(currentPointToEvaluate, XYZ.BasisZ);
                    if (currentRefContext == null)
                    {
                        currentRefContext = topoRefIntersec.FindNearest(currentPointToEvaluate, XYZ.BasisZ.Negate());
                    }

                    if (currentRefContext == null)
                    {
                        continue;
                    }

                    double currentDist = currentRefContext.Proximity;
                    if (currentDist > maxDist)
                    {
                        maxDist = currentDist;
                    }
                }
            }

            // if we haven't changed the maxdist yet, something went wrong
            if (maxDist == double.NegativeInfinity)
            {
                message = Properties.Messages.SlopeGradingFromPads_NoTopoAssociate;
                return(Result.Failed);
            }

            //Estabilish the offset from the pad
            double offsetDist = maxDist / Math.Tan(targetAngleInRadians);

            using (TopographyEditScope topoEditGroup = new TopographyEditScope(doc, Properties.Messages.SlopeGradingFromPads_Transaction))
            {
                topoEditGroup.Start(topoElementID);
                using (Transaction t = new Transaction(doc, Properties.Messages.SlopeGradingFromPads_Transaction))
                {
                    t.Start();

                    CurveLoop offsetLoop = null;

                    try
                    {
                        offsetLoop = CurveLoop.CreateViaOffset(outerLoop, offsetDist, plannarDirection);
                    }
                    catch
                    {
                        message += Properties.Messages.SlopeGradingFromPads_OuterOffsetLoopIssue;
                        return(Result.Failed);
                    }

                    #region DebugCurve Loop

                    //Plane p = new Plane(plannarDirection, plannarOrigin);
                    //SketchPlane sktP = SketchPlane.Create(doc, p);
                    //foreach (Curve currentOffsetCurve in offsetLoop)
                    //{
                    //    doc.Create.NewModelCurve(currentOffsetCurve, sktP);
                    //}

                    #endregion


                    foreach (Curve currentOffsetCurve in offsetLoop)
                    {
                        int    numberOfInteractions = 0;
                        double increaseAmount       = 0;
                        double currentParameter     = 0;

                        EstabilishInteractionPoints(currentOffsetCurve, maxPointDistInFeet, out numberOfInteractions, out increaseAmount);

                        for (int i = 0; i < numberOfInteractions; i++)
                        {
                            if (i == 0)
                            {
                                currentParameter = 0;
                            }
                            else
                            {
                                currentParameter += increaseAmount;
                            }

                            XYZ currentPointOffset = currentOffsetCurve.Evaluate(currentParameter, true);

                            ReferenceWithContext currentRefContext = topoRefIntersec.FindNearest(currentPointOffset, XYZ.BasisZ);
                            if (currentRefContext == null)
                            {
                                currentRefContext = topoRefIntersec.FindNearest(currentPointOffset, XYZ.BasisZ.Negate());
                            }
                            //if we couldn't find points upwards and downwards, the topo is near the border, so we cant add points
                            if (currentRefContext == null)
                            {
                                continue;
                            }

                            Reference currentReference  = currentRefContext.GetReference();
                            XYZ       currentPointToAdd = currentReference.GlobalPoint;

                            if (currentTopo.ContainsPoint(currentPointToAdd))
                            {
                                continue;
                            }

                            IList <XYZ> ListPointToAdd = new List <XYZ>();
                            ListPointToAdd.Add(currentPointToAdd);

                            currentTopo.AddPoints(ListPointToAdd);
                        }
                    }

                    foreach (Curve currentCurve in outerLoop)
                    {
                        int    numberOfInteractions = 0;
                        double increaseAmount       = 0;
                        double currentParameter     = 0;
                        EstabilishInteractionPoints(currentCurve, maxPointDistInFeet, out numberOfInteractions, out increaseAmount);

                        for (int i = 0; i < numberOfInteractions; i++)
                        {
                            if (i == 0)
                            {
                                currentParameter = 0;
                            }
                            else
                            {
                                currentParameter += increaseAmount;
                            }

                            XYZ currentPointToAdd = currentCurve.Evaluate(currentParameter, true);

                            if (currentTopo.ContainsPoint(currentPointToAdd))
                            {
                                continue;
                            }

                            IList <XYZ> ListPointToAdd = new List <XYZ>();
                            ListPointToAdd.Add(currentPointToAdd);

                            currentTopo.AddPoints(ListPointToAdd);
                        }
                    }
                    t.Commit();
                }
                topoEditGroup.Commit(new TopographyFailurePreprocessor());

                return(Result.Succeeded);
            }
        }
示例#6
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;

            doc = uidoc.Document;
            Selection sel = uidoc.Selection;

            listpoint.Clear();
            Insulationlbr           insulationlbr     = Insulationlbr.Instance;
            InsulationSupport       insulationSupport = new InsulationSupport();
            FamilyInstance          WALLINSTANCE      = null;
            List <FamilySymbol>     listsym           = insulationlbr.GetFamilySymbols(doc);
            List <Rectangleslbr>    soluong           = new List <Rectangleslbr>();
            AssemblyInstance        instance          = null;
            FamilyInstance          insu   = null;
            Rectangleslbr           rec    = null;
            ICollection <ElementId> copyid = new List <ElementId>();
            //Reference rf = sel.PickObject(ObjectType.Element, new AssemblySelectionfilter(), "Assembly");
            //Element ele = doc.GetElement(rf);
            //AssemblyInstance instance = ele as Assembly+Instance;
            ProgressbarWPF progressbarWPF = new ProgressbarWPF(4, "Loading...");

            progressbarWPF.Show();
            for (int i = 1; i < 4; i++)
            {
                progressbarWPF.Giatri();
                if (progressbarWPF.iscontinue == false)
                {
                    break;
                }
                if (i == 1)
                {
                    if (doc.ActiveView.IsAssemblyView)
                    {
                        instance = doc.GetElement(doc.ActiveView.AssociatedAssemblyInstanceId) as AssemblyInstance;
                    }
                    insu         = insulationlbr.Getinsulation(doc, instance);
                    WALLINSTANCE = insulationlbr.GetWall(doc, instance);
                    //var topface = insulationSupport.FindTopWallother(insu);
                    rec = insulationlbr.DrawingFaceTop(doc, instance);
                }
                if (i == 2)
                {
                    var               right   = doc.ActiveView.RightDirection;
                    PlanarFace        topface = insulationSupport.FindTopWallother(insu);
                    IList <CurveLoop> loops   = topface.GetEdgesAsCurveLoops();
                    if (loops.Count != 1)
                    {
                        soluong = insulationSupport.DrawBlockOut2(doc, instance, insu, WALLINSTANCE, rec, 0.125, 8);
                        List <List <Rectangleslbr> > listrec = new List <List <Rectangleslbr> >();
                        listrec = Rectangleslbr.ListRecVert(soluong);
                        insulationSupport.SortRectangleslist(listrec);
                        if (Math.Floor(right.X) != 0)
                        {
                            copyid = Rectangleslbr.LayoutInsulationvert(doc, listrec);
                        }
                        else
                        {
                            copyid = Rectangleslbr.LayoutInsulationvert2(doc, listrec);
                        }
                    }
                    else
                    {
                        soluong = insulationSupport.DrawBlockOut1(doc, instance, insu, WALLINSTANCE, rec, 0.125, 8);
                        List <List <Rectangleslbr> > listrec = new List <List <Rectangleslbr> >();
                        listrec = Rectangleslbr.ListRecVert(soluong);
                        insulationSupport.SortRectangleslist(listrec);
                        if (Math.Floor(right.X) != 0)
                        {
                            copyid = Rectangleslbr.LayoutInsulationvert(doc, listrec);
                        }
                        else
                        {
                            copyid = Rectangleslbr.LayoutInsulationvert2(doc, listrec);
                        }
                    }
                }
                if (i == 3)
                {
                    View viewcopy = insulationlbr.CreateDraftingView(doc);
                    using (Transaction tran = new Transaction(doc, "Copy"))
                    {
                        tran.Start();
                        ElementTransformUtils.CopyElements(doc.ActiveView, copyid, viewcopy, null, new CopyPasteOptions());
                        doc.Delete(copyid);
                        tran.Commit();
                    }
                    TaskDialog.Show("Insulation lay out", "Finish View" + " " + viewcopy.Name);
                }
            }
            progressbarWPF.Close();

            /////////
            //IList<Element> rf = sel.PickElementsByRectangle(new Filterdetailline(), "Detailline");
            //ICollection<ElementId> listd = new List<ElementId>();
            //foreach (Element e in rf)
            //{
            //    listd.Add(e.Id);
            //}
            //List<XYZ> list = insulationlbr.GetIntersectXYZoncurve(doc, listd);
            //List<FamilySymbol> listsym = insulationlbr.GetFamilySymbols(doc);
            //List<Rectangleslbr> soluong = Rectangleslbr.CreateRectangle(doc, list);
            ////insulationlbr.PlaceSymmbolonRectangles(doc, listsym, soluong);
            //List<List<Rectangleslbr>> listrec = new List<List<Rectangleslbr>>();
            //listrec = Rectangleslbr.ListRecVert(soluong);
            //TaskDialog.Show("SSS", soluong.Count.ToString());
            ////insulationlbr.PlaceSymmbolonPoint(doc, listsym, list);
            //insulationlbr.PlaceSymmbolonRectangles(doc, listsym, soluong);
            return(Result.Succeeded);
        }
示例#7
0
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
                                                ref string message, ElementSet elements)
        {
            //get document
            UIDocument uiDoc = revit.Application.ActiveUIDocument;
            Document   doc   = uiDoc.Document;

            //work with host file
            List <Element> tableElments = getAllTablesDataNotLinked(revit);

            List <ResultClass> resultList     = new List <ResultClass>();
            List <string>      resultsStrings = new List <string>();

            //get relevet face turn to solid and get intersecting elements.
            foreach (Element el in tableElments)
            {
                List <Solid> geometrySolidsList = getSolidsListOfElement(revit, el);

                Solid largestSolid = LargestSolidElement(geometrySolidsList);

                FaceArray  faces   = largestSolid.Faces;
                PlanarFace topFace = TopFaceOriantasion(faces);

                Solid preTransformSolid = GeometryCreationUtilities.CreateExtrusionGeometry(topFace.GetEdgesAsCurveLoops(),
                                                                                            topFace.FaceNormal, 1);

                var   tableFamilyInstance = el as FamilyInstance;
                Solid solid = SolidUtils.CreateTransformed(preTransformSolid, tableFamilyInstance.GetTransform());
                PaintSolid(doc, solid, 1);

                List <Element> temIntersectingList = getIntersectingSolidElements(solid, uiDoc, doc);
                List <string>  itersectingElms     = new List <string>();

                //if intersecting elements "write them".
                if (temIntersectingList.Any())
                {
                    foreach (Element intsecEl in temIntersectingList)
                    {
                        itersectingElms.Add(intsecEl.Name);
                    }
                }
                //create a result class with all properties.
                ResultClass resClass = new ResultClass(Int32.Parse(el.Id.ToString()),
                                                       el.Document.Title, itersectingElms.Any(), itersectingElms);

                resultsStrings.Add(resClass.instancePrint());
            }
            string finalMessage = "";

            foreach (string str in resultsStrings)
            {
                finalMessage += str + Environment.NewLine;
            }
            //show results.
            TaskDialog.Show("revit", finalMessage + Environment.NewLine + "Done in host model");

            //work with linked doc.
            List <Element> linkedTables         = getLinkedDocFurniture(doc);
            List <string>  linkedResultsStrings = new List <string>();

            var linkedTransformed = new FilteredElementCollector(doc).OfClass(typeof(RevitLinkInstance))
                                    .Select(lm =>
            {
                var linkedModel = ((RevitLinkInstance)lm);
                return(linkedModel.GetTransform());
            })
                                    .FirstOrDefault();

            //get relevet face turn to solid and get intersecting elements.
            foreach (Element el in linkedTables)
            {
                List <Solid> geometrySolidsList = getSolidsListOfElement(revit, el);
                Solid        largestSolid       = LargestSolidElement(geometrySolidsList);
                FaceArray    faces             = largestSolid.Faces;
                PlanarFace   topFace           = TopFaceOriantasion(faces);
                Solid        preTransformSolid = GeometryCreationUtilities.CreateExtrusionGeometry(
                    topFace.GetEdgesAsCurveLoops(), topFace.FaceNormal, 1);

                var tableInstance = el as FamilyInstance;
                var testSome      = el as Instance;

                Solid customTransformedSolid = TransformSolid(tableInstance.GetTransform(), linkedTransformed, preTransformSolid);

                PaintSolid(doc, customTransformedSolid, 1);

                List <Element> interSectsInLinked    = getIntersectingSolidElements(customTransformedSolid, uiDoc, doc);
                List <string>  linkedItersectingElms = new List <string>();

                if (interSectsInLinked.Any())
                {
                    foreach (Element intsecEl in interSectsInLinked)
                    {
                        linkedItersectingElms.Add(intsecEl.Name);
                    }
                }
                ResultClass resClass = new ResultClass(Int32.Parse(el.Id.ToString()),
                                                       el.Document.Title, interSectsInLinked.Any(), linkedItersectingElms);

                linkedResultsStrings.Add(resClass.instancePrint());
            }
            string linkeFinalMessage = "";

            foreach (string str in linkedResultsStrings)
            {
                linkeFinalMessage += str + Environment.NewLine;
            }
            TaskDialog.Show("revit", linkeFinalMessage + Environment.NewLine + "Done in linked model");


            return(Autodesk.Revit.UI.Result.Succeeded);
        }