public void getSubElement() { UIDocument uiDoc = this.ActiveUIDocument; Document doc = uiDoc.Document; View myView = doc.ActiveView; Reference myRef = uiDoc.Selection.PickObject(ObjectType.Element, "Pick a rebar..."); Rebar myRebar = doc.GetElement(myRef) as Rebar; TaskDialog.Show("abc", "Has: " + myRebar.NumberOfBarPositions.ToString()); ReferenceArray myRefAr = new ReferenceArray(); int myNumberRebar = (int)myRebar.NumberOfBarPositions; if (myNumberRebar > 1) { for (int i = 0; i < myNumberRebar; i++) { List <Curve> centerLines = myRebar.GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, 0) as List <Curve>; foreach (Curve myCurBar in centerLines) { if (myCurBar is Line) { Line myLine = myCurBar as Line; Reference myRefLine = myLine.Reference; myRefAr.Append(myRefLine); break; } } } } TaskDialog.Show("abc", myRefAr.Size.ToString()); setCurrentViewAsWorkPlan(); XYZ myDimPoint_1 = uiDoc.Selection.PickPoint("Pick Point To Place Dimension...."); XYZ myDimPoint_2 = new XYZ(myDimPoint_1.X + 5, myDimPoint_1.Y, myDimPoint_1.Z); Line dimLine = Line.CreateBound(myDimPoint_1, myDimPoint_2); using (Transaction trans = new Transaction(doc, "Create linear Dimension")) { trans.Start(); Dimension myDim = doc.Create.NewDimension(doc.ActiveView, dimLine, myRefAr); trans.Commit(); } }
/// <summary> /// Get Transformed Centerline curves at position. /// This method extracts the centerlinecurves for a rebar set at a given index and transforms them to the correct position. /// </summary> /// <param name="rebar"></param> /// <param name="barPosIndex"></param> /// <returns></returns> public static IList<Curve> GetTransformedCenterLineCurvesAtPostition(Rebar rebar, int barPosIndex) { RebarShapeDrivenAccessor sda = rebar.GetShapeDrivenAccessor(); Transform transform = sda.GetBarPositionTransform(barPosIndex); IList<Curve> curves = rebar.GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, barPosIndex); IList<Curve> transformedCurves = new List<Curve>(); foreach (Curve curve in curves) { transformedCurves.Add(curve.CreateTransformed(transform)); } return transformedCurves; }
public static Dictionary <string, object> getRebarCenterLineCurve( List <Revit.Elements.Element> rebar, bool adjustForSelfIntersection = false, bool suppressHooks = true, bool suppressBendRadius = true, bool multiplanarOption = true ) { string message = ""; Document doc = DocumentManager.Instance.CurrentDBDocument; DynaFunctions f = new DynaFunctions(); //UIApplication uiapp = DocumentManager.Instance.CurrentUIApplication; //Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; //UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument; List <Autodesk.DesignScript.Geometry.PolyCurve> curves = new List <Autodesk.DesignScript.Geometry.PolyCurve>(); MultiplanarOption mp = MultiplanarOption.IncludeOnlyPlanarCurves; foreach (Revit.Elements.Element r in rebar) { switch (multiplanarOption) { case true: mp = MultiplanarOption.IncludeOnlyPlanarCurves; break; case false: mp = MultiplanarOption.IncludeAllMultiplanarCurves; break; } Autodesk.Revit.DB.Element el = doc.GetElement(r.UniqueId.ToString()); Rebar reb = el as Rebar; IList <Curve> sketch = reb.GetCenterlineCurves(adjustForSelfIntersection, suppressHooks, suppressBendRadius, mp, 0); List <Autodesk.DesignScript.Geometry.Curve> crv = new List <Autodesk.DesignScript.Geometry.Curve>(); foreach (Curve s in sketch) { Autodesk.DesignScript.Geometry.Curve c = Revit.GeometryConversion.RevitToProtoCurve.ToProtoType(s, true); crv.Add(c); } Autodesk.DesignScript.Geometry.PolyCurve pc = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(crv); curves.Add(pc); } return(new Dictionary <string, object> { { "polyCurves", curves }, //{ "Message", message }, }); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document doc = commandData.Application.ActiveUIDocument.Document; Selection sel = commandData.Application.ActiveUIDocument.Selection; if (sel.GetElementIds().Count == 0) { message = "Выберите арматурные стержни"; return(Result.Failed); } Rebar bar = doc.GetElement(sel.GetElementIds().First()) as Rebar; if (bar == null) { message = "Выберите арматурные стержни"; return(Result.Failed); } #if R2017 XYZ normal = bar.Normal; #else RebarShapeDrivenAccessor acc = bar.GetShapeDrivenAccessor(); XYZ normal = acc.Normal; #endif RebarBarType barType = doc.GetElement(bar.GetTypeId()) as RebarBarType; int rebarStyleNumber = bar.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_STYLE).AsInteger(); RebarStyle rebarStyle = (RebarStyle)rebarStyleNumber; RebarHookType hookTypeStart = null; ElementId hookStartTypeId = bar.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_START_TYPE).AsElementId(); if (hookStartTypeId != null) { hookTypeStart = doc.GetElement(hookStartTypeId) as RebarHookType; } RebarHookType hookTypeEnd = null; ElementId hookEndTypeId = bar.get_Parameter(BuiltInParameter.REBAR_ELEM_HOOK_END_TYPE).AsElementId(); if (hookEndTypeId != null) { hookTypeEnd = doc.GetElement(hookEndTypeId) as RebarHookType; } RebarBendData rbd = bar.GetBendData(); RebarHookOrientation hookOrient0 = rbd.HookOrient0; RebarHookOrientation hookOrient1 = rbd.HookOrient1; Element host = doc.GetElement(bar.GetHostId()); List <Curve> curves = bar.GetCenterlineCurves(false, true, true, MultiplanarOption.IncludeOnlyPlanarCurves, 0).ToList(); int barsCount = bar.NumberOfBarPositions; List <ElementId> newRebarIds = new List <ElementId>(); using (Transaction tr = new Transaction(doc)) { tr.Start("Explode rebar set"); for (int i = 0; i < barsCount; i++) { #if R2017 Transform barOffset = bar.GetBarPositionTransform(i); #else Transform barOffset = acc.GetBarPositionTransform(i); #endif XYZ offset = barOffset.Origin; Rebar newRebar = Rebar.CreateFromCurves(doc, rebarStyle, barType, hookTypeStart, hookTypeEnd, host, normal, curves, hookOrient0, hookOrient1, true, false); doc.Regenerate(); ElementTransformUtils.MoveElement(doc, newRebar.Id, offset); newRebarIds.Add(newRebar.Id); } doc.Delete(bar.Id); tr.Commit(); } sel.SetElementIds(newRebarIds); return(Result.Succeeded); }
private void Stream( ArrayList data, Rebar rebar ) { data.Add( new Snoop.Data.ClassSeparator( typeof( Rebar ) ) ); data.Add( new Snoop.Data.ElementId( "Bar type", rebar.GetTypeId(), rebar.Document ) ); data.Add( new Snoop.Data.ElementId( "Rebar shape", rebar.RebarShapeId, rebar.Document ) ); data.Add( new Snoop.Data.ElementId( "Host", rebar.GetHostId(), rebar.Document ) ); data.Add( new Snoop.Data.Object( "Distribution path", rebar.GetDistributionPath() ) ); data.Add( new Snoop.Data.Enumerable( "GetCenterlineCurves(false, false, false)", rebar.GetCenterlineCurves( false, false, false ) ) ); data.Add( new Snoop.Data.String( "LayoutRule", rebar.LayoutRule.ToString() ) ); if( rebar.LayoutRule != RebarLayoutRule.Single ) { data.Add( new Snoop.Data.Double( "Distribution path length", rebar.ArrayLength ) ); data.Add( new Snoop.Data.Int( "Quantity", rebar.Quantity ) ); data.Add( new Snoop.Data.Int( "NumberOfBarPositions", rebar.NumberOfBarPositions ) ); data.Add( new Snoop.Data.Double( "MaxSpacing", rebar.MaxSpacing ) ); } //TF data.Add( new Snoop.Data.Object( "ConstraintsManager", rebar.GetRebarConstraintsManager() ) ); //TFEND }
private void Stream( ArrayList data, Rebar rebar ) { data.Add( new Snoop.Data.ClassSeparator( typeof( Rebar ) ) ); data.Add( new Snoop.Data.ElementId( "Bar type", rebar.GetTypeId(), rebar.Document ) ); data.Add( new Snoop.Data.ElementId( "Rebar shape", rebar.RebarShapeId, rebar.Document ) ); data.Add( new Snoop.Data.ElementId( "Host", rebar.GetHostId(), rebar.Document ) ); data.Add( new Snoop.Data.Object( "Distribution path", rebar.GetDistributionPath() ) ); data.Add( new Snoop.Data.Enumerable( "GetCenterlineCurves(false, false, false)", rebar.GetCenterlineCurves( false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, 0 ) ) ); data.Add( new Snoop.Data.String( "LayoutRule", rebar.LayoutRule.ToString() ) ); if( rebar.LayoutRule != RebarLayoutRule.Single ) { data.Add( new Snoop.Data.Double( "Distribution path length", rebar.ArrayLength ) ); data.Add( new Snoop.Data.Int( "Quantity", rebar.Quantity ) ); data.Add( new Snoop.Data.Int( "NumberOfBarPositions", rebar.NumberOfBarPositions ) ); data.Add( new Snoop.Data.Double( "MaxSpacing", rebar.MaxSpacing ) ); data.Add( new Snoop.Data.Bool( "BarsOnNormalSide", rebar.BarsOnNormalSide ) ); } data.Add( new Snoop.Data.String( "ScheduleMark", rebar.ScheduleMark ) ); data.Add( new Snoop.Data.Double( "Volume", rebar.Volume ) ); data.Add( new Snoop.Data.Double( "TotalLength", rebar.TotalLength ) ); data.Add( new Snoop.Data.Object( "Normal", rebar.Normal ) ); //TF data.Add( new Snoop.Data.Object( "ConstraintsManager", rebar.GetRebarConstraintsManager() ) ); //TFEND // Bending data data.Add( new Snoop.Data.Object( "Bending Data", rebar.GetBendData() ) ); // Hook information addHookInformation2Rebar( data, rebar, 0 ); addHookInformation2Rebar( data, rebar, 1 ); }
private List <ElementId> copyRebarByDistance_Update_MaxSpace(Document doc, Rebar myRebar, Dictionary <double, double> myDicDisNum) { List <double> myDistances = myDicDisNum.Keys.ToList(); myDistances.Sort(); List <double> myListNum = new List <double>(); foreach (double key in myDistances) { myListNum.Add(myDicDisNum[key]); } //Get Id rebar ElementId myIdRebar = myRebar.Id; //Get Id Beam ElementId myIdBeam = myRebar.GetHostId(); Element myBeam = doc.GetElement(myIdBeam); if (myBeam.Category.Name != "Structural Framing") { TaskDialog.Show("Loi!", "Hay chon 1 rebar co host la 1 Structural Framing"); return(null); } else { LocationCurve cur = myBeam.Location as LocationCurve; Line lineCur = cur.Curve as Line; XYZ p1 = lineCur.GetEndPoint(0); XYZ q = lineCur.GetEndPoint(1); XYZ v = q - p1; double lengCurLine = v.GetLength(); XYZ p = p1 - 0.1 * v; List <XYZ> myCoors = new List <XYZ>(); // NOTE LAM TRON SO //Get diameter of rebar XYZ middlePoint = myRebar.get_BoundingBox(null).Max.Add(myRebar.get_BoundingBox(null).Min) / 2; List <Curve> centerLines = myRebar.GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, 0) as List <Curve>; foreach (Curve myCurBar in centerLines) { middlePoint = myCurBar.GetEndPoint(0); break; } Plane myReBarPlane = Plane.CreateByNormalAndOrigin(v, middlePoint); // Distance from first rebar to RebarBarType myRbType = doc.GetElement(myRebar.GetTypeId()) as RebarBarType; double myRebarDiameter = myRbType.BarDiameter; XYZ v1 = p - myReBarPlane.Origin; double delta_0 = Math.Abs(myReBarPlane.Normal.DotProduct(v1)); if (delta_0 == 10000000) { return(null); } foreach (double distance in myDistances) { XYZ myPointPlace = ((distance - delta_0) / lengCurLine) * v; myCoors.Add(myPointPlace); } if (myCoors.Count < 1) { TaskDialog.Show("Loi!", "Khong the copy..."); return(null); } ICollection <ElementId> myRebarIdCol; List <ElementId> myListIdRebar = new List <ElementId>(); // using transcation (edit DB) using (Transaction myTrans = new Transaction(doc, "CopyElementByCoordinate")) { myTrans.Start(); foreach (XYZ myXYZ in myCoors) { myRebarIdCol = ElementTransformUtils.CopyElement(doc, myIdRebar, myXYZ); foreach (ElementId elemRebarId in myRebarIdCol) { myListIdRebar.Add(elemRebarId); } } myTrans.Commit(); } return(myListIdRebar); } }
public void testRebar_FromShape() { UIDocument uiDoc = this.ActiveUIDocument; Document doc = uiDoc.Document; // Pick Rebar List <int> myListIdCategoryRebar = new List <int>(); myListIdCategoryRebar.Add((int)BuiltInCategory.OST_StructuralFraming); // Select first Element (ex beam) Reference myRefBeam = uiDoc.Selection.PickObject(ObjectType.Element, new FilterByIdCategory(myListIdCategoryRebar), "Pick a Beam..."); //Get element1 from ref Element myBeam = doc.GetElement(myRefBeam); setBeJoined(myBeam); LocationCurve myLocBeam = myBeam.Location as LocationCurve; Line centerLinebeam = myLocBeam.Curve as Line; XYZ p = centerLinebeam.GetEndPoint(0); XYZ q = centerLinebeam.GetEndPoint(1); XYZ v = p - q; XYZ v1 = v.CrossProduct(p); List <Curve> myShape = new List <Curve>() { centerLinebeam }; // Rebartype FilteredElementCollector fec1 = new FilteredElementCollector(doc) .OfClass(typeof(RebarBarType)); IEnumerable <RebarBarType> iterRebarBarTypes = fec1.Cast <RebarBarType>(); RebarBarType myRebarType = iterRebarBarTypes.First(); // RebarShape FilteredElementCollector fec3 = new FilteredElementCollector(doc) .OfClass(typeof(RebarShape)); IEnumerable <RebarShape> iterRebarBarShapes = fec3.Cast <RebarShape>(); RebarShape myRebarShape = iterRebarBarShapes.First(); // Hooktype FilteredElementCollector fec2 = new FilteredElementCollector(doc) .OfClass(typeof(RebarHookType)); IEnumerable <RebarHookType> iterRebarHookTypes = fec2.Cast <RebarHookType>(); RebarHookType myRebarHookType = iterRebarHookTypes.First(); XYZ ORIGIN = new XYZ(q.X, q.Y, q.Z - 25 / 304.8); using (Transaction trans = new Transaction(doc, "rebar test")) { trans.Start(); Rebar bar = Rebar.CreateFromRebarShape(doc, myRebarShape, myRebarType, myBeam, ORIGIN, v, new XYZ(0, 0, 1)); doc.Regenerate(); List <Curve> myCenterLineOfRebar = bar.GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeOnlyPlanarCurves, 0) as List <Curve>; trans.Commit(); } }