public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; Transaction t1 = new Transaction(doc, "Box"); t1.Start(); Curve c1 = Line.CreateBound(new XYZ(), new XYZ(0, 10, 0)); Curve c2 = Line.CreateBound(new XYZ(0, 10, 0), new XYZ(10, 10, 0)); Curve c3 = Line.CreateBound(new XYZ(10, 10, 0), new XYZ(10, 0, 0)); Curve c4 = Line.CreateBound(new XYZ(10, 0, 0), new XYZ(0, 0, 0)); CurveArray curveArray = new CurveArray(); curveArray.Append(c1); curveArray.Append(c2); curveArray.Append(c3); curveArray.Append(c4); CurveArrArray curveArr = new CurveArrArray(); curveArr.Append(curveArray); doc.FamilyCreate.NewExtrusion(true, curveArr, SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), XYZ.Zero)), 10); doc.FamilyManager.NewType("UCD"); t1.Commit(); return(Result.Succeeded); }
// ================================================================= // (1.2) create a simple solid by extrusion with L-shape profile // ================================================================= Extrusion createSolid() { // // (1) define a simple L-shape profile // //CurveArrArray pProflie = createBox(); CurveArrArray pProfile = createProfileLShape(); // Lab2 // // (2) create a sketch plane // // we need to know the template. If you look at the template (Metric Column.rft) and "Front" view, // you will see "Reference Plane" at "Lower Ref. Level". We are going to create an extrusion there. // findElement() is a helper function that find an element of the given type and name. see below. // ReferencePlane pRefPlane = findElement(typeof(ReferencePlane), "Reference Plane") as ReferencePlane; // need to know from the template //SketchPlane pSketchPlane = _doc.FamilyCreate.NewSketchPlane(pRefPlane.Plane); // Revit 2013 //SketchPlane pSketchPlane = SketchPlane.Create(_doc, pRefPlane.Plane); // Revit 2014 SketchPlane pSketchPlane = SketchPlane.Create(_doc, pRefPlane.GetPlane()); // Revit 2016 // (3) height of the extrusion // // same as profile, you will need to know your template. unlike UI, the alightment will not adjust the geometry. // You will need to have the exact location in order to set alignment. // Here we hard code for simplicity. 4000 is the distance between Lower and Upper Ref. Level. // as an exercise, try changing those values and see how it behaves. // double dHeight = mmToFeet(4000.0); // (4) create an extrusion here. at this point. just an box, nothing else. // bool bIsSolid = true; // as oppose to void. return _doc.FamilyCreate.NewExtrusion(bIsSolid, pProfile, pSketchPlane, dHeight); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; Document doc = uiDoc.Document; UIApplication uiApp = commandData.Application; Application app = uiApp.Application; string rfePath = @"C:\ProgramData\Autodesk\RVT 2020\Family Templates\Chinese\公制柱.rft"; Document faDoc = app.NewFamilyDocument(rfePath); Transaction trans = new Transaction(faDoc, "创建族"); trans.Start(); FamilyManager manager = faDoc.FamilyManager; FamilyParameter mfp = manager.AddParameter("材质", BuiltInParameterGroup.PG_MATERIALS, ParameterType.Material, false); CurveArrArray arrArray = GetCurves(); SketchPlane sketchPlane = GetSketchPlane(faDoc); Extrusion extrusion = faDoc.FamilyCreate.NewExtrusion(true, arrArray, sketchPlane, 4000 / 304.8); faDoc.Regenerate(); Reference topFaceReference = null; Options opt = new Options { ComputeReferences = true, DetailLevel = ViewDetailLevel.Fine }; GeometryElement geometry = extrusion.get_Geometry(opt); foreach (GeometryObject o in geometry) { if (o is Solid) { Solid s = o as Solid; foreach (Face face in s.Faces) { if (face.ComputeNormal(new UV()).IsAlmostEqualTo(new XYZ(0, 0, 1))) { topFaceReference = face.Reference; } } } } View v = GetView(faDoc); Reference r = GetTopLevel(faDoc); Dimension d = faDoc.FamilyCreate.NewAlignment(v, r, topFaceReference); d.IsLocked = true; faDoc.Regenerate(); Parameter p = extrusion.get_Parameter(BuiltInParameter.MATERIAL_ID_PARAM); manager.AssociateElementParameterToFamilyParameter(p, mfp); trans.Commit(); Family fa = faDoc.LoadFamily(doc); faDoc.Close(false); trans = new Transaction(doc, "创建柱"); trans.Start(); fa.Name = "我的柱子"; trans.Commit(); return(Result.Succeeded); }
/// <summary> /// Creates a new CurtainSystem with transaction. /// </summary> /// <param name="doc"></param> /// <param name="app"></param> /// <param name="profile"></param> /// <param name="curtainParm"></param> /// <param name="normal"></param> /// <returns></returns> public static CurtainSystem CreateCurtainSystem(this Document doc, App app, CurveArrArray profile, CurtainParm curtainParm, XYZ normal) { if (doc is null) { throw new ArgumentNullException(nameof(doc)); } if (app is null) { throw new NullReferenceException(nameof(app)); } if (profile is null) { throw new NullReferenceException(nameof(profile)); } if (normal is null) { throw new NullReferenceException(nameof(normal)); } var plane = normal.CreatePlane(XYZ.Zero); var symbolParm = new SymbolParm(curtainParm.TemplateFileName, profile, plane, 1.0); var symbol = doc.CreateExtrusionSymbol(app, symbolParm); var location = profile.ToCurveList().GetDistinctPointList().GetMinPoint(); var instParm = new InstParm(location, symbol, curtainParm.Room.Level, NonStructural); return(doc.CreateCurtainSystem(curtainParm, instParm, normal)); }
public void CreateInstance(UIApplication app) { Document familyDoc = app.Application.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2017\Family Templates\Chinese\公制常规模型.rft"); try { Transaction transaction = new Transaction(familyDoc, "Create family"); if (transaction.Start() == TransactionStatus.Started) { CurveArray curveArray = new CurveArray(); curveArray.Append(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(5, 0, 0))); curveArray.Append(Line.CreateBound(new XYZ(5, 0, 0), new XYZ(5, 5, 0))); curveArray.Append(Line.CreateBound(new XYZ(5, 5, 0), new XYZ(0, 5, 0))); curveArray.Append(Line.CreateBound(new XYZ(0, 5, 0), new XYZ(0, 0, 0))); CurveArrArray curveArrArray = new CurveArrArray(); curveArrArray.Append(curveArray); //创建一个拉伸实体 familyDoc.FamilyCreate.NewExtrusion(true, curveArrArray, SketchPlane.Create(familyDoc, Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), XYZ.Zero)), 10); //创建一个族类型 familyDoc.FamilyManager.NewType("MyNewType"); transaction.Commit(); familyDoc.SaveAs(@"C:\Users\Administrator\Desktop\MyNewFamily.rfa"); familyDoc.Close(); } } catch (Exception) { throw; } }
//本来想在这里做一个放样的,但是放样用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); }
private bool ConvertHbCurveArrArray(HbCurveArrArray hbCurveArrArray, CurveArrArray curveArrArray) { try { foreach (HbCurveArray hbCurveArray in hbCurveArrArray) { CurveArray curveArray = new CurveArray(); foreach (HbCurve hbCurve in hbCurveArray) { Curve curve = null; if (!ConvertHbCurve(hbCurve, ref curve)) { curveArrArray = null; return(false); } curveArray.Append(curve); } curveArrArray.Append(curveArray); } return(true); } catch { curveArrArray = null; return(false); } }
public static List <Face3D> ToSAM_Face3Ds(this Sketch sketch, bool flip = false) { if (sketch == null) { return(null); } CurveArrArray profile = null; try { profile = sketch.Profile; } catch { profile = null; } if (profile == null) { return(null); } List <Face3D> result = new List <Face3D>(); foreach (CurveArray curveArray in sketch.Profile) { result.Add(curveArray.ToSAM_Face3D(flip)); } return(result); }
/// <summary> /// Converts the Curve list to the CurveArrArray. /// </summary> /// <param name="curves"></param> /// <returns></returns> public static CurveArrArray ToCurveArrArray <T>(params T[] curves) where T : Curve { if (curves is null) { throw new ArgumentNullException(nameof(curves)); } if (curves.ToList().Count == 0) { throw new InvalidDataException(nameof(curves)); } var ary = new CurveArray(); foreach (var curve in curves) { ary.Append(curve); } var results = new CurveArrArray(); results.Append(ary); return(results); }
public bool isCarInsideCanPlacedRegion(CurveArray curveArray, CurveArrArray curveArrArray)//由于clipper传递后,边界线会产生误差值,这里设置为点与线的重合容差为10mm { bool isIN = isCarMiddlePointInsideCanPlacedRegion(curveArray, curveArrArray); bool _isIN = isCarFourcornerInCanPlacedRegion(curveArray, curveArrArray); return(isIN && _isIN); }
/// <summary> /// Resets the family symbol profile's location to zero point. /// </summary> /// <param name="profile"></param> /// <returns></returns> private static CurveArrArray ResetCurveArrArray(CurveArrArray profile) { if (profile == null) { throw new ArgumentNullException(nameof(profile)); } var results = new CurveArrArray(); var location = GetLocationPoint(profile); foreach (CurveArray lines in profile) { var tmpLines = new CurveArray(); foreach (var line in lines.Cast <Line>()) { var pt1 = line.GetEndPoint(0) - location; var pt2 = line.GetEndPoint(1) - location; var newLine = Line.CreateBound(pt1, pt2); tmpLines.Append(newLine); } results.Append(tmpLines); } return(results); }
/// <summary> /// Family symbol parameter. /// </summary> /// <param name="tplFileName"></param> /// <param name="profile"></param> /// <param name="plane"></param> /// <param name="end"></param> public FamilySymbolParameter(string tplFileName, CurveArrArray profile, Plane plane, double end) { TemplateFileName = tplFileName ?? throw new ArgumentNullException(nameof(tplFileName)); Profile = profile ?? throw new ArgumentNullException(nameof(profile)); Plane = plane ?? throw new ArgumentNullException(nameof(plane)); End = end; }
/// <summary> /// 由于已经是对目标region进行clipper裁剪,因此,该判断只需要处理与障碍物线圈的关系,即可。 /// </summary> public bool isCarFourcornerInCanPlacedRegion(CurveArrArray nowObstacleCurveArrArray)//由于clipper传递后,边界线会产生误差值,这里设置为点与线的重合容差为0.5feet { //四个角点不位于目标区域边界与障碍物边界之间,角点可以压线 bool isNeeded = false; //判断是否在障碍物区域外 可压线 bool isInsideObstalRegion = false; foreach (CurveArray _curevs in nowObstacleCurveArrArray) { bool _ld = _Methods.IsInsidePolygon(this.leftDown, _curevs); bool _lu = _Methods.IsInsidePolygon(this.leftUp, _curevs); bool _ru = _Methods.IsInsidePolygon(this.rightUp, _curevs); bool _rd = _Methods.IsInsidePolygon(this.rightDown, _curevs); bool _mid = _Methods.IsInsidePolygon(this.middlePoint, _curevs); if (_ld || _lu || _ru || _rd || _mid) { isInsideObstalRegion = true; break; } } if (!isInsideObstalRegion) { isNeeded = true; } return(isNeeded); }
public static List <Polygon3D> Polygon3Ds(this CurtainCell curtainCell) { CurveArrArray curveArrArray = curtainCell?.PlanarizedCurveLoops; if (curveArrArray == null) { return(null); } List <Polygon3D> result = new List <Polygon3D>(); foreach (CurveArray curveArray in curtainCell.PlanarizedCurveLoops) { Polygon3D polygon3D = curveArray?.ToSAM_Polygon3D(); if (polygon3D == null && !polygon3D.IsValid()) { continue; } Geometry.Spatial.Plane plane = polygon3D.GetPlane(); if (plane == null) { continue; } result.Add(polygon3D); } return(result); }
/// <summary> /// create the extrusions of the air handler system /// </summary> private void CreateExtrusions() { Autodesk.Revit.Creation.Application app = m_application.Create; CurveArray curves = null; CurveArrArray profile = null; Plane plane = null; SketchPlane sketchPlane = null; #region Create the cuboid extrusions for (int i = 0; i <= 2; ++i) { // create the profile curves = app.NewCurveArray(); curves.Append(Line.CreateBound(profileData[i, 0], profileData[i, 1])); curves.Append(Line.CreateBound(profileData[i, 1], profileData[i, 2])); curves.Append(Line.CreateBound(profileData[i, 2], profileData[i, 3])); curves.Append(Line.CreateBound(profileData[i, 3], profileData[i, 0])); profile = app.NewCurveArrArray(); profile.Append(curves); // create the sketch plane plane = Plane.CreateByNormalAndOrigin(sketchPlaneData[i, 0], sketchPlaneData[i, 1]); sketchPlane = SketchPlane.Create(m_document, plane); // create the extrusion extrusions[i] = f.NewExtrusion(isSolid[i], profile, sketchPlane, extrusionOffsets[i, 1]); extrusions[i].StartOffset = extrusionOffsets[i, 0]; m_combineElements.Append(extrusions[i]); } #endregion #region Create the round extrusions for (int i = 3; i <= 4; ++i) { // create the profile profile = app.NewCurveArrArray(); curves = app.NewCurveArray(); plane = Plane.CreateByNormalAndOrigin(profileData[i, 0], profileData[i, 1]); curves.Append(Arc.Create(plane, arcRadius, 0, Math.PI * 2)); profile.Append(curves); // create the sketch plane plane = Plane.CreateByNormalAndOrigin(sketchPlaneData[i, 0], sketchPlaneData[i, 1]); sketchPlane = SketchPlane.Create(m_document, plane); // create the extrusion extrusions[i] = f.NewExtrusion(isSolid[i], profile, sketchPlane, extrusionOffsets[i, 1]); extrusions[i].StartOffset = extrusionOffsets[i, 0]; m_combineElements.Append(extrusions[i]); } #endregion }
/// <summary> 转换曲线集合的格式,并进行空间变换 </summary> public static void Convert(EdgeArrayArray sourceCurves, Transform transf, out CurveArrArray targetCurves) { List <List <Curve> > llc; Convert(sourceCurves, transf, out llc); // Convert(llc, out targetCurves); }
/// <summary> /// Family symbol parameter. /// </summary> /// <param name="tplFileName"></param> /// <param name="profile"></param> /// <param name="profilePath"></param> /// <param name="location"></param> /// <param name="index"></param> public FamilySymbolParameter(string tplFileName, CurveArrArray profile, ReferenceArray profilePath, ProfilePlaneLocation location = ProfilePlaneLocation.Start, int index = 0) { TemplateFileName = tplFileName ?? throw new ArgumentNullException(nameof(tplFileName)); Profile = profile ?? throw new ArgumentNullException(nameof(profile)); SweepPath = profilePath ?? throw new ArgumentNullException(nameof(profilePath)); Location = location; Index = index; }
// =========================================== // (1.2a) create a simple L-shaped profile // =========================================== CurveArrArray createProfileLShape() { // // define a simple L-shape profile // // 5 tw 4 // +-+ // | | 3 h = height // d | +---+ 2 // +-----+ td // 0 1 // 6 w // // sizes (hard coded for simplicity) // note: these need to match reference plane. otherwise, alignment won't work. // as an exercise, try changing those values and see how it behaves. // double w = mmToFeet(600.0); // those are hard coded for simplicity here. in practice, you may want to find out from the references) double d = mmToFeet(600.0); double tw = mmToFeet(150.0); // thickness added for Lab2 double td = mmToFeet(150.0); // define vertices // const int nVerts = 6; // the number of vertices XYZ[] pts = new XYZ[] { new XYZ(-w / 2.0, -d / 2.0, 0.0), new XYZ(w / 2.0, -d / 2.0, 0.0), new XYZ(w / 2.0, (-d / 2.0) + td, 0.0), new XYZ((-w / 2.0) + tw, (-d / 2.0) + td, 0.0), new XYZ((-w / 2.0) + tw, d / 2.0, 0.0), new XYZ(-w / 2.0, d / 2.0, 0.0), new XYZ(-w / 2.0, -d / 2.0, 0.0) }; // the last one is to make the loop simple // define a loop. define individual edges and put them in a curveArray // CurveArray pLoop = _app.Create.NewCurveArray(); for (int i = 0; i < nVerts; ++i) { //Line line = _app.Create.NewLineBound(pts[i], pts[i + 1]); // Revit 2013 Line line = Line.CreateBound(pts[i], pts[i + 1]); // Revit 2014 pLoop.Append(line); } // then, put the loop in the curveArrArray as a profile // CurveArrArray pProfile = _app.Create.NewCurveArrArray(); pProfile.Append(pLoop); // if we come here, we have a profile now. return(pProfile); }
/// <summary> /// 1 过滤器筛选元素 2 通过区域锁定元素 3 使用clipper进行裁剪 /// </summary> public void RegionCalcution(Document doc, CurveArray controlRegionBaseWall) { #region 获取目标region内的元素 ElementCategoryFilter detailGroupFilter = new ElementCategoryFilter(BuiltInCategory.OST_IOSDetailGroups); //ElementCategoryFilter modelGroupFilter = new ElementCategoryFilter(BuiltInCategory.OST_IOSModelGroups); ElementCategoryFilter detailComponentsFilter = new ElementCategoryFilter(BuiltInCategory.OST_DetailComponents); ElementCategoryFilter linesFilter = new ElementCategoryFilter(BuiltInCategory.OST_Lines); ElementCategoryFilter genericModel = new ElementCategoryFilter(BuiltInCategory.OST_GenericModel); LogicalOrFilter logicalOrFilter = new LogicalOrFilter(new List <ElementFilter>() { detailGroupFilter, detailComponentsFilter, linesFilter, genericModel }); List <Element> allTarEles = (new FilteredElementCollector(doc, doc.ActiveView.Id)).WherePasses(logicalOrFilter).WhereElementIsNotElementType().ToElements().ToList(); List <Element> selEles = _Methods.GetTarlElesByRegion(doc, controlRegionBaseWall, allTarEles); #endregion #region 筛选 地库_地库外墙线圈中的目标元素 障碍物 主次道路中线 处理地库_地库外墙线退距 默认800mm #region 基于各属性进行目标元素抓取 CurveArray roadCurves = new CurveArray(); CurveArray mainRoadCurves = RegionConditionGrab(doc, selEles, out roadCurves); #endregion CurveLoop baseWallLoop = new CurveLoop(); bool isLoop = _Methods.IsCurveLoop(controlRegionBaseWall, out baseWallLoop); CurveArrArray baseWallCurveArrArray = new CurveArrArray(); XYZ normal = new XYZ(0, 0, 1); double offsetDistance = 0; bool isCounterclockwise = baseWallLoop.IsCounterclockwise(normal);//curveloop内外偏移的依据 if (isCounterclockwise) { offsetDistance = -CMD.basementWall_offset_distance; } else if (!isCounterclockwise) { offsetDistance = CMD.basementWall_offset_distance; } CurveLoop curveLoop = CurveLoop.CreateViaOffset(baseWallLoop, offsetDistance, normal); CurveArray _controlRegion = _Methods.CurveLoopToCurveArray(curveLoop); baseWallCurveArrArray.Append(_controlRegion); #endregion #region clipper最后图形处理 得到各个可停车区域region Paths basementWallPath = clipper_methods.Paths_xyzToPaths(_Methods.GetUniqueXYZFromCurves(baseWallCurveArrArray)); Paths roadRegion = HandleMainRoadSpace(mainRoadCurves, roadCurves, CMD.Wd_main, CMD.Wd); Paths canPlacedRegion = clipper_methods.RegionCropctDifference(basementWallPath, roadRegion);//得到可停车区域 this.parkingRegionsPoints = clipper_methods.PathsToPaths_xyz(canPlacedRegion); List <List <Line> > listLines = _Methods.GetListClosedtLineFromListPoints(this.parkingRegionsPoints); this.parkingCurveArrArray = _Methods.ListLinesToCurveArrArray(listLines); #endregion }
private Extrusion CreateExtrusion(Document document, SketchPlane sketchPlane) { Extrusion rectExtrusion = null; // make sure we have a family document if (true == document.IsFamilyDocument) { // define the profile for the extrusion CurveArrArray curveArrArray = new CurveArrArray(); CurveArray curveArray1 = new CurveArray(); CurveArray curveArray2 = new CurveArray(); CurveArray curveArray3 = new CurveArray(); // create a rectangular profile XYZ p0 = XYZ.Zero; XYZ p1 = new XYZ(10 / 304.8, 0, 0); XYZ p2 = new XYZ(10 / 304.8, 10 / 304.8, 0); XYZ p3 = new XYZ(0, 10 / 304.8, 0); Line line1 = Line.CreateBound(p0, p1); Line line2 = Line.CreateBound(p1, p2); Line line3 = Line.CreateBound(p2, p3); Line line4 = Line.CreateBound(p3, p0); curveArray1.Append(line1); curveArray1.Append(line2); curveArray1.Append(line3); curveArray1.Append(line4); curveArrArray.Append(curveArray1); using (Transaction ts = new Transaction(document)) { ts.Start("Create"); // create solid rectangular extrusion rectExtrusion = document.FamilyCreate.NewExtrusion(true, curveArrArray, sketchPlane, 1000 / 304.8); if (null != rectExtrusion) { // move extrusion to proper place XYZ transPoint1 = new XYZ(2000 / 304.8, 0, 0); ElementTransformUtils.MoveElement(document, rectExtrusion.Id, transPoint1); } else { throw new Exception("Create new Extrusion failed."); } ts.Commit(); } } else { throw new Exception("Please open a Family document."); } return(rectExtrusion); }
public static FamilySymbol NewSpecialShapedColumnType(Application app, Document doc, CurveArray boundary) { Document familyDoc = app.NewFamilyDocument(Properties.Settings.Default.url_columnFamily); using (Transaction tx_createFamily = new Transaction(familyDoc, "Create family")) { tx_createFamily.Start(); Plane familyGeomplane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero); SketchPlane sketch = SketchPlane.Create(familyDoc, familyGeomplane); CurveArrArray curveArrArray = new CurveArrArray(); curveArrArray.Append(boundary); // The end has to be 4000mm in metric which is in align with the Metric Column.rft Extrusion extrusion = familyDoc.FamilyCreate.NewExtrusion(true, curveArrArray, sketch, Misc.MmToFoot(4000)); familyDoc.FamilyManager.NewType("Type 0"); familyDoc.Regenerate(); Reference topFaceRef = null; Options opt = new Options(); opt.ComputeReferences = true; opt.DetailLevel = ViewDetailLevel.Fine; GeometryElement gelm = extrusion.get_Geometry(opt); foreach (GeometryObject gobj in gelm) { if (gobj is Solid) { Solid solid = gobj as Solid; foreach (Face face in solid.Faces) { if (face.ComputeNormal(UV.Zero).IsAlmostEqualTo(XYZ.BasisZ)) { topFaceRef = face.Reference; } } } } View v = GetView(familyDoc); Reference r = GetUpperRefLevel(familyDoc); Dimension d = familyDoc.FamilyCreate.NewAlignment(v, r, topFaceRef); d.IsLocked = true; tx_createFamily.Commit(); } //familyDoc.SaveAs("Special Shaped Column - " + boundary.Size.ToString() + ".rfa"); //familyDoc.Close(); Family f = familyDoc.LoadFamily(doc) as Family; FamilySymbol s = null; foreach (ElementId id in f.GetFamilySymbolIds()) { s = doc.GetElement(id) as FamilySymbol; } return(s); }
/// <summary> /// Converts the curve array set to the curve arr array. /// </summary> /// <param name="curvess"></param> /// <returns></returns> public static CurveArrArray ToCurveArrArray(this List <CurveArray> curvess) { var results = new CurveArrArray(); foreach (var curves in curvess) { results.Append(curves); } return(results); }
/// <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"; } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // UIApplication uiapp = commandData.Application; UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; // // View acView = uidoc.ActiveView; // UIView acuiview = uidoc.ActiveUiview(); //创建简单的拉升族 string templateFileName = @"C:\ProgramData\Autodesk\RVT 2019\Family Templates\Chinese\公制常规模型.rft"; Document familyDoc = commandData.Application.Application.NewFamilyDocument (templateFileName); using (Transaction ts = new Transaction(familyDoc)) { ts.Start("CreatFamily"); CurveArray curveArray = new CurveArray(); curveArray.Append(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(5 / 304.8, 0, 0))); curveArray.Append(Line.CreateBound(new XYZ(5 / 304.8, 0, 0), new XYZ(5 / 304.8, 5 / 304.8, 0))); curveArray.Append(Line.CreateBound(new XYZ(5 / 304.8, 5 / 304.8, 0), new XYZ(0, 5 / 304.8, 0))); curveArray.Append(Line.CreateBound(new XYZ(0, 5 / 304.8, 0), new XYZ(0, 0, 0))); CurveArrArray curveArrArray = new CurveArrArray(); curveArrArray.Append(curveArray); Plane plane = Plane.CreateByOriginAndBasis(XYZ.Zero, new XYZ(1, 0, 0), new XYZ(0, 1, 0)); SketchPlane sketchPlane = SketchPlane.Create(familyDoc, plane); //创建一个拉拉升体 familyDoc.FamilyCreate.NewExtrusion (true, curveArrArray, sketchPlane, 10 / 304.8); //创建一个族类型 familyDoc.FamilyManager.NewType("MyNewType"); ts.Commit(); familyDoc.SaveAs(@"D:\MyNewFamily3.rfa"); familyDoc.Close(); } TaskDialog.Show("提示", "创建成功"); return(Result.Succeeded); }
// ============================================== // (1.2b) create a simple rectangular profile // ============================================== CurveArrArray createProfileRectangle() { // // define a simple rectangular profile // // 3 2 // +---+ // | | d h = height // +---+ // 0 1 // 4 w // // sizes (hard coded for simplicity) // note: these need to match reference plane. otherwise, alignment won't work. // as an exercise, try changing those values and see how it behaves. // double w = mmToFeet(600.0); double d = mmToFeet(600.0); // define vertices // const int nVerts = 4; // the number of vertices XYZ[] pts = new XYZ[] { new XYZ(-w / 2.0, -d / 2.0, 0.0), new XYZ(w / 2.0, -d / 2.0, 0.0), new XYZ(w / 2.0, d / 2.0, 0.0), new XYZ(-w / 2.0, d / 2.0, 0.0), new XYZ(-w / 2.0, -d / 2.0, 0.0) }; // define a loop. define individual edges and put them in a curveArray // CurveArray pLoop = _app.Create.NewCurveArray(); for (int i = 0; i < nVerts; ++i) { //Line line = _app.Create.NewLineBound(pts[i], pts[i + 1]); // Revit 2013 Line line = Line.CreateBound(pts[i], pts[i + 1]); // Revit 2014 pLoop.Append(line); } // then, put the loop in the curveArrArray as a profile // CurveArrArray pProfile = _app.Create.NewCurveArrArray(); pProfile.Append(pLoop); // if we come here, we have a profile now. return(pProfile); }
/// <summary> /// Gets the family symbol's raw location, it's for moving zero point. /// </summary> /// <param name="profile"></param> /// <returns></returns> private static XYZ GetLocationPoint(CurveArrArray profile) { if (profile == null) { throw new ArgumentNullException(nameof(profile)); } var curves = profile.Cast <CurveArray>().SelectMany(s => s.Cast <Curve>()).ToList(); var pts = curves.GetDistinctPointList() .OrderBy(o => o.Z).ThenBy(o => o.Y).ThenBy(o => o.X).ToList(); return(pts.FirstOrDefault()); }
public void CreateFamilyExtrusionTest(XYZ[] pts, double height) { using (Transaction t = new Transaction(familyDoc)) { t.Start("Family Creation"); Creation.FamilyItemFactory factory = familyDoc.FamilyCreate; SketchPlane sketch = new FilteredElementCollector(familyDoc).OfClass(typeof(SketchPlane)) .First <Element>(e => e.Name.Equals("Ref. Level")) as SketchPlane; CurveArrArray curveArrArray = new CurveArrArray(); curveArrArray.Append(PolygonalCurveArray(pts)); factory.NewExtrusion(true, curveArrArray, sketch, height); t.Commit(); } }
/// <summary> </summary> public static void Convert(List <List <Curve> > sourceCurves, out CurveArrArray targetCurves) { targetCurves = new CurveArrArray(); foreach (List <Curve> curves in sourceCurves) { CurveArray ca = new CurveArray(); foreach (Curve c in curves) { ca.Append(c); } targetCurves.Append(ca); } }
/// <summary> /// Converts the CurveArray list to the CurveLoop list. /// </summary> /// <param name="curveArrays"></param> /// <returns></returns> public static List <CurveLoop> ToCurveLoopList(params CurveArray[] curveArrays) { if (curveArrays is null) { throw new ArgumentNullException(nameof(curveArrays)); } var results = new CurveArrArray(); foreach (var curves in curveArrays) { results.Append(curves); } return(results.ToCurveLoopList()); }
/// <summary> /// Converts the CurveLoop list to the CurveArrArray. /// </summary> /// <param name="curveLoops"></param> /// <returns></returns> public static CurveArrArray ToCurveArrArray(this IEnumerable <CurveLoop> curveLoops) { if (curveLoops is null) { throw new ArgumentNullException(nameof(curveLoops)); } var results = new CurveArrArray(); foreach (var curveLoop in curveLoops) { results.Append(curveLoop.ToCurveArray()); } return(results); }
private void SetConstraints(Document familyDoc, Extrusion extrusion) { try { CurveArrArray curvesArr = new CurveArrArray(); curvesArr = extrusion.Sketch.Profile; foreach (CurveArray ca in curvesArr) { CurveArrayIterator itor = ca.ForwardIterator(); itor.Reset(); itor.MoveNext(); Line l = itor.Current as Line; _rightCon.Append(l.Reference); itor.MoveNext(); l = itor.Current as Line; _topCon.Append(l.Reference); itor.MoveNext(); l = itor.Current as Line; _leftCon.Append(l.Reference); l = itor.Current as Line; _botCon.Append(l.Reference); } ReferenceArrayArray conArray = new ReferenceArrayArray(); conArray.Append(_rightCon); conArray.Append(_topCon); conArray.Append(_leftCon); conArray.Append(_botCon); ConstructConstraint(familyDoc, _rightCon); ConstructConstraint(familyDoc, _topCon); ConstructConstraint(familyDoc, _leftCon); } catch (Exception ex) { TaskDialog.Show("Constraint Error", ex.Message); } }
private Extrusion CreateExtrusion(Document familyDoc) { try { Plane plane = _uiapp.Application.Create.NewPlane(new XYZ(0.0, 0.0, 1.0), new XYZ(0.0, 0.0, 0.0) ); SketchPlane s_plane = familyDoc.FamilyCreate.NewSketchPlane(plane); ReferenceArray ra = new ReferenceArray(); CurveArray profile = new CurveArray(); CurveArrArray caa = new CurveArrArray(); int i = 0; while (i < 3) { profile.Append(familyDoc.Application.Create.NewLineBound(_vert[i],_vert[i + 1])); ++i; } profile.Append(familyDoc.Application.Create.NewLineBound(_vert[i], _vert[i - i])); caa.Append(profile); Extrusion extrusion = familyDoc.FamilyCreate.NewExtrusion(true, caa, s_plane, 10.0); Line line = familyDoc.Application.Create.NewLine(_vert[0], _vert[1], true); ConstructParam(familyDoc, _width, line, "Width"); line = familyDoc.Application.Create.NewLine(_vert[1], _vert[2], true); ConstructParam(familyDoc, _height, line, "Height"); SetFormula(familyDoc); return extrusion; } catch (Exception ex) { TaskDialog.Show("Extrusion Error", ex.Message); return null; } }
private void SetConstraints(Document familyDoc, Extrusion extrusion) { CurveArrArray curvesArr = new CurveArrArray(); curvesArr = extrusion.Sketch.Profile; foreach (CurveArray ca in curvesArr) { CurveArrayIterator itor = ca.ForwardIterator(); itor.Reset(); itor.MoveNext(); Line l = itor.Current as Line; _rightCon.Append(l.Reference); itor.MoveNext(); l = itor.Current as Line; _topCon.Append(l.Reference); itor.MoveNext(); l = itor.Current as Line; _leftCon.Append(l.Reference); l = itor.Current as Line; _botCon.Append(l.Reference); } ReferenceArrayArray conArray = new ReferenceArrayArray(); conArray.Append(_rightCon); conArray.Append(_topCon); conArray.Append(_leftCon); conArray.Append(_botCon); //Line line = familyDoc.Application.Create.NewLine(_vert[0], _vert[1], true); ConstructConstraint(familyDoc, _rightCon); //line = familyDoc.Application.Create.NewLine(_vert[1], _vert[2], true); ConstructConstraint(familyDoc, _topCon); //line = familyDoc.Application.Create.NewLine(_vert[2], _vert[3], true); ConstructConstraint(familyDoc, _leftCon); //line = familyDoc.Application.Create.NewLine(_vert[3], _vert[0], true); //ConstructConstraint(familyDoc, _botCon, line); }
/// <summary> /// The implementation of CreateFrame() /// </summary> public override void CreateFrame() { SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); //get the wall in the document and retrieve the exterior face List<Wall> walls = Utility.GetElements<Wall>(m_application, m_document); Face exteriorWallFace = GeoHelper.GetWallFace(walls[0], m_rightView, true); //create sash referenceplane and exterior referenceplane CreateRefPlane refPlaneCreator = new CreateRefPlane(); if(m_sashPlane==null) m_sashPlane = refPlaneCreator.Create(m_document, m_centerPlane, m_rightView, new Autodesk.Revit.DB.XYZ (0, m_wallThickness / 2 - m_windowInset, 0), new Autodesk.Revit.DB.XYZ (0, 0, 1), "Sash"); if (m_exteriorPlane==null) m_exteriorPlane = refPlaneCreator.Create(m_document, m_centerPlane, m_rightView, new Autodesk.Revit.DB.XYZ (0, m_wallThickness / 2, 0), new Autodesk.Revit.DB.XYZ (0, 0, 1), "MyExterior"); m_document.Regenerate(); //add dimension between sash reference plane and wall face,and add parameter "Window Inset",label the dimension with window-inset parameter Dimension windowInsetDimension = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, exteriorWallFace); FamilyParameter windowInsetPara = m_familyManager.AddParameter("Window Inset", BuiltInParameterGroup.INVALID, ParameterType.Length, false); m_familyManager.Set(windowInsetPara, m_windowInset); windowInsetDimension.Label = windowInsetPara; //create the exterior frame double frameCurveOffset1 = 0.075; CurveArray curveArr1 = m_extrusionCreator.CreateRectangle(m_width / 2, -m_width / 2, m_sillHeight + m_height, m_sillHeight, 0); CurveArray curveArr2 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr1, frameCurveOffset1); CurveArrArray curveArrArray1 = new CurveArrArray(); curveArrArray1.Append(curveArr1); curveArrArray1.Append(curveArr2); Extrusion extFrame = m_extrusionCreator.NewExtrusion(curveArrArray1, m_sashPlane, m_wallThickness / 2 + m_wallThickness/12, -m_windowInset); extFrame.SetVisibility( CreateVisibility()); m_document.Regenerate(); //add alignment between wall face and exterior frame face Face exteriorExtrusionFace1=GeoHelper.GetExtrusionFace(extFrame,m_rightView,true); Face interiorExtrusionFace1 = GeoHelper.GetExtrusionFace(extFrame,m_rightView,false); CreateAlignment alignmentCreator = new CreateAlignment(m_document); alignmentCreator.AddAlignment(m_rightView,exteriorWallFace,exteriorExtrusionFace1); //add dimension between sash referenceplane and exterior frame face and lock the dimension Dimension extFrameWithSashPlane = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, interiorExtrusionFace1); extFrameWithSashPlane.IsLocked = true; m_document.Regenerate(); //create the interior frame double frameCurveOffset2 = 0.125; CurveArray curveArr3 = m_extrusionCreator.CreateRectangle(m_width / 2, -m_width / 2, m_sillHeight + m_height, m_sillHeight, 0); CurveArray curveArr4 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr3, frameCurveOffset2); m_document.Regenerate(); CurveArrArray curveArrArray2 = new CurveArrArray(); curveArrArray2.Append(curveArr3); curveArrArray2.Append(curveArr4); Extrusion intFrame = m_extrusionCreator.NewExtrusion(curveArrArray2, m_sashPlane, m_wallThickness - m_windowInset, m_wallThickness / 2 + m_wallThickness / 12); intFrame.SetVisibility( CreateVisibility()); m_document.Regenerate(); //add alignment between interior face of wall and interior frame face Face interiorWallFace = GeoHelper.GetWallFace(walls[0], m_rightView, false); Face interiorExtrusionFace2 = GeoHelper.GetExtrusionFace(intFrame, m_rightView, false); Face exteriorExtrusionFace2 = GeoHelper.GetExtrusionFace(intFrame, m_rightView, true); alignmentCreator.AddAlignment(m_rightView, interiorWallFace, interiorExtrusionFace2); //add dimension between sash referenceplane and interior frame face and lock the dimension Dimension intFrameWithSashPlane = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, exteriorExtrusionFace2); intFrameWithSashPlane.IsLocked = true; //create the sill frame CurveArray sillCurs = m_extrusionCreator.CreateRectangle(m_width / 2, -m_width / 2, m_sillHeight + frameCurveOffset1, m_sillHeight, 0); CurveArrArray sillCurveArray = new CurveArrArray(); sillCurveArray.Append(sillCurs); Extrusion sillFrame= m_extrusionCreator.NewExtrusion(sillCurveArray, m_sashPlane, -m_windowInset, -m_windowInset - 0.1); m_document.Regenerate(); //add alignment between wall face and sill frame face Face sillExtFace = GeoHelper.GetExtrusionFace(sillFrame, m_rightView, false); alignmentCreator.AddAlignment(m_rightView, sillExtFace, exteriorWallFace); m_document.Regenerate(); //set subcategories of the frames if (m_frameCat != null) { extFrame.Subcategory = m_frameCat; intFrame.Subcategory = m_frameCat; sillFrame.Subcategory = m_frameCat; } subTransaction.Commit(); }
/// <summary> /// The method is used to create extrusion using FamilyItemFactory.NewExtrusion() /// </summary> /// <param name="curveArrArray">the CurveArrArray parameter</param> /// <param name="workPlane">the reference plane is used to create SketchPlane</param> /// <param name="startOffset">the extrusion's StartOffset property</param> /// <param name="endOffset">the extrusion's EndOffset property</param> /// <returns>the new extrusion</returns> public Extrusion NewExtrusion(CurveArrArray curveArrArray, ReferencePlane workPlane, double startOffset, double endOffset) { Extrusion rectExtrusion = null; try { SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); SketchPlane sketch = m_familyCreator.NewSketchPlane(workPlane.Plane); rectExtrusion = m_familyCreator.NewExtrusion(true, curveArrArray, sketch, Math.Abs(endOffset - startOffset)); rectExtrusion.StartOffset = startOffset; rectExtrusion.EndOffset = endOffset; subTransaction.Commit(); return rectExtrusion; } catch { return null; } }
/// <summary> /// The implementation of CreateGlass(), creating the Window Glass Solid Geometry /// </summary> public override void CreateGlass() { double frameCurveOffset1 = 0.075; double frameDepth = m_wallThickness - 0.15; double sashCurveOffset = 0.075; double sashDepth = (frameDepth - m_windowInset) / 2; double glassDepth = 0.05; double glassOffsetSash = 0.05; //from the exterior of the sash //create first glass SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); CurveArray curveArr9 = m_extrusionCreator.CreateRectangle(m_width / 2 - frameCurveOffset1 - sashCurveOffset, -m_width / 2 + frameCurveOffset1 + sashCurveOffset, m_sillHeight + m_height / 2 - sashCurveOffset / 2, m_sillHeight + frameCurveOffset1 + sashCurveOffset, 0); m_document.Regenerate(); CurveArrArray curveArrArray5 = new CurveArrArray(); curveArrArray5.Append(curveArr9); Extrusion glass1 = m_extrusionCreator.NewExtrusion(curveArrArray5, m_sashPlane, sashDepth + glassOffsetSash + glassDepth, sashDepth + glassOffsetSash); m_document.Regenerate(); glass1.SetVisibility(CreateVisibility()); m_document.Regenerate(); Face eglassFace1 = GeoHelper.GetExtrusionFace(glass1, m_rightView, true); Face iglassFace1 = GeoHelper.GetExtrusionFace(glass1, m_rightView, false); Dimension glassDim1 = m_dimensionCreator.AddDimension(m_rightView, eglassFace1, iglassFace1); glassDim1.IsLocked = true; Dimension glass1WithSashPlane = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, eglassFace1); glass1WithSashPlane.IsLocked = true; //create the second glass CurveArray curveArr10 = m_extrusionCreator.CreateRectangle(m_width / 2 - frameCurveOffset1 - sashCurveOffset, -m_width / 2 + frameCurveOffset1 + sashCurveOffset, m_sillHeight + m_height - frameCurveOffset1 - sashCurveOffset, m_sillHeight + m_height / 2 + sashCurveOffset / 2, 0); CurveArrArray curveArrArray6 = new CurveArrArray(); curveArrArray6.Append(curveArr10); Extrusion glass2 = m_extrusionCreator.NewExtrusion(curveArrArray6, m_sashPlane, glassOffsetSash + glassDepth, glassOffsetSash); m_document.Regenerate(); glass2.SetVisibility(CreateVisibility()); m_document.Regenerate(); Face eglassFace2 = GeoHelper.GetExtrusionFace(glass2, m_rightView, true); Face iglassFace2 = GeoHelper.GetExtrusionFace(glass2, m_rightView, false); Dimension glassDim2 = m_dimensionCreator.AddDimension(m_rightView, eglassFace2, iglassFace2); glassDim2.IsLocked = true; Dimension glass2WithSashPlane = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, eglassFace2); glass2WithSashPlane.IsLocked = true; //set category if (null != m_glassCat) { glass1.Subcategory = m_glassCat; glass2.Subcategory = m_glassCat; } Autodesk.Revit.DB.ElementId id = new ElementId(m_glassMatID); glass1.ParametersMap.get_Item("Material").Set(id); glass2.ParametersMap.get_Item("Material").Set(id); subTransaction.Commit(); }
/// <summary> /// Create an extrusion from a given thickness /// and list of XYZ points defined in millimetres /// in the given family document, which must /// contain a sketch plane named "Ref. Level". /// </summary> Extrusion CreateExtrusion( Document doc, List<XYZ> pts, double thickness) { Autodesk.Revit.Creation.FamilyItemFactory factory = doc.FamilyCreate; SketchPlane sketch = FindElement( doc, typeof( SketchPlane ), "Ref. Level" ) as SketchPlane; CurveArrArray curveArrArray = new CurveArrArray(); curveArrArray.Append( CreateProfile( pts ) ); double extrusionHeight = MmToFoot( thickness ); return factory.NewExtrusion( true, curveArrArray, sketch, extrusionHeight ); }
private static CurveArrArray ConvertFSharpListListToCurveArrayArray(FSharpList<Value> lstlst) { CurveArrArray crvArrArr = new CurveArrArray(); foreach (Value v in lstlst) { CurveArray crvArr = new CurveArray(); FSharpList<Value> lst = (v as Value.List).Item; AddCurvesToArray(crvArr, lst); crvArrArr.Append(crvArr); } return crvArrArr; }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { Application app = commandData.Application.Application; string filename = Path.Combine( _folder, _template ); Document familyDoc = app.NewFamilyDocument( filename ); Family family = familyDoc.OwnerFamily; Autodesk.Revit.Creation.FamilyItemFactory factory = familyDoc.FamilyCreate; Extrusion extrusion = null; using( Transaction trans = new Transaction( familyDoc ) ) { trans.Start( "Create Extrusion" ); XYZ arcCenter = new XYZ( 0.0, 3.0, -2.0 ); // Get the "left" view View view = GetView( ViewType.Elevation, XYZ.BasisY.Negate(), XYZ.BasisZ, familyDoc ); // 2D offsets from view 'left' XYZ xOffset = new XYZ( 0.0, 10.0, 0.0 ); XYZ yOffset = new XYZ( 0.0, 0.0, -10.0 ); //################## Reference planes ################################ // Origin's reference planes ReferencePlane referencePlaneOriginX = factory.NewReferencePlane( XYZ.BasisX, XYZ.Zero, XYZ.BasisY, view ); referencePlaneOriginX.Name = "ReferencePlane_OriginX"; referencePlaneOriginX.Pinned = true; ReferencePlane referencePlaneOriginY = factory.NewReferencePlane( XYZ.BasisZ, XYZ.Zero, -XYZ.BasisX, view ); referencePlaneOriginY.Name = "ReferencePlane_OriginY"; referencePlaneOriginY.Pinned = true; // Reference planes the extruded arc should stick to ReferencePlane referencePlaneX = factory.NewReferencePlane( XYZ.BasisX + yOffset, XYZ.Zero + yOffset, XYZ.BasisY, view ); referencePlaneX.Name = "ReferencePlane_X"; ReferencePlane referencePlaneY = factory.NewReferencePlane( XYZ.BasisZ + xOffset, XYZ.Zero + xOffset, -XYZ.BasisX, view ); referencePlaneY.Name = "ReferencePlane_Y"; familyDoc.Regenerate(); //################## Create dimensions ############################### // Dimension x ReferenceArray refArrayX = new ReferenceArray(); refArrayX.Append( referencePlaneX.GetReference() ); refArrayX.Append( referencePlaneOriginX.GetReference() ); Line lineX = Line.CreateUnbound( arcCenter, XYZ.BasisZ ); Dimension dimensionX = factory.NewDimension( view, lineX, refArrayX ); // Dimension y ReferenceArray refArrayY = new ReferenceArray(); refArrayY.Append( referencePlaneY.GetReference() ); refArrayY.Append( referencePlaneOriginY.GetReference() ); Line lineY = Line.CreateUnbound( arcCenter, XYZ.BasisY ); Dimension dimensionY = factory.NewDimension( view, lineY, refArrayY ); familyDoc.Regenerate(); //################## Create arc ###################################### double arcRadius = 1.0; Arc arc = Arc.Create( XYZ.Zero + xOffset + yOffset, arcRadius, 0.0, 2 * Math.PI, XYZ.BasisZ, XYZ.BasisY.Negate() ); CurveArray curves = new CurveArray(); curves.Append( arc ); CurveArrArray profile = new CurveArrArray(); profile.Append( curves ); Plane plane = new Plane( XYZ.BasisX.Negate(), arcCenter ); SketchPlane sketchPlane = SketchPlane.Create( familyDoc, plane ); Debug.WriteLine( "Origin: " + sketchPlane.GetPlane().Origin ); Debug.WriteLine( "Normal: " + sketchPlane.GetPlane().Normal ); Debug.WriteLine( "XVec: " + sketchPlane.GetPlane().XVec ); Debug.WriteLine( "YVec: " + sketchPlane.GetPlane().YVec ); extrusion = factory.NewExtrusion( true, profile, sketchPlane, 10 ); familyDoc.Regenerate(); //################## Add family parameters ########################### FamilyManager fmgr = familyDoc.FamilyManager; FamilyParameter paramX = fmgr.AddParameter( "X", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, true ); dimensionX.FamilyLabel = paramX; FamilyParameter paramY = fmgr.AddParameter( "Y", BuiltInParameterGroup.PG_GEOMETRY, ParameterType.Length, true ); dimensionY.FamilyLabel = paramY; // Set their values FamilyType familyType = fmgr.NewType( "Standard" ); fmgr.Set( paramX, 10 ); fmgr.Set( paramY, 10 ); trans.Commit(); } // Save it to inspect SaveAsOptions opt = new SaveAsOptions(); opt.OverwriteExistingFile = true; filename = Path.Combine( Path.GetTempPath(), "test.rfa" ); familyDoc.SaveAs( filename, opt ); return Result.Succeeded; }
/// <summary> /// The implementation of CreateSash(),and creating the Window Sash Solid Geometry /// </summary> public override void CreateSash() { double frameCurveOffset1 = 0.075; double frameDepth = 7*m_wallThickness/12+m_windowInset; double sashCurveOffset = 0.075; double sashDepth = (frameDepth - m_windowInset) / 2; //get the exterior view and sash referenceplane which are used in this process Autodesk.Revit.DB.View exteriorView = Utility.GetViewByName("Exterior", m_application, m_document); SubTransaction subTransaction = new SubTransaction(m_document); subTransaction.Start(); //add a middle reference plane between the top referenceplane and sill referenceplane CreateRefPlane refPlaneCreator = new CreateRefPlane(); ReferencePlane middlePlane=refPlaneCreator.Create(m_document, m_topPlane, exteriorView, new Autodesk.Revit.DB.XYZ (0, 0, -m_height / 2), new Autodesk.Revit.DB.XYZ (0, -1, 0), "tempmiddle"); m_document.Regenerate(); //add dimension between top, sill, and middle reference plane, make the dimension segment equal Dimension dim = m_dimensionCreator.AddDimension(exteriorView, m_topPlane, m_sillPlane, middlePlane); dim.AreSegmentsEqual = true; //create first sash CurveArray curveArr5 = m_extrusionCreator.CreateRectangle(m_width / 2 - frameCurveOffset1, -m_width / 2 + frameCurveOffset1, m_sillHeight + m_height / 2 + sashCurveOffset / 2, m_sillHeight + frameCurveOffset1, 0); CurveArray curveArr6 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr5, sashCurveOffset); m_document.Regenerate(); CurveArrArray curveArrArray3 = new CurveArrArray(); curveArrArray3.Append(curveArr5); curveArrArray3.Append(curveArr6); Extrusion sash1 = m_extrusionCreator.NewExtrusion(curveArrArray3, m_sashPlane, 2 * sashDepth, sashDepth); m_document.Regenerate(); Face esashFace1=GeoHelper.GetExtrusionFace(sash1,m_rightView,true); Face isashFace1=GeoHelper.GetExtrusionFace(sash1,m_rightView,false); Dimension sashDim1=m_dimensionCreator.AddDimension(m_rightView,esashFace1,isashFace1); sashDim1.IsLocked = true; Dimension sashWithPlane1 = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, isashFace1); sashWithPlane1.IsLocked = true; sash1.SetVisibility(CreateVisibility()); //create second sash CurveArray curveArr7 = m_extrusionCreator.CreateRectangle(m_width / 2 - frameCurveOffset1, -m_width / 2 + frameCurveOffset1, m_sillHeight + m_height - frameCurveOffset1, m_sillHeight + m_height / 2 - sashCurveOffset / 2, 0); CurveArray curveArr8 = m_extrusionCreator.CreateCurveArrayByOffset(curveArr7, sashCurveOffset); m_document.Regenerate(); CurveArrArray curveArrArray4 = new CurveArrArray(); curveArrArray4.Append(curveArr7); curveArrArray4.Append(curveArr8); Extrusion sash2 = m_extrusionCreator.NewExtrusion(curveArrArray4, m_sashPlane, sashDepth, 0); sash2.SetVisibility(CreateVisibility()); m_document.Regenerate(); Face esashFace2 = GeoHelper.GetExtrusionFace(sash2, m_rightView, true); Face isashFace2 = GeoHelper.GetExtrusionFace(sash2, m_rightView, false); Dimension sashDim2 = m_dimensionCreator.AddDimension(m_rightView, esashFace2, isashFace2); sashDim2.IsLocked = true; Dimension sashWithPlane2 = m_dimensionCreator.AddDimension(m_rightView, m_sashPlane, isashFace2); m_document.Regenerate(); sashWithPlane2.IsLocked = true; //set category of the sash extrusions if (m_frameCat != null) { sash1.Subcategory = m_frameCat; sash2.Subcategory = m_frameCat; } Autodesk.Revit.DB.ElementId id = new ElementId(m_sashMatID); sash1.ParametersMap.get_Item("Material").Set(id); sash2.ParametersMap.get_Item("Material").Set(id); subTransaction.Commit(); }
/// <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 ); }