//本来想在这里做一个放样的,但是放样用api做需要建立族文件,然后再在族文件中创建放样,再导入进来,比较麻烦暂时就不做了,详参: //https://blog.csdn.net/niaxiapia/article/details/80513595?ops_request_misc=%25257B%252522request%25255Fid%252522%25253A%252522161121330016780265434271%252522%25252C%252522scm%252522%25253A%25252220140713.130102334.pc%25255Fall.%252522%25257D&request_id=161121330016780265434271&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_v2~rank_v29-4-80513595.pc_search_result_cache&utm_term=revit%E4%BA%8C%E6%AC%A1%E5%BC%80%E5%8F%91%20%E6%94%BE%E6%A0%B7 private void createExtrusionProfile(ExternalCommandData commandData, Line line, Double radius) { Autodesk.Revit.DB.Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档 Application revitApp = commandData.Application.Application; //取得应用程序 UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 Autodesk.Revit.DB.Document document = uiDoc.Document; //获取一个轮廓,此处就用圆形轮廓 Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero); SketchPlane sketchPlane = SketchPlane.Create(document, plane); Arc arc = Arc.Create(plane, radius, 0, Math.PI * 2); //为下面的放样准备参数 CurveArray curveArray = new CurveArray(); CurveArrArray curveArrArray = new CurveArrArray(); curveArray.Append(arc); curveArrArray.Append(curveArray); //放样所用的直线 ReferenceArray referenceArray = new ReferenceArray(); referenceArray.Append(line.Reference); Autodesk.Revit.Creation.Application application = uiDoc.Application.Application.Create; SweepProfile sweepProfile = application.NewCurveLoopsProfile(curveArrArray); //这句话是不对的,原因是在项目文档中无法拉伸,应该在族文档中实现 //Sweep sweep = document.FamilyCreate.NewSweep(true, referenceArray, sweepProfile, 0, ProfilePlaneLocation.Start); }
/// <summary> /// Create one SweptBlend /// </summary> private void CreateSweptBlend() { try { #region Create top and bottom profiles and path curve Autodesk.Revit.DB.XYZ pnt1 = new Autodesk.Revit.DB.XYZ(0, 0, 0); Autodesk.Revit.DB.XYZ pnt2 = new Autodesk.Revit.DB.XYZ(1, 0, 0); Autodesk.Revit.DB.XYZ pnt3 = new Autodesk.Revit.DB.XYZ(1, 1, 0); Autodesk.Revit.DB.XYZ pnt4 = new Autodesk.Revit.DB.XYZ(0, 1, 0); Autodesk.Revit.DB.XYZ pnt5 = new Autodesk.Revit.DB.XYZ(0, 0, 1); CurveArrArray arrarr1 = new CurveArrArray(); CurveArray arr1 = new CurveArray(); arr1.Append(Line.CreateBound(pnt1, pnt2)); arr1.Append(Line.CreateBound(pnt2, pnt3)); arr1.Append(Line.CreateBound(pnt3, pnt4)); arr1.Append(Line.CreateBound(pnt4, pnt1)); arrarr1.Append(arr1); Autodesk.Revit.DB.XYZ pnt6 = new Autodesk.Revit.DB.XYZ(0.5, 0, 0); Autodesk.Revit.DB.XYZ pnt7 = new Autodesk.Revit.DB.XYZ(1, 0.5, 0); Autodesk.Revit.DB.XYZ pnt8 = new Autodesk.Revit.DB.XYZ(0.5, 1, 0); Autodesk.Revit.DB.XYZ pnt9 = new Autodesk.Revit.DB.XYZ(0, 0.5, 0); CurveArrArray arrarr2 = new CurveArrArray(); CurveArray arr2 = new CurveArray(); arr2.Append(Line.CreateBound(pnt6, pnt7)); arr2.Append(Line.CreateBound(pnt7, pnt8)); arr2.Append(Line.CreateBound(pnt8, pnt9)); arr2.Append(Line.CreateBound(pnt9, pnt6)); arrarr2.Append(arr2); SweepProfile bottomProfile = m_revit.Create.NewCurveLoopsProfile(arrarr1); SweepProfile topProfile = m_revit.Create.NewCurveLoopsProfile(arrarr2); Autodesk.Revit.DB.XYZ pnt10 = new Autodesk.Revit.DB.XYZ(5, 0, 0); Autodesk.Revit.DB.XYZ pnt11 = new Autodesk.Revit.DB.XYZ(0, 20, 0); Curve curve = Line.CreateBound(pnt10, pnt11); Autodesk.Revit.DB.XYZ normal = Autodesk.Revit.DB.XYZ.BasisZ; SketchPlane sketchPlane = CreateSketchPlane(normal, Autodesk.Revit.DB.XYZ.Zero); #endregion // here create one swept blend SweptBlend newSweptBlend1 = m_creationFamily.NewSweptBlend(true, curve, sketchPlane, bottomProfile, topProfile); // move to proper place Autodesk.Revit.DB.XYZ transPoint1 = new Autodesk.Revit.DB.XYZ(11, 32, 0); ElementTransformUtils.MoveElement(m_familyDocument, newSweptBlend1.Id, transPoint1); } catch (Exception e) { m_errCount++; m_errorInfo += "Unexpected exceptions occur in CreateSweptBlend: " + e.ToString() + "\r\n"; } }
Stream(ArrayList data, SweepProfile sweepProf) { data.Add(new Snoop.Data.ClassSeparator(typeof(SweepProfile))); // Nothing at this level yet! CurveLoopsProfile curLoopsProf = sweepProf as CurveLoopsProfile; if (curLoopsProf != null) { Stream(data, curLoopsProf); return; } FamilySymbolProfile famSymProf = sweepProf as FamilySymbolProfile; if (famSymProf != null) { Stream(data, famSymProf); return; } }
/// <summary> /// Create one sweep /// </summary> private void CreateSweep() { try { #region Create rectangular profile and path curve CurveArrArray arrarr = new CurveArrArray(); CurveArray arr = new CurveArray(); Autodesk.Revit.DB.XYZ normal = Autodesk.Revit.DB.XYZ.BasisZ; SketchPlane sketchPlane = CreateSketchPlane(normal, Autodesk.Revit.DB.XYZ.Zero); Autodesk.Revit.DB.XYZ pnt1 = new Autodesk.Revit.DB.XYZ(0, 0, 0); Autodesk.Revit.DB.XYZ pnt2 = new Autodesk.Revit.DB.XYZ(2, 0, 0); Autodesk.Revit.DB.XYZ pnt3 = new Autodesk.Revit.DB.XYZ(1, 1, 0); arr.Append(Arc.Create(pnt2, 1.0d, 0.0d, 180.0d, Autodesk.Revit.DB.XYZ.BasisX, Autodesk.Revit.DB.XYZ.BasisY)); arr.Append(Arc.Create(pnt1, pnt3, pnt2)); arrarr.Append(arr); SweepProfile profile = m_revit.Create.NewCurveLoopsProfile(arrarr); Autodesk.Revit.DB.XYZ pnt4 = new Autodesk.Revit.DB.XYZ(10, 0, 0); Autodesk.Revit.DB.XYZ pnt5 = new Autodesk.Revit.DB.XYZ(0, 10, 0); Curve curve = Line.CreateBound(pnt4, pnt5); CurveArray curves = new CurveArray(); curves.Append(curve); #endregion // here create one sweep with two arcs formed the profile Sweep sweep1 = m_creationFamily.NewSweep(true, curves, sketchPlane, profile, 0, ProfilePlaneLocation.Start); // move to proper place Autodesk.Revit.DB.XYZ transPoint1 = new Autodesk.Revit.DB.XYZ(11, 0, 0); ElementTransformUtils.MoveElement(m_familyDocument, sweep1.Id, transPoint1); } catch (Exception e) { m_errCount++; m_errorInfo += "Unexpected exceptions occur in CreateSweep: " + e.ToString() + "\r\n"; } }
/// <summary> /// Create a new swept blend form. /// The NewSweptBlend method requires the /// input profile to be in the XY plane. /// </summary> public void CreateNewSweptBlend(Document doc) { Debug.Assert(doc.IsFamilyDocument, "this method will only work in a family document"); Application app = doc.Application; Autodesk.Revit.Creation.Application creapp = app.Create; CurveArrArray curvess0 = creapp.NewCurveArrArray(); CurveArray curves0 = new CurveArray(); XYZ p00 = creapp.NewXYZ(0, 7.5, 0); XYZ p01 = creapp.NewXYZ(0, 15, 0); // changing Z to 1 in the following line fails: XYZ p02 = creapp.NewXYZ(-1, 10, 0); //curves0.Append( creapp.NewLineBound( p00, p01 ) ); // 2013 curves0.Append(Line.CreateBound(p00, p01)); // 2014 curves0.Append(Line.CreateBound(p01, p02)); curves0.Append(Line.CreateBound(p02, p00)); curvess0.Append(curves0); CurveArrArray curvess1 = creapp.NewCurveArrArray(); CurveArray curves1 = new CurveArray(); XYZ p10 = creapp.NewXYZ(7.5, 0, 0); XYZ p11 = creapp.NewXYZ(15, 0, 0); // changing the Z value in the following line fails: XYZ p12 = creapp.NewXYZ(10, -1, 0); curves1.Append(Line.CreateBound(p10, p11)); curves1.Append(Line.CreateBound(p11, p12)); curves1.Append(Line.CreateBound(p12, p10)); curvess1.Append(curves1); SweepProfile sweepProfile0 = creapp.NewCurveLoopsProfile(curvess0); SweepProfile sweepProfile1 = creapp.NewCurveLoopsProfile(curvess1); XYZ pnt10 = new XYZ(5, 0, 0); XYZ pnt11 = new XYZ(0, 20, 0); Curve curve = Line.CreateBound(pnt10, pnt11); XYZ normal = XYZ.BasisZ; SketchPlane splane = CreateSketchPlane( doc, normal, XYZ.Zero); try { SweptBlend sweptBlend = doc.FamilyCreate.NewSweptBlend( true, curve, splane, sweepProfile0, sweepProfile1); } catch (Exception ex) { Util.ErrorMsg("NewSweptBlend exception: " + ex.Message); } }
/// <summary> /// Create a new swept blend form using arcs to /// define circular start and end profiles and an /// arc path. The NewSweptBlend method requires /// the input profiles to be in the XY plane. /// </summary> public void CreateNewSweptBlendArc(Document doc) { Debug.Assert(doc.IsFamilyDocument, "this method will only work in a family document"); Application app = doc.Application; Autodesk.Revit.Creation.Application creapp = app.Create; Autodesk.Revit.Creation.FamilyItemFactory credoc = doc.FamilyCreate; #region Original code for Revit 2012 #if COMPILE_ORIGINAL_CODE XYZ pnt1 = new XYZ(0, -1, 0); XYZ pnt2 = new XYZ(1, 0, 0); XYZ pnt3 = new XYZ(0, 1, 0); XYZ pnt4 = new XYZ(-1, 0, 0); Arc aArc1 = creapp.NewArc(pnt1, pnt3, pnt2); Arc aArc2 = creapp.NewArc(pnt3, pnt1, pnt4); CurveArrArray arrarr1 = new CurveArrArray(); SweepProfile bottomProfile = creapp.NewCurveLoopsProfile(arrarr1); CurveArray arr1 = new CurveArray(); arr1.Append(aArc1); arr1.Append(aArc2); XYZ pnt6 = new XYZ(0, -2, 0); XYZ pnt7 = new XYZ(2, 0, 0); XYZ pnt8 = new XYZ(0, 2, 0); XYZ pnt9 = new XYZ(-2, 0, 0); Arc aArc3 = creapp.NewArc(pnt6, pnt8, pnt7); Arc aArc4 = creapp.NewArc(pnt8, pnt6, pnt9); CurveArrArray arrarr2 = new CurveArrArray(); CurveArray arr2 = new CurveArray(); arr2.Append(aArc3); arr2.Append(aArc4); arrarr2.Append(arr2); SweepProfile topProfile = creapp.NewCurveLoopsProfile(arrarr2); XYZ pnt10 = new XYZ(0, 0, 0); XYZ pnt11 = new XYZ(0, 5, 0); XYZ pnt122 = new XYZ(2.5, 2.5, 0); Arc testArc = creapp.NewArc(pnt10, pnt11, pnt122); Curve curve = (Curve)testArc; Plane geometryPlane = creapp.NewPlane( XYZ.BasisZ, XYZ.Zero); SketchPlane sketchPlane = doc.NewSketchPlane( geometryPlane); SweptBlend aSweptBlend = doc.NewSweptBlend( true, curve, sketchPlane, bottomProfile, topProfile); #endif // COMPILE_ORIGINAL_CODE #endregion // Original code for Revit 2012 XYZ px = XYZ.BasisX; XYZ py = XYZ.BasisY; Arc arc1 = Arc.Create(-px, px, -py); Arc arc2 = Arc.Create(px, -px, py); CurveArray arr1 = new CurveArray(); arr1.Append(arc1); arr1.Append(arc2); CurveArrArray arrarr1 = new CurveArrArray(); arrarr1.Append(arr1); SweepProfile bottomProfile = creapp.NewCurveLoopsProfile(arrarr1); px += px; py += py; Arc arc3 = Arc.Create(-px, px, -py); Arc arc4 = Arc.Create(px, -px, py); CurveArray arr2 = new CurveArray(); arr2.Append(arc3); arr2.Append(arc4); CurveArrArray arrarr2 = new CurveArrArray(); arrarr2.Append(arr2); SweepProfile topProfile = creapp.NewCurveLoopsProfile(arrarr2); XYZ p0 = XYZ.Zero; XYZ p5 = 5 * XYZ.BasisY; XYZ pmid = new XYZ(2.5, 2.5, 0); Arc testArc = Arc.Create(p0, p5, pmid); Plane geometryPlane = creapp.NewPlane( XYZ.BasisZ, XYZ.Zero); SketchPlane sketchPlane = SketchPlane.Create( doc, geometryPlane); SweptBlend aSweptBlend = credoc.NewSweptBlend( true, testArc, sketchPlane, bottomProfile, topProfile); }
private void Stream(ArrayList data, SweepProfile sweepProf) { data.Add(new Snoop.Data.ClassSeparator(typeof(SweepProfile))); // Nothing at this level yet! CurveLoopsProfile curLoopsProf = sweepProf as CurveLoopsProfile; if (curLoopsProf != null) { Stream(data, curLoopsProf); return; } FamilySymbolProfile famSymProf = sweepProf as FamilySymbolProfile; if (famSymProf != null) { Stream(data, famSymProf); return; } }
private FamilySymbol createSweepFamilySymbol(ExternalCommandData commandData, CurveElement curveElement, string filePath, bool v) { Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档 Application revitApp = commandData.Application.Application; //取得应用程序 UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 //创建一个族文档 Document familyDoc = revitDoc.Application.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2020\Family Templates\Chinese\公制常规模型.rft"); FamilySymbol profileFamilySymbol; //在族文件中载入轮廓族 using (Transaction transaction = new Transaction(familyDoc)) { transaction.Start("载入族"); string ProfilePath = filePath; //轮廓族的路径来这里输入一下 bool loadSuccess = familyDoc.LoadFamily(ProfilePath, out Family family); //在族文件中载入轮廓族 string familyName = family.Name; //获取族文件的族类型 if (loadSuccess) { //假如成功导入 //得到族模板 ElementId elementId; ISet <ElementId> symbols = family.GetFamilySymbolIds(); elementId = symbols.First(); profileFamilySymbol = familyDoc.GetElement(elementId) as FamilySymbol; } else { //假如已经导入,则通过名字找到这个族 FilteredElementCollector collector = new FilteredElementCollector(familyDoc); collector.OfClass(typeof(Family));//过滤得到文档中所有的族 IList <Element> families = collector.ToElements(); profileFamilySymbol = null; foreach (Element e in families) { Family f = e as Family; //通过名字进行筛选 if (f.Name == familyName) { profileFamilySymbol = familyDoc.GetElement(f.GetFamilySymbolIds().First()) as FamilySymbol; break; } } } transaction.Commit(); } //在族文件中拉伸放样,并进行一些参数设置 using (Transaction transaction = new Transaction(familyDoc)) { transaction.Start("内建模型"); SweepProfile sweepProfile = familyDoc.Application.Create.NewFamilySymbolProfile(profileFamilySymbol); //从轮廓族里面获取到轮廓 //在族平面内画一条线,该线的位置与在项目文件中的位置完全一致 Plane plane = curveElement.SketchPlane.GetPlane(); SketchPlane sketchPlane = SketchPlane.Create(familyDoc, plane); ModelCurve modelCurve = familyDoc.FamilyCreate.NewModelCurve(curveElement.GeometryCurve, sketchPlane); //将线设置为放样路径 ReferenceArray path = new ReferenceArray(); path.Append(modelCurve.GeometryCurve.Reference); //创建放样 Sweep sweep1 = familyDoc.FamilyCreate.NewSweep(v, path, sweepProfile, 0, ProfilePlaneLocation.Start); //设置该族文件中的空心放样可以去切割别的实例,为空心放样做准备 Parameter p = familyDoc.OwnerFamily.get_Parameter(BuiltInParameter.FAMILY_ALLOW_CUT_WITH_VOIDS); p.Set(1); transaction.Commit(); } //获取族类型 Family loadFamily = familyDoc.LoadFamily(revitDoc); //在项目中载入这个族 FamilySymbol familySymbol = revitDoc.GetElement(loadFamily.GetFamilySymbolIds().First()) as FamilySymbol; //获取到组类型 return(familySymbol); }
/// <summary> /// Create sweep with multiple loops, for /// https://forums.autodesk.com/t5/revit-api-forum/how-to-create-a-sweep-with-multiple-closed-loops-in-profile/m-p/8477617 /// </summary> public Sweep CreateSweepWithMultipleLoops( Document doc) { // Extrusion path CurveArray path = new CurveArray(); path.Append(Line.CreateBound(XYZ.Zero, new XYZ(0, 5, 0))); // Profile vertices: rectangle with two // rectangular holes XYZ p1 = new XYZ(0, 0, 0); XYZ p2 = new XYZ(10, 0, 0); XYZ p3 = new XYZ(10, 15, 0); XYZ p4 = new XYZ(0, 15, 0); XYZ a1 = new XYZ(1, 5, 0); XYZ a2 = new XYZ(3, 5, 0); XYZ a3 = new XYZ(3, 10, 0); XYZ a4 = new XYZ(1, 10, 0); XYZ b1 = new XYZ(5, 5, 0); XYZ b2 = new XYZ(7, 5, 0); XYZ b3 = new XYZ(7, 10, 0); XYZ b4 = new XYZ(5, 10, 0); CurveArrArray arrcurve = new CurveArrArray(); CurveArray curve = new CurveArray(); curve.Append(Line.CreateBound(p1, p2)); curve.Append(Line.CreateBound(p2, p3)); curve.Append(Line.CreateBound(p3, p4)); curve.Append(Line.CreateBound(p4, p1)); arrcurve.Append(curve); curve = new CurveArray(); curve.Append(Line.CreateBound(a1, a4)); curve.Append(Line.CreateBound(a4, a3)); curve.Append(Line.CreateBound(a3, a2)); curve.Append(Line.CreateBound(a2, a1)); arrcurve.Append(curve); curve = new CurveArray(); curve.Append(Line.CreateBound(b1, b4)); curve.Append(Line.CreateBound(b4, b3)); curve.Append(Line.CreateBound(b3, b2)); curve.Append(Line.CreateBound(b2, b1)); arrcurve.Append(curve); Application app = doc.Application; SweepProfile profile = app.Create .NewCurveLoopsProfile(arrcurve); Plane plane = Plane.CreateByNormalAndOrigin( XYZ.BasisZ, XYZ.Zero); SketchPlane sketchPlane = SketchPlane.Create( doc, plane); Sweep sweep = doc.FamilyCreate.NewSweep(true, path, sketchPlane, profile, 0, ProfilePlaneLocation.Start); return(sweep); }
/// <summary> /// Adds the new sweep. /// </summary> /// <param name="doc"></param> /// <param name="path"></param> /// <param name="profile"></param> /// <param name="index"></param> /// <returns></returns> public static Sweep AddSweep(this Document doc, SweepProfile profile, ReferenceArray path, int index) { return(doc.FamilyCreate.NewSweep(true, path, profile, index, ProfilePlaneLocation.Start)); }
CollectEvent(object sender, CollectorEventArgs e) { // cast the sender object to the SnoopCollector we are expecting Collector snoopCollector = sender as Collector; if (snoopCollector == null) { Debug.Assert(false); // why did someone else send us the message? return; } // see if it is a type we are responsible for Location loc = e.ObjToSnoop as Location; if (loc != null) { Stream(snoopCollector.Data(), loc); return; } GeometryObject geomObj = e.ObjToSnoop as GeometryObject; if (geomObj != null) { Stream(snoopCollector.Data(), geomObj); return; } Options opts = e.ObjToSnoop as Options; if (opts != null) { Stream(snoopCollector.Data(), opts); return; } Transform trf = e.ObjToSnoop as Transform; if (trf != null) { Stream(snoopCollector.Data(), trf); return; } BoundingBoxXYZ bndBoxXyz = e.ObjToSnoop as BoundingBoxXYZ; if (bndBoxXyz != null) { Stream(snoopCollector.Data(), bndBoxXyz); return; } MeshTriangle meshTri = e.ObjToSnoop as MeshTriangle; if (meshTri != null) { Stream(snoopCollector.Data(), meshTri); return; } Reference reference = e.ObjToSnoop as Reference; if (reference != null) { Stream(snoopCollector.Data(), reference); return; } EdgeArray edgeArray = e.ObjToSnoop as EdgeArray; // NOTE: this is needed because EdgeArrayArray will display enumerable Snoop items if (edgeArray != null) { Stream(snoopCollector.Data(), edgeArray); return; } CurveArray curveArray = e.ObjToSnoop as CurveArray; // NOTE: this is needed because CurveArrayArray will display enumerable Snoop items if (curveArray != null) { Stream(snoopCollector.Data(), curveArray); return; } Plane plane = e.ObjToSnoop as Plane; if (plane != null) { Stream(snoopCollector.Data(), plane); return; } IntersectionResult intrResult = e.ObjToSnoop as IntersectionResult; if (intrResult != null) { Stream(snoopCollector.Data(), intrResult); return; } BoundingBoxUV bboxUV = e.ObjToSnoop as BoundingBoxUV; if (bboxUV != null) { Stream(snoopCollector.Data(), bboxUV); return; } SweepProfile sweepProf = e.ObjToSnoop as SweepProfile; if (sweepProf != null) { Stream(snoopCollector.Data(), sweepProf); return; } DimensionSegment dimSeg = e.ObjToSnoop as DimensionSegment; if (dimSeg != null) { Stream(snoopCollector.Data(), dimSeg); return; } UV uv = e.ObjToSnoop as UV; if (uv != null) { Stream(snoopCollector.Data(), uv); return; } }
/// <summary> /// Adds the new family symbol. /// </summary> /// <param name="uiapp"></param> /// <param name="rfa"></param> /// <param name="profile"></param> /// <param name="path"></param> /// <param name="index"></param> /// <returns></returns> public static FamilySymbol AddFamilySymbol(this UIApplication uiapp, string rfa, SweepProfile profile, ReferenceArray path, int index) { var doc = uiapp.ActiveUIDocument.Document; var fdoc = uiapp.Application.NewFamilyDocument(rfa); fdoc.AddSweep(profile, path, index); return(doc.GetElement(fdoc.LoadFamily(doc).GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol); }