private static ElementId GetDash(this Document doc) { var collector = new FilteredElementCollector(doc) .OfClass(typeof(LinePatternElement)) .ToElementIds().ToList(); foreach (var id in collector) { LinePatternElement lpe = doc.GetElement(id) as LinePatternElement; string name = lpe.Name; if (lpe.Name == "Dash") { return(lpe.Id); } } LinePattern lp = new LinePattern("Dash"); List <LinePatternSegment> Segments = new List <LinePatternSegment>(); Segments.Add(new LinePatternSegment(LinePatternSegmentType.Dash, 0.05)); Segments.Add(new LinePatternSegment(LinePatternSegmentType.Space, 0.05)); lp.SetSegments(Segments); LinePatternElement lped = LinePatternElement.Create(doc, lp); return(lped.Id); }
/// <summary> /// Draw point marker with detail circles. /// Optional colors are "red" "blue" "orange" /// </summary> public static void DrawDetailMarkers(Document doc, List <XYZ> pts, int weight = 2, string color = "red", string pattern = "") { GetListOfLinestyles(doc); View view = doc.ActiveView; Color palette = new Color(0, 0, 0); switch (color) { case "red": palette = new Color(200, 50, 80); break; case "blue": palette = new Color(100, 149, 237); break; case "orange": palette = new Color(255, 140, 0); break; } FilteredElementCollector fec = new FilteredElementCollector(doc) .OfClass(typeof(LinePatternElement)); LinePatternElement linePatternElem = null; if (pattern != "") { try { linePatternElem = fec .Cast <LinePatternElement>() .First <LinePatternElement>(linePattern => linePattern.Name == pattern); } catch { Debug.Print("There's no matching pattern in the document"); } } XYZ xAxis = new XYZ(1, 0, 0); XYZ yAxis = new XYZ(0, 1, 0); using (Transaction tx = new Transaction(doc)) { tx.Start("Create Detail Markers"); foreach (XYZ pt in pts) { double radius = 0.3; Arc marker = Arc.Create(pt, radius, 0, 2 * Math.PI, xAxis, yAxis); DetailCurve detailCrv = doc.Create.NewDetailCurve(view, marker); GraphicsStyle gs = detailCrv.LineStyle as GraphicsStyle; gs.GraphicsStyleCategory.LineColor = palette; gs.GraphicsStyleCategory.SetLineWeight(weight, gs.GraphicsStyleType); if (linePatternElem != null) { gs.GraphicsStyleCategory.SetLinePatternId(linePatternElem.Id, GraphicsStyleType.Projection); } } tx.Commit(); } }
private static ElementId[] GetLineStyles(this Document doc) { ElementId[] eids = new ElementId[5]; var collector = new FilteredElementCollector(doc) .OfClass(typeof(LinePatternElement)) .ToElementIds().ToList(); bool[] check = new bool[5] { false, false, false, false, false }; foreach (var id in collector) { LinePatternElement lpe = doc.GetElement(id) as LinePatternElement; string name = lpe.Name; if (Names.Contains(name)) { check[Names.ToList().IndexOf(name)] = true; eids[Names.ToList().IndexOf(name)] = lpe.Id; } } if (!check[0]) { eids[0] = LinePatternElement.GetSolidPatternId(); } if (!check[1]) { TaskDialog.Show("Test", "Dash Trying to be Created"); LinePattern lp = new LinePattern("Dash"); lp.SetSegments(CreateDash()); LinePatternElement lpe = LinePatternElement.Create(doc, lp); eids[1] = lpe.Id; } if (!check[2]) { LinePattern lp = new LinePattern("Dot"); lp.SetSegments(CreateDot()); LinePatternElement lpe = LinePatternElement.Create(doc, lp); eids[2] = lpe.Id; } if (!check[3]) { LinePattern lp = new LinePattern("Center"); lp.SetSegments(CreateCenter()); LinePatternElement lpe = LinePatternElement.Create(doc, lp); eids[3] = lpe.Id; } if (!check[4]) { LinePattern lp = new LinePattern("Hidden"); lp.SetSegments(CreateHidden()); LinePatternElement lpe = LinePatternElement.Create(doc, lp); eids[4] = lpe.Id; } return(eids); }
public ViewsOICBRequest(UIApplication uiApp, String text) { UIDocument uidoc = uiApp.ActiveUIDocument; //Collect all viewers and viewports var viewerCollector = new FilteredElementCollector(uidoc.Document).OfCategory(BuiltInCategory.OST_Viewers); var viewportCollector = new FilteredElementCollector(uidoc.Document).OfClass(typeof(Viewport)).ToElements(); //Generate an OverrideGraphicsSetting OverrideGraphicSettings orgs = new OverrideGraphicSettings(); //Use the solid line pattern orgs.SetProjectionLinePatternId(LinePatternElement.GetSolidPatternId()); //Set the line weight to the property value orgs.SetProjectionLineWeight(Properties.Settings.Default.RevitOverrideInteriorCropWeight); //Start a new transaction and cycle through the viewports Transaction t1 = new Transaction(uidoc.Document, "OverrideInteriorElevationCrops"); t1.Start(); foreach (Viewport viewport in viewportCollector) { //Get the view associated with the viewport, then get its ViewType ElementId viewId = viewport.ViewId; Element viewElem = uidoc.Document.GetElement(viewId); Autodesk.Revit.DB.View viewElemView = viewElem as Autodesk.Revit.DB.View; ElementId typeId = viewElem.GetTypeId(); Element typeElement = uidoc.Document.GetElement(typeId); string typeElementName = typeElement.Name.ToString(); //If the view is a derivative of a section, its type is an Elevation, and its type name contains Interior, continue if (viewElem.GetType().ToString() == "Autodesk.Revit.DB.ViewSection" && viewElemView.ViewType == ViewType.Elevation && typeElementName.Contains("Interior")) { //Get the viewers and cycle through them var viewers = new FilteredElementCollector(uidoc.Document).OfCategory(BuiltInCategory.OST_Viewers); foreach (Element viewer in viewerCollector) { //If the viewer's name is equal to the view's name, continue if (viewer.Name.ToString() == viewElem.Name.ToString()) { //Override the view element's viewer with the settings Autodesk.Revit.DB.View viewToOverride = viewElem as Autodesk.Revit.DB.View; viewToOverride.SetElementOverrides(viewer.Id, orgs); } else { continue; } } } else { continue; } } t1.Commit(); }
/// <summary> /// Draw detail curves based on List<Curve> /// </summary> public static void DrawDetailLines(Document doc, List <Curve> crvs, int weight = 2, string color = "red", string pattern = "") { GetListOfLinestyles(doc); View view = doc.ActiveView; Color palette = new Color(0, 0, 0); switch (color) { case "red": palette = new Color(200, 50, 80); break; case "blue": palette = new Color(100, 149, 237); break; case "orange": palette = new Color(255, 140, 0); break; } FilteredElementCollector fec = new FilteredElementCollector(doc) .OfClass(typeof(LinePatternElement)); LinePatternElement linePatternElem = null; if (pattern != "") { try { linePatternElem = fec .Cast <LinePatternElement>() .First <LinePatternElement>(linePattern => linePattern.Name == pattern); } catch { Debug.Print("There's no matching pattern in the document"); } } using (Transaction tx = new Transaction(doc)) { tx.Start("Create Detail Curves"); foreach (Curve crv in crvs) { // Should do style setting here or...? DetailCurve detailCrv = doc.Create.NewDetailCurve(view, crv); GraphicsStyle gs = detailCrv.LineStyle as GraphicsStyle; gs.GraphicsStyleCategory.LineColor = palette; gs.GraphicsStyleCategory.SetLineWeight(weight, gs.GraphicsStyleType); if (linePatternElem != null) { gs.GraphicsStyleCategory.SetLinePatternId(linePatternElem.Id, GraphicsStyleType.Projection); } } tx.Commit(); } }
/// <summary> /// Create a new line style using NewSubcategory /// </summary> void CreateLineStyle(Document doc) { // Use this to access the current document in a macro. // //Document doc = this.ActiveUIDocument.Document; // Find existing linestyle. Can also opt to // create one with LinePatternElement.Create() FilteredElementCollector fec = new FilteredElementCollector(doc) .OfClass(typeof(LinePatternElement)); LinePatternElement linePatternElem = fec .Cast <LinePatternElement>() .First <LinePatternElement>(linePattern => linePattern.Name == "Long Dash"); // The new linestyle will be a subcategory // of the Lines category Categories categories = doc.Settings.Categories; Category lineCat = categories.get_Item( BuiltInCategory.OST_Lines); using (Transaction t = new Transaction(doc)) { t.Start("Create LineStyle"); // Add the new linestyle Category newLineStyleCat = categories .NewSubcategory(lineCat, "New LineStyle"); doc.Regenerate(); // Set the linestyle properties // (weight, color, pattern). newLineStyleCat.SetLineWeight(8, GraphicsStyleType.Projection); newLineStyleCat.LineColor = new Color( 0xFF, 0x00, 0x00); newLineStyleCat.SetLinePatternId( linePatternElem.Id, GraphicsStyleType.Projection); t.Commit(); } }
/// <summary> /// Get the Revit Object representation of the Line Pattern Element. /// </summary> /// <returns>LinePatternElement object</returns> public LinePatternElement GetLinePatternElement() { LinePatternElement patternElement = null; // Account for deprecated API methods and missing objects from "Solid" line patterns. try { patternElement = Doc.GetElement(LinePatternId) as LinePatternElement; } catch (Exception exceptionPattern) { Console.WriteLine(exceptionPattern.ToString()); } return(patternElement); }
/// <summary> /// A Linestyle is a Document Setting in Revit, not a typical object. The Category object contains the Linestyle information. /// </summary> /// <param name="doc">The Revit Document object.</param> /// <param name="subCategoryLinestyle">Revit Category object.</param> public LinestyleST(Document doc, Category subCategoryLinestyle) { Doc = doc; SubCategoryLinestyle = subCategoryLinestyle; LineStyleName = SubCategoryLinestyle.Name; LineStyleId = SubCategoryLinestyle.Id; LineStyleWeight = SubCategoryLinestyle.GetLineWeight(GraphicsStyleType.Projection).ToString(); LineStyleRgb = GetLineStyleRgb(); LinePatternId = GetLinePatternId(); LinePatternName = GetLinePatternName(); LinePatternElement = GetLinePatternElement(); LinePattern = GetLinePattern(); LinePatternComponentsLength = GetLinePatternSegmentLengths(); LinePatternComponentsType = GetLinePatternSegmentTypes(); Serialized = JsonConvert.SerializeObject(this); JsonObject = JObject.Parse(Serialized); }
/// <summary> /// 创建线型图案 CreatLinePattern /// </summary> /// <param name="doc"></param> /// <param name="patternName"></param> /// <returns></returns> public static LinePatternElement CreatLinePatternElement(Document doc, string patternName) { List <LinePatternSegment> lstSegments = new List <LinePatternSegment>(); lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Dot, 0.0)); lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Space, 0.02)); lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Dash, 0.03)); lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Space, 0.02)); LinePattern _linePattern = new LinePattern(patternName); _linePattern.SetSegments(lstSegments); using (Transaction trans = new Transaction(doc)) { trans.Start("Create a linepattern element"); LinePatternElement linePatternElement = LinePatternElement.Create(doc, _linePattern); trans.Commit(); return(linePatternElement); } }
/// <summary> /// Create a linepattern element /// </summary> /// <param name="patternName">The linepattern name</param> /// <returns>Created linepattern element</returns> private LinePatternElement CreateLinePatternElement(string patternName) { //Create list of segments which define the line pattern List <LinePatternSegment> lstSegments = new List <LinePatternSegment>(); lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Dot, 0.0)); lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Space, 0.02)); lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Dash, 0.03)); lstSegments.Add(new LinePatternSegment(LinePatternSegmentType.Space, 0.02)); LinePattern linePattern = new LinePattern(patternName); linePattern.SetSegments(lstSegments); Transaction trans = new Transaction(doc); trans.Start("Create a linepattern element"); LinePatternElement linePatternElement = LinePatternElement.Create(doc, linePattern); trans.Commit(); return(linePatternElement); }
/// <summary> /// Create a linepattern element and apply it to grids /// </summary> /// <param name="sender">This object</param> /// <param name="e">A object contains the event data</param> private void buttonCreateLinePattern_Click(object sender, EventArgs e) { List <ElementId> lstGridTypeIds = new List <ElementId>(); GetSelectedGridTypeIds(lstGridTypeIds); if (lstGridTypeIds.Count == 0) { TaskDialog.Show("Apply To Grids", "Before applying a LinePattern to Grids, you must first select at least one grid."); this.Close(); return; } LinePatternElement myLinePatternElement = CreateLinePatternElement("MyLinePattern"); foreach (ElementId typeId in lstGridTypeIds) { Element gridType = doc.GetElement(typeId); //set the parameter value of End Segment Pattern SetParameter("End Segment Pattern", myLinePatternElement.Id, gridType); } this.Close(); }
protected GraphicsStyle NewLineStyle( Document doc, string styleName, int weight, Color color, string patternName) { // Use this to access the current document in a macro. // //Document doc = this.ActiveUIDocument.Document; // Find existing linestyle. Can also opt to // create one with LinePatternElement.Create() FilteredElementCollector fec = new FilteredElementCollector(doc) .OfClass(typeof(LinePatternElement)); LinePatternElement linePatternElem = fec .Cast <LinePatternElement>() .First(linePattern => linePattern.Name == patternName); // The new linestyle will be a subcategory // of the Lines category Categories categories = doc.Settings.Categories; Category lineCat = categories.get_Item( BuiltInCategory.OST_Lines); Category newLineStyleCat; using (Transaction t = new Transaction(doc, "Create LineStyle")) { t.Start(); // Add the new linestyle newLineStyleCat = categories .NewSubcategory(lineCat, styleName); doc.Regenerate(); // Set the linestyle properties // (weight, color, pattern). newLineStyleCat.SetLineWeight( weight, GraphicsStyleType.Projection); newLineStyleCat.LineColor = color; newLineStyleCat.SetLinePatternId( linePatternElem.Id, GraphicsStyleType.Projection); t.Commit(); } return(newLineStyleCat.GetGraphicsStyle(GraphicsStyleType.Projection)); }
// Main thread 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; double tolerance = app.ShortCurveTolerance; // Pick Import Instance ImportInstance import = null; try { Reference r = uidoc.Selection.PickObject(ObjectType.Element, new Util.ElementsOfClassSelectionFilter <ImportInstance>()); import = doc.GetElement(r) as ImportInstance; } catch { return(Result.Cancelled); } if (import == null) { System.Windows.MessageBox.Show("CAD not found", "Tips"); return(Result.Cancelled); } List <Curve> columnCrvs = Util.TeighaGeometry.ShatterCADGeometry(uidoc, import, "COLUMN", tolerance); List <Curve> wallCrvs = Util.TeighaGeometry.ShatterCADGeometry(uidoc, import, "WALL", tolerance); List <Curve> doorCrvs = Util.TeighaGeometry.ShatterCADGeometry(uidoc, import, "DOOR", tolerance); List <Curve> windowCrvs = Util.TeighaGeometry.ShatterCADGeometry(uidoc, import, "WINDOW", tolerance); //List<Line> columnLines = Util.CrvsToLines(columnCrvs); //List<Line> wallLines = Util.CrvsToLines(wallCrvs); // Merge the overlapped wall boundaries // Seal the wall boundary by column block // INPUT List<Line> wallLines, List<Line> columnLines #region PATCH wallLines List <Line> patchLines = new List <Line>(); List <XYZ> sectPts = new List <XYZ>(); // Seal the wall when encountered with column foreach (Curve columnCrv in columnCrvs) { sectPts.Clear(); foreach (Line wallCrv in wallCrvs) { if (!Algorithm.IsParallel(columnCrv, wallCrv)) { SetComparisonResult result = wallCrv.Intersect(columnCrv, out IntersectionResultArray results); if (result != SetComparisonResult.Disjoint) { XYZ sectPt = results.get_Item(0).XYZPoint; sectPts.Add(sectPt); } } else { continue; } } if (sectPts.Count() == 2) { patchLines.Add(Line.CreateBound(sectPts[0], sectPts[1])); } if (sectPts.Count() > 2) // not sure how to solve this { Line minPatch = Line.CreateBound(XYZ.Zero, 10000 * XYZ.BasisX); for (int i = 0; i < sectPts.Count(); i++) { for (int j = i + 1; j < sectPts.Count(); j++) { if (sectPts[i].DistanceTo(sectPts[j]) > 0.001) { Line testPatch = Line.CreateBound(sectPts[i], sectPts[j]); if (testPatch.Length < minPatch.Length) { minPatch = testPatch; } } } } patchLines.Add(minPatch); } } // Patch for the wall lines wallCrvs.AddRange(patchLines); // Merge lines when they are parallel and almost intersected (knob) List <Curve> mergeLines = CloseGapAtBreakpoint(wallCrvs); // List <Curve> fixedLines = CloseGapAtCorner(mergeLines); #endregion // OUTPUT List<Line> fixedLines // INPUT List<Line> fixedLines #region Cluster the wallLines by hierarchy var wallClusters = Algorithm.ClusterByIntersect(fixedLines); Debug.Print("{0} clustered wall blocks in total", wallClusters.Count); // Generate boundingbox marker for the wall cluster List <List <Curve> > wallBlocks = new List <List <Curve> > { }; foreach (List <Curve> cluster in wallClusters) { List <Curve> clusterCrv = cluster; if (null != Algorithm.CreateBoundingBox2D(clusterCrv)) { wallBlocks.Add(Algorithm.CreateBoundingBox2D(clusterCrv)); } } Debug.Print("{0} clustered wall bounding boxes in total", wallBlocks.Count); #endregion // INPUT List<List< Curve >> wallClusters Debug.Print("WALL LINES PATCH & CLUSTERING COMPLETE!"); // INPUT List<List<Curve>> wallClusters #region Iterate the generaion of axis // Wall axes List <Curve> axes = new List <Curve>(); double bias = Misc.MmToFoot(20); foreach (List <Curve> wallCluster in wallClusters) { List <Line> lines = Misc.CrvsToLines(wallCluster); for (int i = 0; i < lines.Count; i++) { for (int j = 0; j < lines.Count - i; j++) { if (Algorithm.IsParallel(lines[i], lines[i + j]) && !Algorithm.IsIntersected(lines[i], lines[i + j])) { if (Algorithm.LineSpacing(lines[i], lines[i + j]) < Misc.MmToFoot(200) + bias && Algorithm.LineSpacing(lines[i], lines[i + j]) > Misc.MmToFoot(200) - bias && Algorithm.IsShadowing(lines[i], lines[i + j])) { if (Algorithm.GenerateAxis(lines[i], lines[i + j]) != null) { axes.Add(Algorithm.GenerateAxis(lines[i], lines[i + j])); Debug.Print("got it!"); } } } } } } #endregion // OUTPUT List<Line> axes Debug.Print("WALL AXIS ITERATION COMPLETE!"); // INPUT List<Curve> doorCrvs // INPUT List<Curve> windowCrvs // INPUT List<Line> axes #region Merge axis joined/overlapped // Door axes var doorClusters = Algorithm.ClusterByIntersect(doorCrvs); List <List <Curve> > doorBlocks = new List <List <Curve> > { }; foreach (List <Curve> cluster in doorClusters) { if (null != Algorithm.CreateBoundingBox2D(cluster)) { doorBlocks.Add(Algorithm.CreateBoundingBox2D(cluster)); } } List <Curve> doorAxes = new List <Curve> { }; foreach (List <Curve> doorBlock in doorBlocks) { List <Curve> doorFrame = new List <Curve> { }; for (int i = 0; i < doorBlock.Count; i++) { int sectCount = 0; List <Line> fenses = new List <Line>(); foreach (Line line in fixedLines) { Curve testCrv = doorBlock[i].Clone(); SetComparisonResult result = RegionDetect.ExtendCrv(testCrv, 0.01).Intersect(line, out IntersectionResultArray results); if (result == SetComparisonResult.Overlap) { sectCount += 1; fenses.Add(line); } } if (sectCount == 2) { XYZ projecting = fenses[0].Evaluate(0.5, true); XYZ projected = fenses[1].Project(projecting).XYZPoint; if (fenses[0].Length > fenses[1].Length) { projecting = fenses[1].Evaluate(0.5, true); projected = fenses[0].Project(projecting).XYZPoint; } Line doorAxis = Line.CreateBound(projecting, projected); doorAxes.Add(doorAxis); //doorAxes.Add(doorBlock[i]); } } } // Window axes var windowClusters = Algorithm.ClusterByIntersect(windowCrvs); List <List <Curve> > windowBlocks = new List <List <Curve> > { }; foreach (List <Curve> cluster in windowClusters) { if (null != Algorithm.CreateBoundingBox2D(cluster)) { windowBlocks.Add(Algorithm.CreateBoundingBox2D(cluster)); } } List <Curve> windowAxes = new List <Curve> { }; foreach (List <Curve> windowBlock in windowBlocks) { Line axis1 = Line.CreateBound((windowBlock[0].GetEndPoint(0) + windowBlock[0].GetEndPoint(1)).Divide(2), (windowBlock[2].GetEndPoint(0) + windowBlock[2].GetEndPoint(1)).Divide(2)); Line axis2 = Line.CreateBound((windowBlock[1].GetEndPoint(0) + windowBlock[1].GetEndPoint(1)).Divide(2), (windowBlock[3].GetEndPoint(0) + windowBlock[3].GetEndPoint(1)).Divide(2)); if (axis1.Length > axis2.Length) { windowAxes.Add(axis1); } else { windowAxes.Add(axis2); } } axes.AddRange(windowAxes); axes.AddRange(doorAxes); Debug.Print("Checklist for axes: Door-{0}, Window-{1}, All-{2}", doorAxes.Count, windowAxes.Count, axes.Count); List <Curve> axesExtended = new List <Curve>(); foreach (Curve axis in axes) { axesExtended.Add(Algorithm.ExtendLine(axis, 200)); } // Axis merge List <List <Curve> > axisGroups = Algorithm.ClusterByOverlap(axesExtended); List <Curve> centerLines = new List <Curve>(); foreach (List <Curve> axisGroup in axisGroups) { var merged = Algorithm.FuseLines(axisGroup); centerLines.Add(merged); } #endregion // OUTPUT List<Line> centerLines Debug.Print("WINDOW / DOOR LINES JOINED!"); // INPUT List<Curve> columnCrvs // INPUT List<Line> centerLines #region Extend and trim the axis (include column corner) List <List <Curve> > columnGroups = Algorithm.ClusterByIntersect(columnCrvs); foreach (List <Curve> columnGroup in columnGroups) { //List<Line> columnGrouplines = Util.CrvsToLines(columnGroup); List <Curve> nestLines = new List <Curve>(); for (int i = 0; i < columnGroup.Count; i++) { foreach (Line centerLine in centerLines) { SetComparisonResult result = columnGroup[i].Intersect(centerLine, out IntersectionResultArray results); if (result == SetComparisonResult.Overlap) { for (int j = 0; j < columnGroup.Count; j++) { if (j != i) { if (null != ExtendLine(centerLine, columnGroup[j])) { nestLines.Add(ExtendLine(centerLine, columnGroup[j])); } } } } } } Debug.Print("Got nested lines: " + nestLines.Count.ToString()); if (nestLines.Count < 2) { continue; } else { centerLines.AddRange(nestLines); int count = 0; for (int i = 1; i < nestLines.Count; i++) { if (!Algorithm.IsParallel(nestLines[0], nestLines[i])) { count += 1; } } if (count == 0) { var patches = Algorithm.CenterLinesOfBox(columnGroup); foreach (Line patch in patches) { if (Algorithm.IsLineIntersectLines(patch, nestLines)) { centerLines.Add(patch); } } } } } #endregion // OUTPUT List<Line> centerLines Debug.Print("AXES JOINED AT COLUMN"); // INPUT List<Line> centerLines //#The region detect function has fatal bug during boolean union operation #region Call region detection // Axis merge List <List <Curve> > tempStrays = Algorithm.ClusterByOverlap(centerLines); List <Curve> strays = new List <Curve>(); foreach (List <Curve> tempStray in tempStrays) { Curve merged = Algorithm.FuseLines(tempStray); strays.Add(merged); } //var strayClusters = Algorithm.ClusterByIntersect(Util.LinesToCrvs(strays)); //Debug.Print("Cluster of strays: " + strayClusters.Count.ToString()); //Debug.Print("Cluster of strays[0]: " + strayClusters[0].Count.ToString()); //Debug.Print("Cluster of strays[1]: " + strayClusters[1].Count.ToString()); // The RegionCluster method should be applied to each cluster of the strays // It only works on a bunch of intersected line segments List <CurveArray> loops = RegionDetect.RegionCluster(strays); // The boolean union method of the loops needs to fix var perimeter = RegionDetect.GetBoundary(loops); var recPerimeter = CloseGapAtBreakpoint(perimeter); var arrayPerimeter = RegionDetect.AlignCrv(recPerimeter); for (int i = 0; i < arrayPerimeter.Size; i++) { Debug.Print("Line-{0} {1} {2}", i, Misc.PointString(arrayPerimeter.get_Item(i).GetEndPoint(0)), Misc.PointString(arrayPerimeter.get_Item(i).GetEndPoint(1))); } #endregion // OUTPUT List<CurveArray> loops Debug.Print("REGION COMPLETE!"); // Get the linestyle of "long-dashed" FilteredElementCollector fec = new FilteredElementCollector(doc) .OfClass(typeof(LinePatternElement)); LinePatternElement linePatternElem = fec.FirstElement() as LinePatternElement; // Main visualization process using (Transaction tx = new Transaction(doc)) { tx.Start("Generate Floor"); // Draw wall patch lines /* * foreach (Curve patchLine in patchLines) * { * DetailLine axis = doc.Create.NewDetailCurve(view, patchLine) as DetailLine; * GraphicsStyle gs = axis.LineStyle as GraphicsStyle; * gs.GraphicsStyleCategory.LineColor = new Color(202, 51, 82); * gs.GraphicsStyleCategory.SetLineWeight(3, gs.GraphicsStyleType); * } */ Plane Geomplane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero); SketchPlane sketch = SketchPlane.Create(doc, Geomplane); /* * // Draw bounding boxes * foreach (List<Curve> wallBlock in wallBlocks) * { * foreach (Curve edge in wallBlock) * { * DetailLine axis = doc.Create.NewDetailCurve(view, edge) as DetailLine; * GraphicsStyle gs = axis.LineStyle as GraphicsStyle; * gs.GraphicsStyleCategory.LineColor = new Color(210, 208, 185); * gs.GraphicsStyleCategory.SetLineWeight(1, gs.GraphicsStyleType); * gs.GraphicsStyleCategory.SetLinePatternId(linePatternElem.Id, gs.GraphicsStyleType); * } * } */ /* * // Draw Axes * Debug.Print("Axes all together: " + strays.Count.ToString()); * foreach (Line centerLine in strays) * { * ModelCurve modelline = doc.Create.NewModelCurve(centerLine, sketch) as ModelCurve; * } */ // Draw Regions foreach (CurveArray loop in loops) { foreach (Curve edge in loop) { ModelCurve modelline = doc.Create.NewModelCurve(edge, sketch) as ModelCurve; } } foreach (Curve edge in arrayPerimeter) { 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(8, gs.GraphicsStyleType); } tx.Commit(); } return(Result.Succeeded); }
public ViewsCEPRRequest(UIApplication uiApp, String text) { MainUI uiForm = BARevitTools.Application.thisApp.newMainUi; UIDocument uidoc = uiApp.ActiveUIDocument; //Collect the ViewTypes in the project FilteredElementCollector viewTypesCollector = new FilteredElementCollector(uidoc.Document); ICollection <Element> viewTypes = viewTypesCollector.OfClass(typeof(ViewFamilyType)).ToElements(); ElementId viewTypeId = null; //Cycle through the ViewType elements to find the one with a type name equal to the one selected in the MainUI's combobox foreach (ViewFamilyType viewType in viewTypes) { if (viewType.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString() == uiForm.viewsCEPRElevationComboBox.Text) { viewTypeId = viewType.Id; } } //If the ViewType was found, and the active view is a plan view, continue if (viewTypeId != null && uidoc.ActiveView.GetType().ToString() == "Autodesk.Revit.DB.ViewPlan") { //Invoke a room selection List <Room> selectedRoomElements = RVTOperations.SelectRoomElements(uiApp); //If the user selected rooms, continue if (selectedRoomElements != null) { try { //Cycle through each selected room foreach (Room room in selectedRoomElements) { //First, get the room number for use in generating the elevation view names string roomNumber = room.Number; string roomName = room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString().ToUpper(); //Get the geometry of the room Options geomOptions = new Options(); geomOptions.IncludeNonVisibleObjects = true; GeometryElement geomElements = room.get_Geometry(geomOptions); //Get the location point of the room as a point for where to place the elevation marker LocationPoint roomLocation = room.Location as LocationPoint; XYZ point = roomLocation.Point; //Start a transaction Transaction t1 = new Transaction(uidoc.Document, "Create Elevations Per Room"); t1.Start(); try { //Make a new ElevationMarker that uses the ViewType earlier, the location point of the room, and has a view scale of 1/8" ElevationMarker newMarker = ElevationMarker.CreateElevationMarker(uidoc.Document, viewTypeId, point, 96); //Start making views going around the elevation marker where the indexes start on the west side and go clockwise ViewSection view0 = newMarker.CreateElevation(uidoc.Document, uidoc.ActiveView.Id, 0); //Set the view name equal to the room number + room name + plus orientation view0.Name = roomNumber + " " + roomName + " WEST"; view0.CropBoxActive = true; //Repeat for the other view directions at their appropriate index ViewSection view1 = newMarker.CreateElevation(uidoc.Document, uidoc.ActiveView.Id, 1); view1.Name = roomNumber + " " + roomName + " NORTH"; view1.CropBoxActive = true; ViewSection view2 = newMarker.CreateElevation(uidoc.Document, uidoc.ActiveView.Id, 2); view2.Name = roomNumber + " " + roomName + " EAST"; view2.CropBoxActive = true; ViewSection view3 = newMarker.CreateElevation(uidoc.Document, uidoc.ActiveView.Id, 3); view3.Name = roomNumber + " " + roomName + " SOUTH"; view3.CropBoxActive = true; //Make a Solid object for assignment Solid roomSolid = null; //The following section is dedicated to cropping the elevation views to the cross-section of the room geometry if (uiForm.viewsCEPRCropCheckBox.Checked == true) { //Cycle through the geometry elements associated with the room geometry until the solid is found foreach (GeometryObject geom in geomElements) { if (geom.GetType().ToString() == "Autodesk.Revit.DB.Solid") { roomSolid = geom as Solid; break; } } //Generate 4 planes at the room point that will correspond to each elevation view's cross section of the room geometry // Each plane's normal vector is in the direction their view is facing Plane westPlane = Plane.CreateByNormalAndOrigin(new XYZ(-1, 0, 0), point); //-X vector for West Plane northPlane = Plane.CreateByNormalAndOrigin(new XYZ(0, 1, 0), point); //+Y vector for North Plane eastPlane = Plane.CreateByNormalAndOrigin(new XYZ(1, 0, 0), point); //+X vector for East Plane southPlane = Plane.CreateByNormalAndOrigin(new XYZ(0, -1, 0), point); //-Y vector for South //Use the room section's perimeter as the crop boundary if the first index of the MainUI combobox is selected if (uiForm.viewsCEPRCropMethodComboBox.SelectedIndex == 0) { try { //Generate some CurveLoop lists for use later IList <CurveLoop> westCurveLoopsFitted = null; IList <CurveLoop> northCurveLoopsFitted = null; IList <CurveLoop> southCurveLoopsFitted = null; IList <CurveLoop> eastCurveLoopsFitted = null; //Slice the room solid with the westPlane object made earlier. This will result in a solid boolean result to the west of the plane because the positive side of the plane faces west Solid westBooleanSolid = BooleanOperationsUtils.CutWithHalfSpace(roomSolid, westPlane); //Grab the faces of the solid that resulted from the boolean FaceArray westBoolSolidFaces = westBooleanSolid.Faces; //Cycle through each face and get the normal vector foreach (PlanarFace westFace in westBoolSolidFaces) { //For the west elevation face to use as the crop boundary, we need the face that has a vector going east, or the +X vector XYZ westFaceNormal = westFace.FaceNormal; if (westFaceNormal.X == 1) { //Get the edges as a CurveLoops once the face is found, then jump out of the loop thorugh the faces westCurveLoopsFitted = westFace.GetEdgesAsCurveLoops(); break; } } //Repeat for the north elevation Solid northBooleanSolid = BooleanOperationsUtils.CutWithHalfSpace(roomSolid, northPlane); FaceArray northBoolSolidFaces = northBooleanSolid.Faces; foreach (PlanarFace northFace in northBoolSolidFaces) { XYZ northFaceNormal = northFace.FaceNormal; if (northFaceNormal.Y == -1) { northCurveLoopsFitted = northFace.GetEdgesAsCurveLoops(); break; } } //Repeat for the east elevation Solid eastBooleanSolid = BooleanOperationsUtils.CutWithHalfSpace(roomSolid, eastPlane); FaceArray eastBoolSolidFaces = eastBooleanSolid.Faces; foreach (PlanarFace eastFace in eastBoolSolidFaces) { XYZ eastFaceNormal = eastFace.FaceNormal; if (eastFaceNormal.X == -1) { eastCurveLoopsFitted = eastFace.GetEdgesAsCurveLoops(); break; } } //Repeat for the south elevation Solid southBooleanSolid = BooleanOperationsUtils.CutWithHalfSpace(roomSolid, southPlane); FaceArray southBoolSolidFaces = southBooleanSolid.Faces; foreach (PlanarFace southFace in southBoolSolidFaces) { XYZ southFaceNormal = southFace.FaceNormal; if (southFaceNormal.Y == 1) { southCurveLoopsFitted = southFace.GetEdgesAsCurveLoops(); break; } } //To get the CurveLoop fitted 0.5" offset to the boundary of the face retrieved, create a CurveLoop via an offset //Now, the original curve loop was drawn on a plane with a +X axis vector normal, so the offset must be made in the positive X axis plane as well CurveLoop offsetWestCurveLoopFitted = CurveLoop.CreateViaOffset(westCurveLoopsFitted[0], (0.5d / 12), XYZ.BasisX); ViewCropRegionShapeManager westCropRegionShapeManager = view0.GetCropRegionShapeManager(); westCropRegionShapeManager.SetCropShape(offsetWestCurveLoopFitted); //Repeat for the north CurveLoop //Note that because the plane has a -Y vector, the offset needs to be negative too CurveLoop offsetNorthCurveLoopFitted = CurveLoop.CreateViaOffset(northCurveLoopsFitted[0], -(0.5d / 12), XYZ.BasisY);; ViewCropRegionShapeManager northCropRegionShapeManager = view1.GetCropRegionShapeManager(); northCropRegionShapeManager.SetCropShape(offsetNorthCurveLoopFitted); //Repeat for the east CurveLoop CurveLoop offsetEastCurveLoopFitted = CurveLoop.CreateViaOffset(eastCurveLoopsFitted[0], -(0.5d / 12), XYZ.BasisX);; ViewCropRegionShapeManager eastCropRegionShapeManager = view2.GetCropRegionShapeManager(); eastCropRegionShapeManager.SetCropShape(offsetEastCurveLoopFitted); //Repeat for the south CurveLoop CurveLoop offsetSouthCurveLoopFitted = CurveLoop.CreateViaOffset(southCurveLoopsFitted[0], (0.5d / 12), XYZ.BasisY);; ViewCropRegionShapeManager southCropRegionShapeManager = view3.GetCropRegionShapeManager(); southCropRegionShapeManager.SetCropShape(offsetSouthCurveLoopFitted); } catch (Exception e) { MessageBox.Show(e.ToString()); } } //Use the room section's rectangular extents as the crop boundary if the second index was selected for the MainUI combobox if (uiForm.viewsCEPRCropMethodComboBox.SelectedIndex == 1) { try { //Create some CurveLoop lists to use later IList <CurveLoop> westCurveLoopsRectangular = null; IList <CurveLoop> northCurveLoopsRectangular = null; IList <CurveLoop> southCurveLoopsRectangular = null; IList <CurveLoop> eastCurveLoopsRectangular = null; //To get a rectangular cross section of a non-rectangular room cross section, we need to generate a bounding box for the room, then make a solid from the bounding box //Get the bounding box of the room BoundingBoxXYZ roomBBox = roomSolid.GetBoundingBox(); //Use the minimum and maximum points of the bounding box to get the 4 points along the bottom of the bounding box XYZ pt0 = new XYZ(roomBBox.Min.X, roomBBox.Min.Y, roomBBox.Min.Z); XYZ pt1 = new XYZ(roomBBox.Max.X, roomBBox.Min.Y, roomBBox.Min.Z); XYZ pt2 = new XYZ(roomBBox.Max.X, roomBBox.Max.Y, roomBBox.Min.Z); XYZ pt3 = new XYZ(roomBBox.Min.X, roomBBox.Max.Y, roomBBox.Min.Z); //Generate perimeter lines for the bottom of the bounding box points Line edge0 = Line.CreateBound(pt0, pt1); Line edge1 = Line.CreateBound(pt1, pt2); Line edge2 = Line.CreateBound(pt2, pt3); Line edge3 = Line.CreateBound(pt3, pt0); //Make a list of curves out of the edges List <Curve> edges = new List <Curve>(); edges.Add(edge0); edges.Add(edge1); edges.Add(edge2); edges.Add(edge3); //Use the curves to make a CurveLoop list List <CurveLoop> loops = new List <CurveLoop>(); loops.Add(CurveLoop.Create(edges)); //Generate a solid from an extrusion that uses the CurveLoops extruded upward a height equal to the the height of the bounding box Solid initialSolidBBox = GeometryCreationUtilities.CreateExtrusionGeometry(loops, XYZ.BasisZ, (roomBBox.Max.Z - roomBBox.Min.Z)); //Create a transformed solid box from the previously created box moved to where the room bounding box is located Solid roomSolidBBox = SolidUtils.CreateTransformed(initialSolidBBox, roomBBox.Transform); //Cut the solid box with the west plane created earlier and get the faces Solid westBooleanSolidBBox = BooleanOperationsUtils.CutWithHalfSpace(roomSolidBBox, westPlane); FaceArray westBoolSolidFacesBBox = westBooleanSolidBBox.Faces; foreach (PlanarFace westFace in westBoolSolidFacesBBox) { //As with the earlier code for a fitted crop, get the face with a positive X normal XYZ westFaceNormal = westFace.FaceNormal; if (westFaceNormal.X == 1) { //Obtain the edges of the face westCurveLoopsRectangular = westFace.GetEdgesAsCurveLoops(); break; } } //Repeat for the north face Solid northBooleanSolidBBox = BooleanOperationsUtils.CutWithHalfSpace(roomSolidBBox, northPlane); FaceArray northBoolSolidFacesBBox = northBooleanSolidBBox.Faces; foreach (PlanarFace northFace in northBoolSolidFacesBBox) { XYZ northFaceNormal = northFace.FaceNormal; if (northFaceNormal.Y == -1) { northCurveLoopsRectangular = northFace.GetEdgesAsCurveLoops(); break; } } //Repeat for the east face Solid eastBooleanSolidBBox = BooleanOperationsUtils.CutWithHalfSpace(roomSolidBBox, eastPlane); FaceArray eastBoolSolidFacesBBox = eastBooleanSolidBBox.Faces; foreach (PlanarFace eastFace in eastBoolSolidFacesBBox) { XYZ eastFaceNormal = eastFace.FaceNormal; if (eastFaceNormal.X == -1) { eastCurveLoopsRectangular = eastFace.GetEdgesAsCurveLoops(); break; } } //Repeat for the south face Solid southBooleanSolidBBox = BooleanOperationsUtils.CutWithHalfSpace(roomSolidBBox, southPlane); FaceArray southBoolSolidFacesBBox = southBooleanSolidBBox.Faces; foreach (PlanarFace southFace in southBoolSolidFacesBBox) { XYZ southFaceNormal = southFace.FaceNormal; if (southFaceNormal.Y == 1) { southCurveLoopsRectangular = southFace.GetEdgesAsCurveLoops(); break; } } //As before, get the offset curve from the original curve, but offset by 1' CurveLoop offsetWestCurveLoopRectangular = CurveLoop.CreateViaOffset(westCurveLoopsRectangular[0], 1, XYZ.BasisX); ViewCropRegionShapeManager westCropRegionShapeManager = view0.GetCropRegionShapeManager(); westCropRegionShapeManager.SetCropShape(offsetWestCurveLoopRectangular); //As with the fitted offset curve, the offset for a curve in a plane with a negative vector must also be negative CurveLoop offsetNorthCurveLoopRectangular = CurveLoop.CreateViaOffset(northCurveLoopsRectangular[0], -1, XYZ.BasisY); ViewCropRegionShapeManager northCropRegionShapeManager = view1.GetCropRegionShapeManager(); northCropRegionShapeManager.SetCropShape(offsetNorthCurveLoopRectangular); CurveLoop offsetEastCurveLoopRectangular = CurveLoop.CreateViaOffset(eastCurveLoopsRectangular[0], -1, XYZ.BasisX); ViewCropRegionShapeManager eastCropRegionShapeManager = view2.GetCropRegionShapeManager(); eastCropRegionShapeManager.SetCropShape(offsetEastCurveLoopRectangular); CurveLoop offsetSouthCurveLoopRectangular = CurveLoop.CreateViaOffset(southCurveLoopsRectangular[0], 1, XYZ.BasisY); ViewCropRegionShapeManager southCropRegionShapeManager = view3.GetCropRegionShapeManager(); southCropRegionShapeManager.SetCropShape(offsetSouthCurveLoopRectangular); } catch (Exception e) { MessageBox.Show(e.ToString()); } } //If the user opted to override the crop boundary of the elevations, continue as follows if (uiForm.viewsCEPROverrideCheckBox.Checked == true) { //Make a new OverrideGraphicsSetting to use in the boundary override OverrideGraphicSettings orgs = new OverrideGraphicSettings(); //Use the solid line pattern orgs.SetProjectionLinePatternId(LinePatternElement.GetSolidPatternId()); //Set the line weight to the properties value orgs.SetProjectionLineWeight(Properties.Settings.Default.RevitOverrideInteriorCropWeight); //Grab all of the viewers, which are the viewport windows, and cycle through them var viewers = new FilteredElementCollector(uidoc.Document).OfCategory(BuiltInCategory.OST_Viewers); foreach (Element viewer in viewers) { //Get the parameters for the viewer ParameterSet parameters = viewer.Parameters; foreach (Parameter parameter in parameters) { //Get the View Name parameter if (parameter.Definition.Name.ToString() == "View Name") { string viewName = parameter.AsString(); //If the view's view name is the same as the west elvation, continue if (viewName == view0.Name) { //Set the view's override setting using the viewer and the OverrideGraphicsSettings Autodesk.Revit.DB.View viewtouse = view0 as Autodesk.Revit.DB.View; viewtouse.SetElementOverrides(viewer.Id, orgs); } //Continue to evaluate for the other view names else if (viewName == view1.Name) { Autodesk.Revit.DB.View viewtouse = view1 as Autodesk.Revit.DB.View; viewtouse.SetElementOverrides(viewer.Id, orgs); } else if (viewName == view2.Name) { Autodesk.Revit.DB.View viewtouse = view2 as Autodesk.Revit.DB.View; viewtouse.SetElementOverrides(viewer.Id, orgs); } else if (viewName == view3.Name) { Autodesk.Revit.DB.View viewtouse = view3 as Autodesk.Revit.DB.View; viewtouse.SetElementOverrides(viewer.Id, orgs); } else { //If the view's name is not one of the create elevation views, skip it continue; } } } } } } t1.Commit(); } catch (Exception e) { MessageBox.Show(e.ToString()); t1.RollBack(); } t1.Dispose(); } } catch { //If the user did not select any room tags or room elements, then report that MessageBox.Show("No rooms were selected"); } } } else if (uidoc.ActiveView.GetType().ToString() != "Autodesk.Revit.DB.ViewPlan") { //If the user tried to run this outside a plan view, report it MessageBox.Show("Please run from a plan view"); } else { //If the user did not select an elevation type, report it MessageBox.Show("No elevation type selected"); } }
public MaterialsAMLRequest(UIApplication uiApp, String text) { DataGridView dgv = BARevitTools.Application.thisApp.newMainUi.materialsAMLDataGridView; RVTDocument doc = uiApp.ActiveUIDocument.Document; //Get all of the line styles in the project and assign them to a dictionary indexed by line style name Dictionary <string, Category> lineStyleDict = new Dictionary <string, Category>(); foreach (Category lineStyle in RVTGetElementsByCollection.DocumentLineStyles(uiApp)) { lineStyleDict.Add(lineStyle.Name.Replace("ID ", ""), lineStyle); } //All new line styles will use the solid line pattern, so get that from the project ElementId solidPatternId = LinePatternElement.GetSolidPatternId(); //Start the transaction to create the line styles Transaction t1 = new Transaction(doc, "CreateLineStyles"); t1.Start(); //Cycle through the rows of line styles in the MainUI form foreach (DataGridViewRow row in dgv.Rows) { //Get the color of the button in the row and convert it to a Revit color System.Drawing.Color buttonColor = row.Cells["Color"].Style.BackColor; Color revitColor = new Color(buttonColor.R, buttonColor.G, buttonColor.B); //If the Updated column cell is not null, continue if (row.Cells["Updated"].Value != null) { //Assuming the user made a modification to the color for an existing line style and the Mark is part of the dictionary keys... if (row.Cells["Updated"].Value.ToString() == "True" && lineStyleDict.Keys.Contains(row.Cells["Mark"].Value.ToString())) { try { //Get the line style by key name in the dictionary and update its line color to the one from the button Category lineStyleToUpdate = lineStyleDict[row.Cells["Mark"].Value.ToString()]; lineStyleToUpdate.LineColor = revitColor; } catch (Exception e) { MessageBox.Show(e.ToString()); } } } //If the Select column cell is not null, continue if (row.Cells["Select"].Value != null) { //Assuming the user checked the box in the Select column, Mark is not emtpy, and the dictionary of line styles does not already contain a line style with the same mark name... if (row.Cells["Select"].Value.ToString() == "True" && row.Cells["Mark"].Value.ToString() != "" && !lineStyleDict.Keys.Contains(row.Cells["Mark"].Value.ToString())) { try { //Get the category for Lines Category linesCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines); //Make a new line style subcategory with the name of the mark value from the Mark column cell, prefixed with ID so it is easier to find during the sort Category newLineStyleCategory = doc.Settings.Categories.NewSubcategory(linesCategory, "ID " + row.Cells["Mark"].Value.ToString()); //Set the line style's color, projection weight, and solid line pattern newLineStyleCategory.LineColor = revitColor; newLineStyleCategory.SetLineWeight(6, GraphicsStyleType.Projection); newLineStyleCategory.SetLinePatternId(solidPatternId, GraphicsStyleType.Projection); //Regenerate the document doc.Regenerate(); } catch (Exception e) { MessageBox.Show(e.ToString()); } } } } t1.Commit(); //Update the DataGridView of the MainUI with the changes and new line styles BARevitTools.Application.thisApp.newMainUi.MaterialsAMLUpdateDGV(dgv); //Make another line style dictionary with the line styles indexed by name (mark) Dictionary <string, Category> newlineStyleDict = new Dictionary <string, Category>(); foreach (Category lineStyle in RVTGetElementsByCollection.DocumentLineStyles(uiApp)) { newlineStyleDict.Add(lineStyle.Name.Replace("ID ", ""), lineStyle); } //Add a default line style to the palette's combo box, then add the checked line styles to a list in alphabetical order SortedList <string, string> materialsToUseList = new SortedList <string, string>(); BARevitTools.Application.thisApp.newMainUi.materialsAMLPalette.paletteMaterialComboBox.Items.Add("Default"); foreach (DataGridViewRow row in dgv.Rows) { if (newlineStyleDict.Keys.Contains(row.Cells["Mark"].Value.ToString()) && row.Cells["Select"].Value.ToString() == "True") { materialsToUseList.Add(row.Cells["Mark"].Value.ToString(), row.Cells["Mark"].Value.ToString()); } } //Assuming there were checked linestyles to add to the palette's combo box, add them to the combo box if (materialsToUseList.Count != 0) { foreach (string item in materialsToUseList.Keys) { BARevitTools.Application.thisApp.newMainUi.materialsAMLPalette.paletteMaterialComboBox.Items.Add(item); } } else { //If there were no additional line styles to add to the combo box, disable it and set it to Default BARevitTools.Application.thisApp.newMainUi.materialsAMLPalette.paletteMaterialComboBox.Text = "Default"; BARevitTools.Application.thisApp.newMainUi.materialsAMLPalette.paletteMaterialComboBox.Enabled = false; } //Show the palette and continue doing requests for the Accent Material Lines tool from there. BARevitTools.Application.thisApp.newMainUi.materialsAMLPalette.Show(); }
private void setStyleCropBoxFromView(UIDocument uiDoc, View myView) { //Set current Document Document doc = uiDoc.Document; // Create A Collection of ElementID (get all ElementId on a View) ICollection <ElementId> myListElemId1 = null; //Start a transaction to hide cropbox of view using (Transaction trans1 = new Transaction(doc, "Hide the cropbox of a myView")) { trans1.Start(); myView.CropBoxVisible = false; trans1.Commit(); } // Set myListElemId1( Without cropBox's elementId) myListElemId1 = new FilteredElementCollector(doc, myView.Id).ToElementIds(); // Start another transaction to unhide (active) cropBox using (Transaction trans2 = new Transaction(doc, "unHide CropBox")) { trans2.Start(); myView.CropBoxVisible = true; trans2.Commit(); } // the CropBox ElementId is firts item in list ElementId convert from FilteredElementCollector ElementId myCropBoxId = new FilteredElementCollector(doc, myView.Id). Excluding(myListElemId1). ToElementIds().First(); // TaskDialog.Show("Abc", "cropbOx Id: " + myCropBoxId.ToString()); //Create a graphic Overide for Element (OverrideGraphicSettings) OverrideGraphicSettings ogsCropBox = new OverrideGraphicSettings(); // Color ogsCropBox.SetProjectionLineColor(new Color(255, 0, 0)); //Line Weight ogsCropBox.SetProjectionLineWeight(5); //Pattern FilteredElementCollector fec = new FilteredElementCollector(doc).OfClass(typeof(LinePatternElement)); LinePatternElement linePatternElem = fec. Cast <LinePatternElement>(). First <LinePatternElement>(linePattern => linePattern.Name == "Dash"); ElementId myLinePatId = linePatternElem.Id; ogsCropBox.SetProjectionLinePatternId(myLinePatId); // Set ElementOverride (Style Line) using (Transaction trans3 = new Transaction(doc, "Change Style of CropBox")) { trans3.Start(); myView.CropBoxVisible = true; myView.SetElementOverrides(myCropBoxId, ogsCropBox); trans3.Commit(); } }
public void GetByName_ValidArgs() { var linePattern = LinePatternElement.GetByName("Dash"); Assert.NotNull(linePattern); }
public void GetByName_NullArgs() { Assert.Throws(typeof(ArgumentException), () => LinePatternElement.GetByName(null)); }
/// <summary> /// Create a OverrideGraphicSettings element /// </summary> /// <param name="cutFillColor">Fill color</param> /// <param name="projectionFillColor">Projection color</param> /// <param name="cutLineColor">Cut line color</param> /// <param name="projectionLineColor">Projection line color</param> /// <param name="cutLineWeight">Cut line weight</param> /// <param name="projectionLineWeight">Projection line weight</param> /// <param name="cutFillPattern">Cut fill pattern</param> /// <param name="projectionFillPattern">Projection fill pattern</param> /// <param name="cutLinePattern">Cut line pattern</param> /// <param name="projectionLinePattern">Projection line pattern</param> /// <returns>OverrideGraphicSettings</returns> public static OverrideGraphicSettings ByProperties( [DefaultArgumentAttribute("null")] DSCore.Color cutFillColor, [DefaultArgumentAttribute("null")] DSCore.Color projectionFillColor, [DefaultArgumentAttribute("null")] DSCore.Color cutLineColor, [DefaultArgumentAttribute("null")] DSCore.Color projectionLineColor, [DefaultArgumentAttribute("null")] FillPatternElement cutFillPattern, [DefaultArgumentAttribute("null")] FillPatternElement projectionFillPattern, [DefaultArgumentAttribute("null")] LinePatternElement cutLinePattern, [DefaultArgumentAttribute("null")] LinePatternElement projectionLinePattern, int cutLineWeight = -1, int projectionLineWeight = -1 ) { Autodesk.Revit.DB.OverrideGraphicSettings filterSettings = new Autodesk.Revit.DB.OverrideGraphicSettings(); // Apply Colors if (cutFillColor != null) { filterSettings.SetCutFillColor(ToRevitColor(cutFillColor)); } if (projectionFillColor != null) { filterSettings.SetProjectionFillColor(ToRevitColor(projectionFillColor)); } if (cutLineColor != null) { filterSettings.SetCutLineColor(ToRevitColor(cutLineColor)); } if (projectionLineColor != null) { filterSettings.SetProjectionLineColor(ToRevitColor(projectionLineColor)); } // Apply Lineweight if (cutLineWeight != -1) { filterSettings.SetCutLineWeight(cutLineWeight); } if (projectionLineWeight != -1) { filterSettings.SetProjectionLineWeight(projectionLineWeight); } // Apply Patterns if (cutFillPattern != null) { filterSettings.SetCutFillPatternId(cutFillPattern.Id); } if (projectionFillPattern != null) { filterSettings.SetProjectionFillPatternId(projectionFillPattern.Id); } if (cutLinePattern != null) { filterSettings.SetCutLinePatternId(cutLinePattern.Id); } if (projectionLinePattern != null) { filterSettings.SetProjectionLinePatternId(projectionLinePattern.Id); } return(new OverrideGraphicSettings(filterSettings)); }
public MaterialsAMLPaletteRequest(UIApplication uiApp, String text) { RVTDocument doc = uiApp.ActiveUIDocument.Document; MaterialsAMLPalette materialsPalette = BARevitTools.Application.thisApp.newMainUi.materialsAMLPalette; //Get the versioned symbol family FamilySymbol familySymbol = null; string versionedFamily = RVTOperations.GetVersionedFamilyFilePath(uiApp, Properties.Settings.Default.RevitIDAccentMatTag); //Try loading the family symbol Transaction loadSymbolTransaction = new Transaction(doc, "LoadFamilySymbol"); loadSymbolTransaction.Start(); try { try { IFamilyLoadOptions loadOptions = new RVTFamilyLoadOptions(); doc.LoadFamilySymbol(versionedFamily, "Legend Tag (Fake)", loadOptions, out FamilySymbol symb); familySymbol = symb; } catch { MessageBox.Show(String.Format("Could not get the 'Legend Tag (Fake)' type from {0}", versionedFamily), "Family Symbol Load Error"); } loadSymbolTransaction.Commit(); } catch (Exception transactionException) { loadSymbolTransaction.RollBack(); MessageBox.Show(transactionException.ToString()); } //Get the line style to use, or create the default Element lineStyle = null; if (materialsPalette.paletteMaterialComboBox.Text == "Default") { try { lineStyle = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines).SubCategories.get_Item("6 BA ID ACCENT").GetGraphicsStyle(GraphicsStyleType.Projection); } catch { try { Category linesCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines); Category newLineStyleCategory = doc.Settings.Categories.NewSubcategory(linesCategory, "6 BA ID ACCENT"); newLineStyleCategory.LineColor = new Color(0, 0, 0); newLineStyleCategory.SetLineWeight(6, GraphicsStyleType.Projection); newLineStyleCategory.SetLinePatternId(LinePatternElement.GetSolidPatternId(), GraphicsStyleType.Projection); doc.Regenerate(); lineStyle = newLineStyleCategory.GetGraphicsStyle(GraphicsStyleType.Projection); } catch (Exception e) { MessageBox.Show(e.ToString()); } } } else { lineStyle = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines).SubCategories.get_Item("ID " + materialsPalette.paletteMaterialComboBox.Text).GetGraphicsStyle(GraphicsStyleType.Projection); } //Assure the view being used is a floor plan if (doc.ActiveView.ViewType != ViewType.FloorPlan) { MessageBox.Show("This tool should be used ina a Floor Plan or Area Plan view"); } else { //Create a loop for picking points. Change the palette background color based on the number of points picked List <XYZ> pickedPoints = new List <XYZ>(); bool breakLoop = false; int pickCount = 0; while (breakLoop == false) { try { //Have the user begin picking points. The number of clicks to start the UI color change is 1 because the first click is usually to activate the window. XYZ point = uiApp.ActiveUIDocument.Selection.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.Endpoints, "Click points for the line to follow. Then click once to the side where the lines should be drawn. Hit ESC to finish"); pickedPoints.Add(point); if (pickCount == 1) { materialsPalette.BackColor = System.Drawing.Color.Firebrick; } else if (pickCount == 2) { materialsPalette.BackColor = System.Drawing.Color.Orange; } else if (pickCount > 2) { //After three clicks in the window, the user has made the minimum point selection to generate the lines from the start, end, and positive side points. materialsPalette.BackColor = System.Drawing.Color.GreenYellow; } else { ; } pickCount++; } catch { materialsPalette.BackColor = MaterialsAMLPalette.DefaultBackColor; breakLoop = true; } } //Get rid of the first point from clicking into the Revit view. This point is not needed. pickedPoints.RemoveAt(0); if (pickedPoints.Count > 2) { Transaction createLinesTransaction = new Transaction(doc, "CreateAccentLines"); createLinesTransaction.Start(); try { //These points will be used in determining the start, end, and room points XYZ firstPoint = pickedPoints[0]; XYZ roomPoint = pickedPoints[pickedPoints.Count - 1]; XYZ lastPoint = pickedPoints[pickedPoints.Count - 2]; //Create a list of points for the polyline that excludes the room point List <XYZ> polyLinePoints = new List <XYZ>(); for (int i = 0; i < pickedPoints.Count - 1; i++) { polyLinePoints.Add(pickedPoints[i]); } //Create a polyline from the list of picked points and then get make lines from the points on the poly line PolyLine guidePolyLine = PolyLine.Create(polyLinePoints); IList <XYZ> polyPoints = guidePolyLine.GetCoordinates(); List <Line> guideLines = new List <Line>(); for (int i = 0; i < polyLinePoints.Count - 1; i++) { guideLines.Add(Line.CreateBound(polyLinePoints[i], polyLinePoints[i + 1])); } //Get the direction of the line offset by measuring the first offset for positive and negative values and comparing their distances with the room point bool positiveZ = false; List <Line> offsetLines = new List <Line>(); Line positiveOffsetLine = guideLines.Last().CreateOffset(0.6666666667d, XYZ.BasisZ) as Line; Line negativeOffsetLine = guideLines.Last().CreateOffset(-0.6666666667d, XYZ.BasisZ) as Line; XYZ positiveOffsetMidPoint = positiveOffsetLine.Evaluate(0.5d, true); XYZ negativeOffsetMidPoint = negativeOffsetLine.Evaluate(0.5d, true); Double positiveOffsetDistance = positiveOffsetMidPoint.DistanceTo(roomPoint); Double negativeOffsetDistance = negativeOffsetMidPoint.DistanceTo(roomPoint); //If the positive offset side resulted in a shorter distance to the point inside the room, then the offset should have a positive Z normal. if (positiveOffsetDistance < negativeOffsetDistance) { positiveZ = true; } //Knowing whether or not to use a positive or negative offset, begin creating offset lines for each guide line foreach (Line guideLine in guideLines) { if (positiveZ) { offsetLines.Add(guideLine.CreateOffset(0.6666666667d, XYZ.BasisZ) as Line); } else { offsetLines.Add(guideLine.CreateOffset(-0.6666666667d, XYZ.BasisZ) as Line); } } //Determine if the number of line segments is 1 or more Line firstLine = offsetLines.First(); Line lastLine = null; if (offsetLines.Count > 1) { lastLine = offsetLines.Last(); } //If there is only one line segment, both end operations must be performed on it if (lastLine == null) { double lineLength = firstLine.Length; double fractionOfLength = 0.6666666667d / lineLength; //Checking fractions to ensure they are not greater than 1 for the normalization if (fractionOfLength > 1) { fractionOfLength = 0.25d; } //Re-evaluating where to place the start and end point of the line XYZ shiftedStartPoint = firstLine.Evaluate(fractionOfLength, true); XYZ shiftedEndPoint = firstLine.Evaluate(1 - fractionOfLength, true); firstLine = Line.CreateBound(shiftedStartPoint, shiftedEndPoint); //Creating the angled corner lines Line firstCornerLine = Line.CreateBound(firstPoint, firstLine.GetEndPoint(0)); Line lastCornerLine = Line.CreateBound(lastPoint, firstLine.GetEndPoint(1)); //Create the detail lines from the lines DetailCurve newAccentLine1 = doc.Create.NewDetailCurve(doc.ActiveView, firstCornerLine); DetailCurve newAccentLine2 = doc.Create.NewDetailCurve(doc.ActiveView, firstLine); DetailCurve newAccentLine3 = doc.Create.NewDetailCurve(doc.ActiveView, lastCornerLine); //Assign a line style to the newly created detail lines newAccentLine1.LineStyle = lineStyle; newAccentLine2.LineStyle = lineStyle; newAccentLine3.LineStyle = lineStyle; XYZ tagPlacementPoint = firstLine.Evaluate(0.5d, true); XYZ direction = firstLine.Direction; Line axisLine = Line.CreateUnbound(tagPlacementPoint, XYZ.BasisZ); double rotationAngle = direction.AngleTo(XYZ.BasisX); //Get the midpoint of the line, its direction, and create the rotation and axis if (familySymbol != null) { //Create the tag instance FamilyInstance newTag = doc.Create.NewFamilyInstance(tagPlacementPoint, familySymbol, doc.ActiveView); //Rotate the new tag instance ElementTransformUtils.RotateElement(doc, newTag.Id, axisLine, rotationAngle); } createLinesTransaction.Commit(); } //If there is more than one line segment, an operation must be performed on the start and end of the start and end lines, respectively else { List <Line> linesToDraw = new List <Line>(); // Get the normalized value for 8" relative to the lengths of the start and end lines double firstLineLength = firstLine.Length; double fractionOfFirstLine = 0.6666666667 / firstLineLength; double lastLineLength = lastLine.Length; double fractionOfLastLine = 0.666666667 / lastLineLength; //Checking fractions to ensure they are not greater than 1 for the normalization if (fractionOfFirstLine > 1) { fractionOfFirstLine = 0.25d; } if (fractionOfLastLine > 1) { fractionOfLastLine = 0.25d; } //Shift the ends of the start and end lines by finding the point along the line relative to the normalized 8" value XYZ shiftedStartPoint = firstLine.Evaluate(fractionOfFirstLine, true); XYZ shiftedEndPoint = lastLine.Evaluate(1 - fractionOfLastLine, true); //Reset the start and end lines with the new shifted points firstLine = Line.CreateBound(shiftedStartPoint, firstLine.GetEndPoint(1)); lastLine = Line.CreateBound(lastLine.GetEndPoint(0), shiftedEndPoint); linesToDraw.Add(firstLine); //If there are only 3 offset lines, there will be just one middle segment if (offsetLines.Count == 3) { linesToDraw.Add(offsetLines[1]); } //If there are more than three offset lines, there will be more than one middle line segment else { List <Line> middleLines = offsetLines.GetRange(1, offsetLines.Count - 2); foreach (Line middleLine in middleLines) { linesToDraw.Add(middleLine); } } linesToDraw.Add(lastLine); //For the lines to draw, intersect them with the next line in the list and reset their start and end points to be the intersection for (int i = 0; i < linesToDraw.Count - 1; i++) { Line line1 = linesToDraw[i]; Line scaledLine1 = Line.CreateUnbound(line1.GetEndPoint(1), line1.Direction); Line line2 = linesToDraw[i + 1]; Line scaledLine2 = Line.CreateUnbound(line2.GetEndPoint(0), line2.Direction.Negate()); SetComparisonResult intersectionResult = scaledLine1.Intersect(scaledLine2, out IntersectionResultArray results); if (intersectionResult == SetComparisonResult.Overlap) { IntersectionResult result = results.get_Item(0); Line newLine1 = Line.CreateBound(line1.GetEndPoint(0), result.XYZPoint); Line newLine2 = Line.CreateBound(result.XYZPoint, line2.GetEndPoint(1)); linesToDraw[i] = newLine1; linesToDraw[i + 1] = newLine2; } } //Create the angled corner lines at the start and end of the line chain Line firstCornerLine = Line.CreateBound(firstPoint, firstLine.GetEndPoint(0)); Line lastCornerLine = Line.CreateBound(lastPoint, lastLine.GetEndPoint(1)); linesToDraw.Add(firstCornerLine); linesToDraw.Add(lastCornerLine); //Create each line as a detail line foreach (Line apiLine in linesToDraw) { DetailCurve newAccentLine = doc.Create.NewDetailCurve(doc.ActiveView, apiLine); newAccentLine.LineStyle = lineStyle; } //Declare some stuff for use in the symbol placement Line firstMiddleLine = linesToDraw[0]; Line lastMiddleLine = linesToDraw[linesToDraw.Count - 3]; XYZ firstTagPoint = firstMiddleLine.Evaluate(0.5d, true); XYZ lastTagPoint = lastMiddleLine.Evaluate(0.5d, true); XYZ firstDirection = firstMiddleLine.Direction; XYZ lastDirection = lastMiddleLine.Direction; Line firstAxisLine = Line.CreateUnbound(firstTagPoint, XYZ.BasisZ); Line lastAxisLine = Line.CreateUnbound(lastTagPoint, XYZ.BasisZ); double firstRotation = firstDirection.AngleTo(XYZ.BasisX); double lastRotation = lastDirection.AngleTo(XYZ.BasisX); if (familySymbol != null) { //Create tag at the beginning of the middle lines FamilyInstance firstTag = doc.Create.NewFamilyInstance(firstTagPoint, familySymbol, doc.ActiveView); ElementTransformUtils.RotateElement(doc, firstTag.Id, firstAxisLine, firstRotation); //Create a tag at the end of the middle lines if there are more than 2 middle lines if (linesToDraw.Count > 4) { FamilyInstance lastTag = doc.Create.NewFamilyInstance(lastTagPoint, familySymbol, doc.ActiveView); ElementTransformUtils.RotateElement(doc, lastTag.Id, lastAxisLine, lastRotation); } } createLinesTransaction.Commit(); } } catch (Exception e) { //Suppose the user closed the palette too soon. This will remind them to keep it open. if (BARevitTools.Application.thisApp.newMainUi.materialsAMLPalette == null) { MessageBox.Show("AML Picker was closed prematurely. Please keep the picker open until the lines are drawn."); } else { //Otherwise, if some other error occurred, show the exception MessageBox.Show(e.ToString()); } createLinesTransaction.RollBack(); } } else { ; } } }