/// <summary> /// Gets element filter that match certain types. /// </summary> /// <param name="forSpatialElements">True if to get filter for spatial element, false for other elements.</param> /// <returns>The element filter.</returns> private static ElementFilter GetClassFilter(bool forSpatialElements) { if (forSpatialElements) { return new ElementClassFilter(typeof(SpatialElement)); } else { List<Type> excludedTypes = new List<Type>(); // FamilyInstances are handled in separate filter. excludedTypes.Add(typeof(FamilyInstance)); excludedTypes.Add(typeof(SpatialElement)); if (!ExporterCacheManager.ExportOptionsCache.ExportAnnotations) excludedTypes.Add(typeof(CurveElement)); excludedTypes.Add(typeof(ElementType)); excludedTypes.Add(typeof(Group)); excludedTypes.Add(typeof(BaseArray)); excludedTypes.Add(typeof(FillPatternElement)); excludedTypes.Add(typeof(LinePatternElement)); excludedTypes.Add(typeof(Material)); excludedTypes.Add(typeof(GraphicsStyle)); excludedTypes.Add(typeof(Family)); excludedTypes.Add(typeof(SketchPlane)); excludedTypes.Add(typeof(View)); excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.LoadBase)); excludedTypes.Add(typeof(BeamSystem)); // curtain wall sub-types we are ignoring. excludedTypes.Add(typeof(CurtainGridLine)); // excludedTypes.Add(typeof(Mullion)); // this will be gotten from the element(s) it cuts. excludedTypes.Add(typeof(Opening)); // 2D types we are ignoring excludedTypes.Add(typeof(SketchBase)); excludedTypes.Add(typeof(FaceSplitter)); // 2D types covered by the element owner view filter excludedTypes.Add(typeof(TextNote)); excludedTypes.Add(typeof(FilledRegion)); // exclude levels that are covered in BeginExport excludedTypes.Add(typeof(Level)); // exclude analytical models excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.AnalyticalModel)); ElementFilter excludedClassFilter = new ElementMulticlassFilter(excludedTypes, true); List<BuiltInCategory> excludedCategories = new List<BuiltInCategory>(); // Native Revit types without match in API excludedCategories.Add(BuiltInCategory.OST_Property); excludedCategories.Add(BuiltInCategory.OST_SiteProperty); excludedCategories.Add(BuiltInCategory.OST_SitePropertyLineSegment); excludedCategories.Add(BuiltInCategory.OST_Viewports); excludedCategories.Add(BuiltInCategory.OST_Views); excludedCategories.Add(BuiltInCategory.OST_IOS_GeoLocations); excludedCategories.Add(BuiltInCategory.OST_RvtLinks); excludedCategories.Add(BuiltInCategory.OST_DecalElement); //excludedCategories.Add(BuiltInCategory.OST_Parts); excludedCategories.Add(BuiltInCategory.OST_DuctCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_DuctFittingCenterLine); excludedCategories.Add(BuiltInCategory.OST_PipeCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_PipeFittingCenterLine); excludedCategories.Add(BuiltInCategory.OST_ConduitCenterLine); excludedCategories.Add(BuiltInCategory.OST_ConduitFittingCenterLine); excludedCategories.Add(BuiltInCategory.OST_FlexDuctCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_FlexPipeCurvesCenterLine); ElementMulticategoryFilter excludedCategoryFilter = new ElementMulticategoryFilter(excludedCategories, true); LogicalAndFilter exclusionFilter = new LogicalAndFilter(excludedClassFilter, excludedCategoryFilter); ElementOwnerViewFilter ownerViewFilter = new ElementOwnerViewFilter(ElementId.InvalidElementId); LogicalAndFilter returnedFilter = new LogicalAndFilter(exclusionFilter, ownerViewFilter); return returnedFilter; } }
private static ElementFilter CreateTextFilter(View view) { var filter = new ElementOwnerViewFilter(view.Id); return(filter); }
/// <summary> /// Gets element filter that match certain types. /// </summary> /// <param name="forSpatialElements">True if to get filter for spatial element, false for other elements.</param> /// <returns>The element filter.</returns> private static ElementFilter GetClassFilter(bool forSpatialElements) { if (forSpatialElements) { return(new ElementClassFilter(typeof(SpatialElement))); } else { List <Type> excludedTypes = new List <Type>(); // FamilyInstances are handled in separate filter. excludedTypes.Add(typeof(FamilyInstance)); // Spatial element are exported in a separate pass. excludedTypes.Add(typeof(SpatialElement)); // AreaScheme elements are exported as groups after all Areas have been exported. excludedTypes.Add(typeof(AreaScheme)); // FabricArea elements are exported as groups after all FabricSheets have been exported. excludedTypes.Add(typeof(FabricArea)); if (!ExporterCacheManager.ExportOptionsCache.ExportAnnotations) { excludedTypes.Add(typeof(CurveElement)); } excludedTypes.Add(typeof(ElementType)); excludedTypes.Add(typeof(BaseArray)); excludedTypes.Add(typeof(FillPatternElement)); excludedTypes.Add(typeof(LinePatternElement)); excludedTypes.Add(typeof(Material)); excludedTypes.Add(typeof(GraphicsStyle)); excludedTypes.Add(typeof(Family)); excludedTypes.Add(typeof(SketchPlane)); excludedTypes.Add(typeof(View)); excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.LoadBase)); // curtain wall sub-types we are ignoring. excludedTypes.Add(typeof(CurtainGridLine)); // excludedTypes.Add(typeof(Mullion)); // this will be gotten from the element(s) it cuts. excludedTypes.Add(typeof(Opening)); // 2D types we are ignoring excludedTypes.Add(typeof(SketchBase)); excludedTypes.Add(typeof(FaceSplitter)); // 2D types covered by the element owner view filter excludedTypes.Add(typeof(TextNote)); excludedTypes.Add(typeof(FilledRegion)); // exclude levels that are covered in BeginExport excludedTypes.Add(typeof(Level)); // exclude analytical models excludedTypes.Add(typeof(Autodesk.Revit.DB.Structure.AnalyticalElement)); ElementFilter excludedClassFilter = new ElementMulticlassFilter(excludedTypes, true); List <BuiltInCategory> excludedCategories = new List <BuiltInCategory>(); // Native Revit types without match in API excludedCategories.Add(BuiltInCategory.OST_ConduitCenterLine); excludedCategories.Add(BuiltInCategory.OST_ConduitFittingCenterLine); excludedCategories.Add(BuiltInCategory.OST_DecalElement); //excludedCategories.Add(BuiltInCategory.OST_Parts); //excludedCategories.Add(BuiltInCategory.OST_RvtLinks); excludedCategories.Add(BuiltInCategory.OST_DuctCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_DuctFittingCenterLine); excludedCategories.Add(BuiltInCategory.OST_FlexDuctCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_FlexPipeCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_IOS_GeoLocations); excludedCategories.Add(BuiltInCategory.OST_PipeCurvesCenterLine); excludedCategories.Add(BuiltInCategory.OST_PipeFittingCenterLine); excludedCategories.Add(BuiltInCategory.OST_Property); excludedCategories.Add(BuiltInCategory.OST_SiteProperty); excludedCategories.Add(BuiltInCategory.OST_SitePropertyLineSegment); excludedCategories.Add(BuiltInCategory.OST_TopographyContours); excludedCategories.Add(BuiltInCategory.OST_Viewports); excludedCategories.Add(BuiltInCategory.OST_Views); // Exclude elements with no category. excludedCategories.Add(BuiltInCategory.INVALID); ElementMulticategoryFilter excludedCategoryFilter = new ElementMulticategoryFilter(excludedCategories, true); LogicalAndFilter exclusionFilter = new LogicalAndFilter(excludedClassFilter, excludedCategoryFilter); ElementOwnerViewFilter ownerViewFilter = new ElementOwnerViewFilter(ElementId.InvalidElementId); LogicalAndFilter returnedFilter = new LogicalAndFilter(exclusionFilter, ownerViewFilter); return(returnedFilter); } }
/// <summary> /// Exports all elements in 3D View to separate .fbx files. /// </summary> public string Export(Autodesk.Revit.DB.Document document) { Autodesk.Revit.DB.Document doc = document; Autodesk.Revit.DB.View activeView = doc.ActiveView; FBXExportOptions options = new FBXExportOptions(); if (activeView.ViewType != ViewType.ThreeD) { TaskDialog.Show("Warning", "Can only be run in 3D View."); return("Failed"); } ElementOwnerViewFilter elementOwnerViewFilter = new ElementOwnerViewFilter(activeView.Id); FilteredElementCollector col = new FilteredElementCollector(doc, activeView.Id) .WhereElementIsNotElementType(); ICollection <ElementId> allAlements = col.ToElementIds(); IList <Element> viewElements = col.ToElements(); using (System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog()) { if (folderDialog.ShowDialog() != DialogResult.OK) { return("No folder chosen."); } string folder = folderDialog.SelectedPath; // Filtered element collector is iterable ViewSet viewSet = new ViewSet(); int c = 0; foreach (Element e in col) { using (Transaction tx = new Transaction(doc)) { tx.Start(String.Format("Export element {0}", e.Id.ToString())); activeView.IsolateElementTemporary(e.Id); activeView.ConvertTemporaryHideIsolateToPermanent(); viewSet.Insert(activeView); doc.Export(folder, e.Id.ToString(), viewSet, options); activeView.UnhideElements(allAlements); doc.Regenerate(); tx.Commit(); } viewSet.Clear(); c++; } string runMessage = String.Format("Run {0} times", c); TaskDialog.Show("Result", runMessage); return(String.Format("Successfully exported {0} elements", c)); } }
public void TransferViewproject(Document source, Document targets, ICollection <ElementId> elementIds, string Title_name, int versionnumber) { Transaction newtran = new Transaction(targets, "Transfer"); newtran.Start(); CopyPasteOptions options = new CopyPasteOptions(); options.SetDuplicateTypeNamesHandler(new CopyHandler()); foreach (var i in elementIds) { View view = source.GetElement(i) as View; if (view.ViewType == ViewType.Legend) { IList <ElementId> list1 = (from View i1 in new FilteredElementCollector(targets).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.ViewType == ViewType.Legend select i1.Id).ToList(); ICollection <ElementId> collection2 = new List <ElementId>(); collection2.Add(i); ICollection <ElementId> litstrans = ElementTransformUtils.CopyElements(source, collection2, targets, null, options); foreach (var m in litstrans) { View o = targets.GetElement(m) as View; o.Name = o.Name + "(" + Title_name + ")"; } if (versionnumber <= 2019) { View val4 = (from View i1 in new FilteredElementCollector(source).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.Id == i select i1).FirstOrDefault(); FilteredElementCollector val5 = new FilteredElementCollector(targets).OfClass(typeof(View)); if (list1.Count > 0) { var Y = val5.Excluding(list1); } View val6 = (from View i1 in val5.WhereElementIsNotElementType() where (int)i1.ViewType == 11 select i1).FirstOrDefault(); ElementOwnerViewFilter val7 = new ElementOwnerViewFilter(val4.Id); ElementCategoryFilter val8 = new ElementCategoryFilter(BuiltInCategory.OST_IOSSketchGrid, true); ElementCategoryFilter val9 = new ElementCategoryFilter(BuiltInCategory.OST_CLines, true); FilteredElementCollector val10 = new FilteredElementCollector(source); val10.WherePasses(val7); val10.WherePasses(val8); val10.WherePasses(val9); IList <ElementId> list2 = (from Element i1 in val10 where i1.Category != null select i1.Id).ToList(); if (list2.Count > 0) { ElementTransformUtils.CopyElements(val4, list2, val6, null, options); } } } if (view.ViewType == ViewType.DraftingView) { IList <ElementId> list1 = (from View i1 in new FilteredElementCollector(targets).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.ViewType == ViewType.DraftingView select i1.Id).ToList(); ICollection <ElementId> collection2 = new List <ElementId>(); collection2.Add(i); ICollection <ElementId> litstrans = ElementTransformUtils.CopyElements(source, collection2, targets, null, options); foreach (var m in litstrans) { View o = targets.GetElement(m) as View; o.Name = o.Name + "(" + Title_name + ")"; } View val4 = (from View i1 in new FilteredElementCollector(source).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.Id == i select i1).FirstOrDefault(); FilteredElementCollector val5 = new FilteredElementCollector(targets).OfClass(typeof(View)); if (list1.Count > 0) { var Y = val5.Excluding(list1); } View val6 = (from View i1 in val5.WhereElementIsNotElementType() where i1.ViewType == ViewType.DraftingView select i1).FirstOrDefault(); ElementOwnerViewFilter val7 = new ElementOwnerViewFilter(val4.Id); ElementCategoryFilter val8 = new ElementCategoryFilter(BuiltInCategory.OST_IOSSketchGrid, true); ElementCategoryFilter val9 = new ElementCategoryFilter(BuiltInCategory.OST_CLines, true); FilteredElementCollector val10 = new FilteredElementCollector(source); val10.WherePasses(val7); val10.WherePasses(val8); val10.WherePasses(val9); IList <ElementId> list2 = (from Element i1 in val10 where i1.Category != null select i1.Id).ToList(); IList <ElementId> list3 = new List <ElementId>(); foreach (var u in list2) { Element po = source.GetElement(u); var ty = po.Category.Name.ToString(); if (ty != "Views") { list3.Add(u); } } if (list3.Count > 0) { ElementTransformUtils.CopyElements(val4, list3, val6, null, options); } } if (view.ViewType == ViewType.Schedule) { IList <ElementId> list1 = (from View i1 in new FilteredElementCollector(targets).OfClass(typeof(View)).WhereElementIsNotElementType() where i1.ViewType == ViewType.Schedule select i1.Id).ToList(); ICollection <ElementId> collection2 = new List <ElementId>(); collection2.Add(i); ICollection <ElementId> litstrans = ElementTransformUtils.CopyElements(source, collection2, targets, null, options); foreach (var m in litstrans) { View o = targets.GetElement(m) as View; o.Name = o.Name + "(" + Title_name + ")"; } } } newtran.Commit(); }
Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Level level = doc.ActiveView.GenLevel; View view = doc.ActiveView; FamilySymbol symbol = doc.GetElement(new ElementId(587194)) as FamilySymbol; ElementClassFilter dimfilter = new ElementClassFilter(typeof(Dimension)); ElementOwnerViewFilter viewfilter = new ElementOwnerViewFilter(view.Id); FilteredElementCollector collector = new FilteredElementCollector(doc); collector.WherePasses(dimfilter).WherePasses(viewfilter); List <Dimension> add = new List <Dimension>(); List <Dimension> add2 = new List <Dimension>(); List <DimensionSegmentArray> dimarrayarray = new List <DimensionSegmentArray>(); ReferenceArray referarray = new ReferenceArray(); ReferenceArray referarray2 = new ReferenceArray(); foreach (Element e in collector) { Dimension dim = e as Dimension; if (dim.NumberOfSegments > 1) { dimarrayarray.Add(dim.Segments); add2.Add(dim); } else { add.Add(dim); } } if (add2.Count != 0) //连续尺寸标注 { using (Transaction trans = new Transaction(doc)) { FailureHandlingOptions failureHandlingOptions = trans.GetFailureHandlingOptions(); FailureHandler failureHandler = new FailureHandler(); failureHandlingOptions.SetFailuresPreprocessor(failureHandler); // 这句话是关键 failureHandlingOptions.SetClearAfterRollback(true); trans.SetFailureHandlingOptions(failureHandlingOptions); trans.Start("Start"); ChangeDimensionTypeStyle(add2.First <Dimension>(), doc); for (int b = 0; b < add2.Count; b++) { referarray2 = add2.ElementAt <Dimension>(b).References; foreach (Reference refer in referarray2) { //string re = refer.ElementReferenceType.ToString(); var cu = add2.ElementAt <Dimension>(b).Curve; Dimension dim = add2.ElementAt <Dimension>(b); Line li = cu as Line; //var n = re.GetType().ToString(); Element el = doc.GetElement(refer); Curve curve = null; if (el.Location.GetType() != typeof(LocationCurve)) { if (el.GetType() == typeof(Grid)) { curve = (el as Grid).Curve; } else if ((el as FamilyInstance) is FamilyInstance) { FamilyInstance instance2 = el as FamilyInstance; Element hostelement = instance2.Host; curve = GetLineFromLcPoint(GetSolid(hostelement), instance2); } else if (el.GetType() == typeof(Floor)) { Floor floor = el as Floor; Face face = GetGeometryFace(GetSolid(el)); var test2 = GetCurveFromFloor(face, add2[b].Curve); if (test2.Size < 2) { break; } XYZ[] xYZsn = { test2.get_Item(0).GetEndPoint(0), test2.get_Item(1).GetEndPoint(0) }; Line l3 = Line.CreateBound(test2.get_Item(0).GetEndPoint(0), test2.get_Item(1).GetEndPoint(0)); curve = l3 as Curve; } } else { curve = (el.Location as LocationCurve).Curve; } if (curve == null) { break; } XYZ p0 = li.Project(curve.GetEndPoint(1)) .XYZPoint; if (!symbol.IsActive) { symbol.Activate(); } FamilyInstance instance = doc.Create.NewFamilyInstance(p0, symbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming); var l = GetGeometryLine(GetGeometryFace(GetSolid(instance))); double an = GetAngle(li, l); double rotateangle; double e = 1e-12; double a = Math.Round((an - Math.PI / 4), 13); double c = Math.Round(Math.Abs((an - Math.PI * 3 / 2)), 13); if (a != e || c != Math.Round(Math.PI * 3 / 2, 13)) //判断度数,相减做判断 { if (an > Math.PI * 0.5) { rotateangle = 0.75 * Math.PI - an; } else { rotateangle = an + 0.25 * Math.PI; } LocationPoint lp = instance.Location as LocationPoint; if (lp != null) { Line line3 = Line.CreateBound(new XYZ(lp.Point.X, lp.Point.Y, 0), new XYZ(lp.Point.X, lp.Point.Y, lp.Point.Z + 20)); lp.Rotate(line3, rotateangle); XYZ pNew = (instance.Location as LocationPoint).Point; if (p0.X != pNew.X || p0.Y != pNew.Y || p0.Z != pNew.Z) { lp.Point = p0; } //旋转基于平面与原点位置,对照两个位置将旋转后族放置到指定位置 } } } } trans.Commit(); } } //逐点标注 if (add.Count != 0) //普通尺寸标注 { using (Transaction trans = new Transaction(doc)) //将本身的Dimension样式修改未无对角线样式 { FailureHandlingOptions failureHandlingOptions = trans.GetFailureHandlingOptions(); FailureHandler failureHandler = new FailureHandler(); failureHandlingOptions.SetFailuresPreprocessor(failureHandler); // 这句话是关键 failureHandlingOptions.SetClearAfterRollback(true); trans.SetFailureHandlingOptions(failureHandlingOptions); trans.Start("Text"); ChangeDimensionTypeStyle(add.First <Dimension>(), doc); trans.Commit(); } for (int a = 0; a < add.Count; a++) { referarray = add.ElementAt <Dimension>(a).References; if (referarray.Size == 2) { foreach (Reference re in referarray) { var cu = add.ElementAt <Dimension>(a).Curve; Dimension dim = add.ElementAt <Dimension>(a); Line li = cu as Line; //var n = re.GetType().ToString(); Element el = doc.GetElement(re); Curve curve = null; using (Transaction test = new Transaction(doc, "change")) { FailureHandlingOptions failureHandlingOptions = test.GetFailureHandlingOptions(); FailureHandler failureHandler = new FailureHandler(); failureHandlingOptions.SetFailuresPreprocessor(failureHandler); // 这句话是关键 failureHandlingOptions.SetClearAfterRollback(true); test.SetFailureHandlingOptions(failureHandlingOptions); test.Start(); if (el.Location.GetType() != typeof(LocationCurve)) { if (el.GetType() == typeof(Grid)) { curve = (el as Grid).Curve; } else if ((el as FamilyInstance) is FamilyInstance) { FamilyInstance instance2 = el as FamilyInstance; Element hostelement = instance2.Host; curve = GetLineFromLcPoint(GetSolid(hostelement), instance2); } else if (el.GetType() == typeof(Floor)) { Floor floor = el as Floor; Face face = GetGeometryFace(GetSolid(el)); var test2 = GetCurveFromFloor(face, add[a].Curve); if (test2.Size < 2) { break; } XYZ[] xYZsn = { test2.get_Item(0).GetEndPoint(0), test2.get_Item(1).GetEndPoint(0) }; Line l = Line.CreateBound(test2.get_Item(0).GetEndPoint(0), test2.get_Item(1).GetEndPoint(0)); curve = l as Curve; } if (curve == null) { break; } XYZ[] xYZs = { curve.GetEndPoint(0), curve.GetEndPoint(1) }; foreach (XYZ xyz in xYZs) { XYZ p0 = li.Project(xyz).XYZPoint; if (!symbol.IsActive) { symbol.Activate(); } FamilyInstance instance = doc.Create.NewFamilyInstance(p0, symbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming); var l = GetGeometryLine(GetGeometryFace(GetSolid(instance))); double an = GetAngle(li, l); if (an != Math.PI / 4 || an != Math.PI * 3 / 2) { LocationPoint lp = instance.Location as LocationPoint; if (lp != null) { Line line3 = Line.CreateBound(new XYZ(lp.Point.X, lp.Point.Y, 0), new XYZ(lp.Point.X, lp.Point.Y, lp.Point.Z + 20)); lp.Rotate(line3, 0.25 * Math.PI + (Math.PI + an)); XYZ pNew = (instance.Location as LocationPoint).Point; if (p0.X != pNew.X || p0.Y != pNew.Y || p0.Z != pNew.Z) { lp.Point = p0; } //旋转基于平面与原点位置,对照两个位置将旋转后族放置到指定位置 } } } } else { curve = (el.Location as LocationCurve).Curve; if (doc.GetElement(referarray.get_Item(0)).Id == doc.GetElement(referarray.get_Item(1)).Id) { var cu4 = add.ElementAt <Dimension>(a).Curve; Dimension dim4 = add.ElementAt <Dimension>(a); Line li4 = cu as Line; //var n = re.GetType().ToString(); Element el4 = doc.GetElement(referarray.get_Item(0)); Curve curve4 = (el4.Location as LocationCurve).Curve; XYZ[] xyzs2 = { curve4.GetEndPoint(0), curve4.GetEndPoint(1) }; foreach (XYZ xyz in xyzs2) { XYZ p0 = li.Project(xyz).XYZPoint; if (!symbol.IsActive) { symbol.Activate(); } FamilyInstance instance = doc.Create.NewFamilyInstance(p0, symbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming); var l = GetGeometryLine(GetGeometryFace(GetSolid(instance))); double an = GetAngle(li, l); if (an != Math.PI / 4 || an != Math.PI * 3 / 2) { LocationPoint lp = instance.Location as LocationPoint; if (lp != null) { Line line3 = Line.CreateBound(new XYZ(lp.Point.X, lp.Point.Y, 0), new XYZ(lp.Point.X, lp.Point.Y, lp.Point.Z + 20)); lp.Rotate(line3, 0.25 * Math.PI + (Math.PI + an)); XYZ pNew = (instance.Location as LocationPoint).Point; if (p0.X != pNew.X || p0.Y != pNew.Y || p0.Z != pNew.Z) { lp.Point = p0; } //旋转基于平面与原点位置,对照两个位置将旋转后族放置到指定位置 } } } } else { foreach (Reference refer in referarray) { //string re = refer.ElementReferenceType.ToString(); var cu3 = add.ElementAt <Dimension>(a).Curve; Dimension dim3 = add.ElementAt <Dimension>(a); Line li3 = cu as Line; //var n = re.GetType().ToString(); Element el3 = doc.GetElement(refer); Curve curve3 = null; if (el3.Location.GetType() != typeof(LocationCurve)) { if (el3.GetType() == typeof(Grid)) { curve3 = (el3 as Grid).Curve; } else if ((el3 as FamilyInstance) is FamilyInstance) { FamilyInstance instance3 = el3 as FamilyInstance; Element hostelement = instance3.Host; curve3 = GetLineFromLcPoint(GetSolid(hostelement), instance3); } else if (el3.GetType() == typeof(Floor)) { Floor floor = el3 as Floor; Face face = GetGeometryFace(GetSolid(el3)); var test2 = GetCurveFromFloor(face, add2[a].Curve); if (test2.Size < 2) { break; } XYZ[] xYZsn = { test2.get_Item(0).GetEndPoint(0), test2.get_Item(1).GetEndPoint(0) }; Line l4 = Line.CreateBound(test2.get_Item(0).GetEndPoint(0), test2.get_Item(1).GetEndPoint(0)); curve3 = l4 as Curve; } } else { curve3 = (el3.Location as LocationCurve).Curve; } if (curve3 == null) { break; } XYZ p0 = li3.Project(curve.GetEndPoint(1)) .XYZPoint; if (!symbol.IsActive) { symbol.Activate(); } FamilyInstance instance = doc.Create.NewFamilyInstance(p0, symbol, level, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming); var l = GetGeometryLine(GetGeometryFace(GetSolid(instance))); double an = GetAngle(li, l); if (an != Math.PI / 4 || an != Math.PI * 3 / 2) { LocationPoint lp = instance.Location as LocationPoint; if (lp != null) { Line line3 = Line.CreateBound(new XYZ(lp.Point.X, lp.Point.Y, 0), new XYZ(lp.Point.X, lp.Point.Y, lp.Point.Z + 20)); lp.Rotate(line3, 0.25 * Math.PI + (Math.PI + an)); XYZ pNew = (instance.Location as LocationPoint).Point; if (p0.X != pNew.X || p0.Y != pNew.Y || p0.Z != pNew.Z) { lp.Point = p0; } //旋转基于平面与原点位置,对照两个位置将旋转后族放置到指定位置 } } } } } test.Commit(); } } } } } //连续标注 return(Result.Succeeded); }
/// <summary> /// Exports all elements in 3D View to separate .fbx files. /// </summary> public static string Export(Autodesk.Revit.DB.Document document, System.Windows.Forms.ProgressBar progressBar, System.Windows.Forms.Label label, System.Windows.Forms.Label percent) { Autodesk.Revit.DB.Document doc = document; Autodesk.Revit.DB.View activeView = doc.ActiveView; FBXExportOptions options = new FBXExportOptions(); if (activeView.ViewType != ViewType.ThreeD) { TaskDialog.Show("Warning", "Can only be run in 3D View."); return("Failed"); } ElementOwnerViewFilter elementOwnerViewFilter = new ElementOwnerViewFilter(activeView.Id); FilteredElementCollector col = new FilteredElementCollector(doc, activeView.Id) .WhereElementIsNotElementType(); ICollection <ElementId> allAlements = col.ToElementIds(); using (System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog()) { if (folderDialog.ShowDialog() != DialogResult.OK) { return("No folder chosen."); } string folder = folderDialog.SelectedPath; // Filtered element collector is iterable ViewSet viewSet = new ViewSet(); int c = 0; ICollection <ElementId> removedElements = new List <ElementId>(); //Hide everything first using (Transaction t = new Transaction(doc, "Hide all")) { t.Start(); foreach (ElementId e in allAlements) { if (e == null) { continue; } try { if (doc.GetElement(e).Category.Name.Contains("Curtain") || doc.GetElement(e).Category.Name.Contains("Lines") || doc.GetElement(e).Category.Name.Contains("Top Rails") || doc.GetElement(e).Category.Name.Contains("Shaft Openings")) { removedElements.Add(e); continue; } } catch (Exception) { } ICollection <ElementId> element = new List <ElementId>() { e }; try { activeView.HideElements(element); } catch (Exception ex) { Console.WriteLine(ex); removedElements.Add(e); } } t.Commit(); } foreach (var obj in removedElements) { allAlements.Remove(obj); } progressBar.Minimum = 0; progressBar.Maximum = allAlements.Count; string regexSearch = new string(System.IO.Path.GetInvalidFileNameChars()); //Unhide each element one by one and export a view with it foreach (ElementId e in allAlements) { ICollection <ElementId> element = new List <ElementId>() { e }; if (e == null) { continue; } var el = doc.GetElement(e); if (el.Category == null) { continue; } if (el.Category.Name == null) { continue; } string category = el.Category.Name; string famtype = el.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString(); string name = String.Format("{0}-{1}-id{2}", category, famtype, e.ToString()); Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch))); name = r.Replace(name, ""); using (Transaction tx = new Transaction(doc)) { tx.Start(String.Format("Export element {0}", e.ToString())); activeView.UnhideElements(element); doc.Regenerate(); viewSet.Insert(activeView); try { doc.Export(folder, name, viewSet, options); } catch (Exception ex) { TaskDialog.Show("Error", String.Format("There has been a problem executing this script.{0}{1}", Environment.NewLine, ex.Message)); } activeView.HideElements(element); tx.Commit(); } viewSet.Clear(); progressBar.Value++; label.Text = String.Format("Exported {0} of {1}", progressBar.Value.ToString(), progressBar.Maximum.ToString()); label.Refresh(); percent.Text = String.Format("{0}{1}", (Convert.ToInt16((progressBar.Value / (progressBar.Maximum * 1.0)) * 100)).ToString(), "%"); percent.Refresh(); c++; } //Finally unhide everything back using (Transaction t = new Transaction(doc, "Hide all")) { t.Start(); activeView.UnhideElements(allAlements); t.Commit(); } string runMessage = String.Format("Successfully exported {0} elements", c); TaskDialog.Show("Result", runMessage); return(runMessage); } }