コード例 #1
0
        public List <string> getModelLineStyles(Document m_doc)
        {
            //returns list of all model line styles in current model - used by dialog box
            List <string>            lineList     = new List <string>();
            FilteredElementCollector curCollector = new FilteredElementCollector(m_doc);
            CurveElementFilter       curFilter    = new CurveElementFilter(CurveElementType.ModelCurve);

            //GraphicsStyle curLineStyle = null;

            //need to filter our arcs and other curved lines
            foreach (ModelCurve curLine in curCollector.WherePasses(curFilter).ToElements())
            {
                //	curLineStyle = curLine.LineStyle;
                lineList.Add(curLine.LineStyle.Name.ToString());
            }

            //purge duplicates from list
            for (int i = lineList.Count - 1; i >= 1; i += -1)
            {
                if (lineList[i] == lineList[i - 1])
                {
                    lineList.RemoveAt(i);
                }
            }

            return(lineList);
        }
コード例 #2
0
        //get all model curves in the current model
        public static List <ModelCurve> getAllModelCurves(Document curDoc)
        {
            FilteredElementCollector curCollector = new FilteredElementCollector(curDoc);
            CurveElementFilter       curFilter    = new CurveElementFilter(CurveElementType.ModelCurve);

            //create list
            List <ModelCurve> lineList = new List <ModelCurve>();

            //loop through the elements - if element is a model line then add to list
            foreach (ModelCurve curCurve in curCollector.WherePasses(curFilter))
            {
                //add to list
                lineList.Add(curCurve);
            }

            return(lineList);
        }
コード例 #3
0
        //----------------Annotation and Lines --------------------------

        /*returns a list of all line styles in the current model
         * public static CategoryNameMap GetAllLineStyles(Document curDoc)
         * {
         *  //get all linestyles
         *  Category curCat = curDoc.Settings.Categories[BuiltInCategory.OST_Lines];
         *  CategoryNameMap subCats = curCat.SubCategories;
         *
         *  return subCats;
         * }*/

        //returns a list of all model lines styles in use in the current model
        public static List <GraphicsStyle> getAllModelLineStyles(Document curDoc)
        {
            //returns list of all model line styles in current model
            List <GraphicsStyle>     lineList     = new List <GraphicsStyle>();
            FilteredElementCollector curCollector = new FilteredElementCollector(curDoc);
            CurveElementFilter       curFilter    = new CurveElementFilter(CurveElementType.ModelCurve);
            GraphicsStyle            curLineStyle = null;

            //need to filter our arcs and other curved lines
            foreach (ModelCurve curLine in curCollector.WherePasses(curFilter))
            {
                curLineStyle = (GraphicsStyle)curLine.LineStyle;

                if (lineList.Contains(curLineStyle) == false)
                {
                    //add to list
                    lineList.Add(curLineStyle);
                }
            }

            return(lineList);
        }
コード例 #4
0
        public List <ModelCurve> getModelLinesByStyle(Document m_doc, string lineStyle)
        {
            //returns list containing all the models lines of the specific model line style
            List <ModelCurve>        lineList     = new List <ModelCurve>();
            FilteredElementCollector curCollector = new FilteredElementCollector(m_doc);
            CurveElementFilter       curFilter    = new CurveElementFilter(CurveElementType.ModelCurve);
            //GraphicsStyle curLineStyle = null;
            string curLineStyle;

            //loop through the elements - if element is a model line then add to list
            foreach (ModelCurve curCurve in curCollector.WherePasses(curFilter))
            {
                curLineStyle = curCurve.LineStyle.ToString();

                if (curLineStyle == lineStyle)
                {
                    //add curve to list
                    lineList.Add(curCurve);
                }
            }

            return(lineList);
        }
コード例 #5
0
ファイル: TestIntersect.cs プロジェクト: ian-quinn/manicotti
        // Main execution
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;
            View          view  = doc.ActiveView;
            Selection     sel   = uidoc.Selection;


            // Grab the current building level
            FilteredElementCollector colLevels = new FilteredElementCollector(doc)
                                                 .WhereElementIsNotElementType()
                                                 .OfCategory(BuiltInCategory.INVALID)
                                                 .OfClass(typeof(Level));
            Level firstLevel = colLevels.FirstElement() as Level;


            // LineStyle filter
            CurveElementFilter       filter       = new CurveElementFilter(CurveElementType.ModelCurve);
            FilteredElementCollector collector    = new FilteredElementCollector(doc);
            ICollection <Element>    founds       = collector.WherePasses(filter).ToElements();
            List <CurveElement>      importCurves = new List <CurveElement>();

            foreach (CurveElement ce in founds)
            {
                importCurves.Add(ce);
            }
            var          wallCurves = importCurves.Where(x => x.LineStyle.Name == "WALL").ToList();
            List <Curve> wallLines  = new List <Curve>(); // Algorithm only support walls of line type

            foreach (CurveElement ce in wallCurves)
            {
                wallLines.Add(ce.GeometryCurve as Curve);
            }

            //double parasStart = wallLines[0].GetEndParameter(0);
            //double parasEnd = wallLines[0].GetEndParameter(1);
            //wallLines[0].MakeUnbound();

            //double _parasStart = wallLines[1].GetEndParameter(0);
            //double _parasEnd = wallLines[1].GetEndParameter(1);
            //wallLines[1].MakeUnbound();

            SetComparisonResult result = wallLines[0].Intersect(wallLines[1], out IntersectionResultArray results);

            Debug.Assert(result != SetComparisonResult.Overlap, "Overlap");
            Debug.Assert(result != SetComparisonResult.BothEmpty, "BothEmpty");
            Debug.Assert(result != SetComparisonResult.Disjoint, "Disjoint");
            Debug.Assert(result != SetComparisonResult.Equal, "Equal");
            Debug.Assert(result != SetComparisonResult.LeftEmpty, "LeftEmpty");
            Debug.Assert(result != SetComparisonResult.RightEmpty, "RightEmpty");
            Debug.Assert(result != SetComparisonResult.Subset, "Subset");
            Debug.Assert(result != SetComparisonResult.Superset, "Superset");



            double radius  = Misc.MmToFoot(50);
            XYZ    ptStart = wallLines[0].GetEndPoint(0);
            XYZ    ptEnd   = wallLines[0].GetEndPoint(1);
            XYZ    xAxis   = new XYZ(1, 0, 0); // The x axis to define the arc plane. Must be normalized
            XYZ    yAxis   = new XYZ(0, 1, 0); // The y axis to define the arc plane. Must be normalized
            Curve  knob1   = Arc.Create(ptStart, radius, 0, 2 * Math.PI, xAxis, yAxis);
            Curve  knob2   = Arc.Create(ptEnd, radius, 0, 2 * Math.PI, xAxis, yAxis);
            SetComparisonResult result1 = knob1.Intersect(wallLines[1], out IntersectionResultArray results1);
            SetComparisonResult result2 = knob2.Intersect(wallLines[1], out IntersectionResultArray results2);

            // if (result1 == SetComparisonResult.Disjoint && result2 == SetComparisonResult.Disjoint)
            if ((result1 == SetComparisonResult.Overlap || result1 == SetComparisonResult.Subset ||
                 result1 == SetComparisonResult.Superset || result1 == SetComparisonResult.Equal) ||
                (result2 == SetComparisonResult.Overlap || result2 == SetComparisonResult.Subset ||
                 result2 == SetComparisonResult.Superset || result2 == SetComparisonResult.Equal))
            {
                Debug.Print("INTERSECTED!");
            }
            else
            {
                Debug.Print("DISJOINT!");
            }


            XYZ  ptStart1 = wallLines[0].GetEndPoint(0);
            XYZ  ptEnd1   = wallLines[0].GetEndPoint(1);
            XYZ  ptStart2 = wallLines[1].GetEndPoint(0);
            XYZ  ptEnd2   = wallLines[1].GetEndPoint(1);
            Line baseline = wallLines[1].Clone() as Line;

            baseline.MakeUnbound();
            XYZ _ptStart = baseline.Project(ptStart1).XYZPoint;
            XYZ _ptEnd   = baseline.Project(ptEnd1).XYZPoint;

            Debug.Print("_start: " + Misc.PointString(_ptStart));
            Debug.Print("_end: " + Misc.PointString(_ptEnd));
            Line checkline = Line.CreateBound(_ptStart, _ptEnd);
            SetComparisonResult projection = checkline.Intersect(wallLines[1] as Line, out IntersectionResultArray projections);

            Debug.Print("Shadowing?" + projection.ToString());
            if (projection == SetComparisonResult.Equal)
            {
                Debug.Print("Shadowing");
            }
            {
                Debug.Print("Departed");
            }
            Curve proj1 = Arc.Create(_ptStart, radius, 0, 2 * Math.PI, xAxis, yAxis);
            Curve proj2 = Arc.Create(_ptEnd, radius, 0, 2 * Math.PI, xAxis, yAxis);


            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Generate sub-surface and its mark");

                Plane       Geomplane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);
                SketchPlane sketch    = SketchPlane.Create(doc, Geomplane);

                ModelCurve modelline1 = doc.Create.NewModelCurve(proj1, sketch) as ModelCurve;
                ModelCurve modelline2 = doc.Create.NewModelCurve(proj2, sketch) as ModelCurve;

                tx.Commit();
            }

            return(Result.Succeeded);
        }
コード例 #6
0
        /// <summary>
        /// Create wall system, floor, and allocate rooms
        /// </summary>

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;
            View          view  = doc.ActiveView;

            Autodesk.Revit.Creation.Application appCreation = app.Create;
            Autodesk.Revit.Creation.Document    docCreation = doc.Create;

            // Access current selection
            Selection sel = uidoc.Selection;

            // Extraction of CurveElements by LineStyle WALL
            CurveElementFilter       filter       = new CurveElementFilter(CurveElementType.ModelCurve);
            FilteredElementCollector collector    = new FilteredElementCollector(doc);
            ICollection <Element>    founds       = collector.WherePasses(filter).ToElements();
            List <CurveElement>      importCurves = new List <CurveElement>();

            foreach (CurveElement ce in founds)
            {
                importCurves.Add(ce);
            }
            var          strayCurves = importCurves.Where(x => x.LineStyle.Name == "WALL").ToList();
            List <Curve> strayLines  = new List <Curve>();

            foreach (CurveElement ce in strayCurves)
            {
                strayLines.Add(ce.GeometryCurve as Line);
            }


            // Grab the current building level
            FilteredElementCollector colLevels = new FilteredElementCollector(doc)
                                                 .WhereElementIsNotElementType()
                                                 .OfCategory(BuiltInCategory.INVALID)
                                                 .OfClass(typeof(Level));
            Level firstLevel = colLevels.FirstElement() as Level;


            // Grab the building view
            // This may be useful when handling room allocation on separate levels
            //FilteredElementCollector colViews = new FilteredElementCollector(doc)
            //    .OfClass(typeof(View));
            //View firstView = colViews.FirstElement() as View;


            // Grab the building floortype
            FloorType floorType = new FilteredElementCollector(doc)
                                  .OfClass(typeof(FloorType))
                                  .First <Element>(e => e.Name.Equals("Generic 150mm")) as FloorType;


            // Modify document within a transaction
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Generate Walls");

                List <CurveArray> curveGroup = RegionCluster(strayLines);
                //var (mesh, perimeter) = FlattenLines(curveGroup);

                Plane       Geomplane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);
                SketchPlane sketch    = SketchPlane.Create(doc, Geomplane);

                foreach (CurveArray group in curveGroup)
                {
                    foreach (Curve edge in group)
                    {
                        DetailLine    axis = doc.Create.NewDetailCurve(view, edge) as DetailLine;
                        GraphicsStyle gs   = axis.LineStyle as GraphicsStyle;
                        gs.GraphicsStyleCategory.LineColor = new Color(202, 51, 82);
                        gs.GraphicsStyleCategory.SetLineWeight(7, gs.GraphicsStyleType);
                    }
                }


                /*
                 * Region detect and boolean union all have bugs to fix
                 * DO NOT TEST THIS ONE
                 *
                 *
                 *
                 * // Wall generation
                 * foreach (Curve wallAxis in mesh)
                 * {
                 *  Wall.Create(doc, wallAxis, firstLevel.Id, true);
                 * }
                 *
                 * // Create.NewRoom will automatically detect the topology according to the wall system
                 * // Don't bother sketching boundary lines unless you're handling a virtual room
                 * //docCreation.NewSpaceBoundaryLines(doc.ActiveView.SketchPlane, mesh, doc.ActiveView);
                 * doc.Regenerate();
                 *
                 * PlanTopology planTopology = doc.get_PlanTopology(firstLevel);
                 * if (doc.ActiveView.ViewType == ViewType.FloorPlan)
                 * {
                 *  foreach (PlanCircuit circuit in planTopology.Circuits)
                 *  {
                 *      if (null != circuit && !circuit.IsRoomLocated)
                 *      {
                 *          var room = doc.Create.NewRoom(null, circuit);
                 *          //Debug.Print("New room created!");
                 *      }
                 *  }
                 * }
                 * /* // add error handling here
                 * else
                 * {
                 *  System.Windows.Forms.MessageBox.Show("You can not create spaces in this plan view");
                 * }
                 */
                /*
                 * Floor newFloor = doc.Create.NewFloor(AlignCrv(perimeter), floorType, firstLevel, false, XYZ.BasisZ);
                 * newFloor.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).Set(0);
                 */

                tx.Commit();
            }


            return(Result.Succeeded);
        }