Esempio n. 1
0
        public List <RevitModelRequest> GroupData(InputRequest inputRequest)
        {
            List <RevitModelRequest> returnValue     = new List <RevitModelRequest>();
            List <LineElement>       useLineElements =
                inputRequest.SelectDataMap["wallLine"].Cast <LineElement>().ToList();

            for (int i = 0; i < useLineElements.Count; i++)
            {
                if (useLineElements[i].ThisCurve.Length < limitLength)
                {
                    continue;
                }

                for (int j = i + 1; j < useLineElements.Count; j++)
                {
                    if (useLineElements[j].ThisCurve.Length < limitLength)
                    {
                        continue;
                    }

                    if (useLineElements[i].IfParallel(useLineElements[j]))
                    {
                        UseRevitModelRequest tempRequest = new UseRevitModelRequest();

                        UseGroupCADElement tempGropuCADELement = new UseGroupCADElement();
                        tempGropuCADELement.LstCurveElements = new List <CurveCadElement>()
                        {
                            useLineElements[j], useLineElements[i]
                        };

                        tempRequest.RequestData = tempGropuCADELement;
                        returnValue.Add(tempRequest);
                    }
                }
            }

            return(returnValue);
        }
Esempio n. 2
0
        public bool TryRebuildRevitModel(Autodesk.Revit.DB.Document inputDoc, RevitModelRequest inputReqeust, out Autodesk.Revit.DB.Element createdElement)
        {
            createdElement = null;
            try
            {
                UseRevitModelRequest useRequest = inputReqeust as UseRevitModelRequest;

                LineElement line1 = inputReqeust.RequestData.LstCurveElements[0] as LineElement;

                LineElement line2 = inputReqeust.RequestData.LstCurveElements[1] as LineElement;

                XYZ midStart, midEnd;

                double width;

                if (line1.ThisCurve.Project(line2.ThisCurve.GetEndPoint(0)).XYZPoint.IsAlmostEqualTo(line1.ThisCurve.GetEndPoint(0)))
                {
                    midStart = (line1.ThisCurve.GetEndPoint(0) + line2.ThisCurve.GetEndPoint(0)) / 2;
                    midEnd   = (line1.ThisCurve.GetEndPoint(1) + line2.ThisCurve.GetEndPoint(1)) / 2;
                    width    = line1.ThisCurve.GetEndPoint(0).DistanceTo(line2.ThisCurve.GetEndPoint(0));
                }
                else
                {
                    midStart = (line1.ThisCurve.GetEndPoint(0) + line2.ThisCurve.GetEndPoint(1)) / 2;
                    midEnd   = (line1.ThisCurve.GetEndPoint(1) + line2.ThisCurve.GetEndPoint(0)) / 2;
                    width    = line1.ThisCurve.GetEndPoint(0).DistanceTo(line2.ThisCurve.GetEndPoint(1));
                }

                Line useMidLine = Line.CreateBound(midStart, midEnd);

                string useTypeName = inputReqeust.UseTypeName;

                FilteredElementCollector useCollector = new FilteredElementCollector(inputDoc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsElementType();

                ElementType useElementType = null;

                foreach (var oneElement in useCollector.ToElements())
                {
                    if (oneElement.Name == useTypeName)
                    {
                        useElementType = oneElement as ElementType;
                        break;
                    }
                }



                Transaction useTransaction = new Transaction(inputDoc, "creatWall");
                useTransaction.Start();
                useElementType = useElementType.Duplicate(useTypeName + Guid.NewGuid().ToString());

                var useStructure = (useElementType as WallType).GetCompoundStructure();
                useStructure.SetLayerWidth(0, width);
                (useElementType as WallType).SetCompoundStructure(useStructure);

                createdElement = Wall.Create(inputDoc, useMidLine, (inputDoc.ActiveView as ViewPlan).GenLevel.Id, false);
                (createdElement as Wall).WallType = useElementType as WallType;
                useTransaction.Commit();


                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }