/// <summary> /// Create Edge (Line or Arc2) from Dynamo Line or Arc. /// Used for bar definition. /// </summary> public static Geometry.Edge FromDynamoLineOrArc2(Autodesk.DesignScript.Geometry.Curve obj) { // if polyline or similar. Autodesk.DesignScript.Geometry.Geometry[] items = obj.Explode(); if (items.Length != 1) { throw new System.ArgumentException("Exploded Curve should only have one item."); } Autodesk.DesignScript.Geometry.Geometry item = items[0]; // if Arc if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Arc)) { return(Edge.FromDynamoArc2((Autodesk.DesignScript.Geometry.Arc)item)); } // if Line else if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Line)) { return(Edge.FromDynamoLine((Autodesk.DesignScript.Geometry.Line)item)); } else { throw new System.ArgumentException($"Curve type: {obj.GetType()}, is not Line or Arc."); } }
/// <summary> /// Create a column. /// </summary> /// <param name="curve">The curve which defines the center line of the column.</param> /// <param name="level">The level with which you'd like the column to be associated.</param> /// <param name="structuralColumnType">The structural column type representing the column.</param> /// <returns></returns> public static StructuralFraming ColumnByCurve( Autodesk.DesignScript.Geometry.Curve curve, Revit.Elements.Level level, Revit.Elements.FamilyType structuralColumnType) { if (curve == null) { throw new System.ArgumentNullException("curve"); } if (level == null) { throw new System.ArgumentNullException("level"); } if (structuralColumnType == null) { throw new System.ArgumentNullException("structuralColumnType"); } var start = curve.PointAtParameter(0); var end = curve.PointAtParameter(1); // Revit will throw an exception if you attempt to create a column whose // base is above its top. if (end.Z <= start.Z) { throw new Exception(Properties.Resources.InvalidColumnBaseLocation); } return(new StructuralFraming(curve.ToRevitType(), level.InternalLevel, Autodesk.Revit.DB.Structure.StructuralType.Column, structuralColumnType.InternalFamilySymbol)); }
private static Curve CreateReversed(Curve curve) { Autodesk.Revit.DB.Curve orig = curve.ToRevitType(); var app = DocumentManager.Instance.CurrentUIApplication; if (orig is Line) { var line = Line.CreateBound( orig.GetEndPoint(1), orig.GetEndPoint(0)); return(line.ToProtoType()); } else if (orig is Arc) { var arc = Arc.Create(orig.GetEndPoint(1), orig.GetEndPoint(0), orig.Evaluate(0.5, true)); return(arc.ToProtoType()); } else { throw new Exception( "CreateReversedCurve - Unreachable"); } }
/// <summary> /// Set Geometry Curve /// </summary> public void SetCurve(Autodesk.DesignScript.Geometry.Curve curve) { Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(document); this.InternalCurveElement.SetGeometryCurve(curve.ToRevitType(), true); TransactionManager.Instance.TransactionTaskDone(); }
/// <summary> /// Construct a Revit DetailCurve element from a curve /// </summary> /// <param name="view">View to place the detail curve on</param> /// <param name="curve">Curve to create detailcurve from</param> /// <returns></returns> public static DetailCurve ByCurve(Revit.Elements.Views.View view, Autodesk.DesignScript.Geometry.Curve curve) { if (!view.IsAnnotationView()) { throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations); } if (!curve.IsPlanar) { throw new Exception(Properties.Resources.CurveIsNotPlanar); } if (curve is Autodesk.DesignScript.Geometry.PolyCurve) { throw new Exception(Properties.Resources.PolyCurvesConversionError); } // Pull Curve onto the XY plane to place it correctly on the view. Autodesk.DesignScript.Geometry.Plane XYplane = Autodesk.DesignScript.Geometry.Plane.XY(); Autodesk.DesignScript.Geometry.Curve flattenedCurve = curve.PullOntoPlane(XYplane); Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement; return(new DetailCurve(revitView, flattenedCurve.ToRevitType())); }
public static Bar Beam(Autodesk.DesignScript.Geometry.Curve curve, Materials.Material material, Sections.Section[] section, [DefaultArgument("Connectivity.Default()")] Connectivity[] connectivity, [DefaultArgument("Eccentricity.Default()")] Eccentricity[] eccentricity, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localY, [DefaultArgument("true")] bool orientLCS, string identifier = "B") { // convert class Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc2(curve); // create bar var type = BarType.Beam; Bar bar = new Bar(edge, type, material, section, eccentricity, connectivity, identifier); // set local y-axis if (!localY.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0))) { bar.BarPart.LocalY = FemDesign.Geometry.FdVector3d.FromDynamo(localY); } // else orient coordinate system to GCS else { if (orientLCS) { bar.BarPart.OrientCoordinateSystemToGCS(); } } // return return(bar); }
public static StructuralFraming ByCurveLevelUpVectorAndType(Autodesk.DesignScript.Geometry.Curve curve, Level level, Autodesk.DesignScript.Geometry.Vector upVector, StructuralType structuralType, FamilyType structuralFramingType) { if (curve == null) { throw new System.ArgumentNullException("curve"); } if (level == null) { throw new System.ArgumentNullException("level"); } if (upVector == null) { throw new System.ArgumentNullException("upVector"); } if (structuralFramingType == null) { throw new System.ArgumentNullException("structuralFramingType"); } return(new StructuralFraming(curve.ToRevitType(), upVector.ToXyz(), level.InternalLevel, structuralType.ToRevitType(), structuralFramingType.InternalFamilySymbol)); }
public static Autodesk.DesignScript.Geometry.PolyCurve ConvertDynamoPolylineToPolyCurve(Autodesk.AutoCAD.DynamoNodes.Polyline dynamoPolyline) { Autodesk.AutoCAD.DatabaseServices.Polyline polyline = (Autodesk.AutoCAD.DatabaseServices.Polyline)dynamoPolyline.InternalDBObject; Autodesk.DesignScript.Geometry.PolyCurve retVal = null; if (polyline != null) { // extract each segment Autodesk.DesignScript.Geometry.Curve[] curves; // = new Autodesk.DesignScript.Geometry.Curve[polyline.NumberOfVertices]; if (polyline.Closed) { curves = new Autodesk.DesignScript.Geometry.Curve[polyline.NumberOfVertices]; } else { curves = new Autodesk.DesignScript.Geometry.Curve[polyline.NumberOfVertices - 1]; } // convert segment into Dynamo curve or line int curIndex = 0; while (curIndex <= polyline.NumberOfVertices) { if (polyline.GetSegmentType(curIndex) == SegmentType.Arc) { Autodesk.DesignScript.Geometry.Arc curCurve; Autodesk.DesignScript.Geometry.Point centerPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetArcSegment2dAt(curIndex).Center.X, polyline.GetArcSegment2dAt(curIndex).Center.Y, 0.0); Autodesk.DesignScript.Geometry.Point startPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetArcSegment2dAt(curIndex).StartPoint.X, polyline.GetArcSegment2dAt(curIndex).StartPoint.Y, 0.0); Autodesk.DesignScript.Geometry.Point endPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetArcSegment2dAt(curIndex).EndPoint.X, polyline.GetArcSegment2dAt(curIndex).EndPoint.Y, 0.0); curCurve = Autodesk.DesignScript.Geometry.Arc.ByCenterPointStartPointEndPoint(centerPt, endPt, startPt); curves.SetValue(curCurve, curIndex); } else if (polyline.GetSegmentType(curIndex) == SegmentType.Line) { Autodesk.DesignScript.Geometry.Line curLine; Autodesk.DesignScript.Geometry.Point startPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetLineSegment2dAt(curIndex).StartPoint.X, polyline.GetLineSegment2dAt(curIndex).StartPoint.Y, 0.0); Autodesk.DesignScript.Geometry.Point endPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetLineSegment2dAt(curIndex).EndPoint.X, polyline.GetLineSegment2dAt(curIndex).EndPoint.Y, 0.0); curLine = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(startPt, endPt); curves.SetValue(curLine, curIndex); } curIndex = curIndex + 1; } retVal = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(curves); } return(retVal); }
public static LineLoad Moment(Autodesk.DesignScript.Geometry.Curve curve, Autodesk.DesignScript.Geometry.Vector startForce, Autodesk.DesignScript.Geometry.Vector endForce, LoadCase loadCase, [DefaultArgument("true")] bool constLoadDir, string comment = "") { // convert geometry Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc1(curve); Geometry.FdVector3d _startForce = Geometry.FdVector3d.FromDynamo(startForce); Geometry.FdVector3d _endForce = Geometry.FdVector3d.FromDynamo(endForce); return(new LineLoad(edge, _startForce, _endForce, loadCase, ForceLoadType.Moment, comment, constLoadDir, loadProjection: false)); }
public static LineTemperatureLoad Define(Autodesk.DesignScript.Geometry.Curve curve, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,1)")] Autodesk.DesignScript.Geometry.Vector direction, List <TopBotLocationValue> topBottomLocationValues, LoadCase loadCase, string comments = "") { // convert geometry Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc1(curve); Geometry.FdVector3d v = Geometry.FdVector3d.FromDynamo(direction); // return return(new LineTemperatureLoad(edge, v, topBottomLocationValues, loadCase, comments)); }
/// <summary> /// Creates a vector between the midpoint of two curves /// </summary> /// <param name="crv1"></param> /// <param name="crv2"></param> /// <search></search> public static Autodesk.DesignScript.Geometry.Vector ByTwoCurves(this Autodesk.DesignScript.Geometry.Curve crv1, Autodesk.DesignScript.Geometry.Curve crv2) { Autodesk.DesignScript.Geometry.Point pt1 = crv1.PointAtParameter(0.5); Autodesk.DesignScript.Geometry.Point pt2 = crv2.PointAtParameter(0.5); Autodesk.DesignScript.Geometry.Vector vec = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(pt1, pt2); pt1.Dispose(); pt2.Dispose(); return(vec); }
/// <summary> /// Creates a Revit divided path on the given curve with specified amount of division /// </summary> /// <param name="curve"></param> /// <param name="divisions"></param> /// <returns></returns> public static DividedPath ByCurveAndDivisions(Autodesk.DesignScript.Geometry.Curve curve, int divisions) { if (curve == null) { throw new ArgumentNullException("curve"); } if (divisions < 2) { throw new Exception(Properties.Resources.NumberOfDivisionsMustBeGreaterThan2); } return(new DividedPath(new[] { ElementCurveReference.TryGetCurveReference(curve) }, divisions)); }
private static ElementCurveReference TryGetCurveReference(Autodesk.DesignScript.Geometry.Curve curveObject, string nodeTypeString = "This node") { // If a Reference has been added to this object, we can use that // to build the element. object tagObj = curveObject.Tags.LookupTag(DefaultTag); if (tagObj != null) { var tagRef = (Reference)tagObj; return(new ElementCurveReference(tagRef)); } throw new ArgumentException(string.Format(Properties.Resources.CurveReferenceExtractionFailure, nodeTypeString) + string.Format(Properties.Resources.CurveReferenceHint, "ModelCurve.ByCurve", "ImportInstance.ByGeometry")); }
public static LineLoad MomentUniform(Autodesk.DesignScript.Geometry.Curve curve, Autodesk.DesignScript.Geometry.Vector force, LoadCase loadCase, [DefaultArgument("true")] bool constLoadDir, string comment = "") { // convert geometry Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc1(curve); Geometry.FdVector3d _startForce = Geometry.FdVector3d.FromDynamo(force); Geometry.FdVector3d _endForce = _startForce; // check zero vector if (_startForce.IsZero()) { throw new System.ArgumentException($"Force is zero."); } return(new LineLoad(edge, _startForce, _endForce, loadCase, ForceLoadType.Moment, comment, constLoadDir, loadProjection: false)); }
private static ElementCurveReference TryGetCurveReference(Autodesk.DesignScript.Geometry.Curve curveObject, string nodeTypeString = "This node") { // If a Reference has been added to this object, we can use that // to build the element. object tagObj = curveObject.Tags.LookupTag(DefaultTag); if (tagObj != null) { var tagRef = (Reference)tagObj; return(new ElementCurveReference(tagRef)); } throw new ArgumentException(nodeTypeString + " requires a Curve extracted from a Revit Element! " + "You can use the ModelCurve.ByCurve or ImportInstance.ByGeometry to " + "turn this Curve into a Revit Element."); }
/// <summary> /// 判断线是否重合 /// </summary> /// <param name="crv1"></param> /// <param name="crv2"></param> /// <returns></returns> public static bool JudgeDuplicateCurves(Autodesk.DesignScript.Geometry.Curve crv1 , Autodesk.DesignScript.Geometry.Curve crv2) { Autodesk.DesignScript.Geometry.Point pt1 = crv1.StartPoint; Autodesk.DesignScript.Geometry.Point pt2 = crv1.EndPoint; bool b1 = JudgeDuplicatePoints(pt1, crv2.StartPoint) && JudgeDuplicatePoints(pt2, crv2.EndPoint); bool b2 = JudgeDuplicatePoints(pt1, crv2.EndPoint) && JudgeDuplicatePoints(pt2, crv2.StartPoint); bool b3 = crv1.TangentAtParameter(0.3).IsParallel(crv2.TangentAtParameter(0.3)) || crv1.TangentAtParameter(0.3).IsParallel(crv2.TangentAtParameter(0.7)); if ((b1 || b2) && b3) { return(true); } return(false); }
/// <summary> /// Create a fictitious bar element. /// </summary> /// <param name="curve">Line or Arc.</param> /// <param name="AE">AE</param> /// <param name="ItG">ItG</param> /// <param name="I1E">I1E</param> /// <param name="I2E">I2E</param> /// <param name="connectivity">Connectivity. If 1 item this item defines both start and end connectivity. If two items the first item defines the start connectivity and the last item defines the end connectivity.</param> /// <param name="localY">Set local y-axis. Vector must be perpendicular to Curve mid-point local x-axis. This parameter overrides OrientLCS</param> /// <param name="orientLCS">Orient LCS to GCS? If true the LCS of this object will be oriented to the GCS trying to align local z to global z if possible or align local y to global y if possible (if object is vertical). If false local y-axis from Curve coordinate system at mid-point will be used.</param> /// <param name="identifier">Identifier. Optional.</param> /// <returns></returns> public static FictitiousBar Define(Autodesk.DesignScript.Geometry.Curve curve, [DefaultArgument("10000000")] double AE, [DefaultArgument("10000000")] double ItG, [DefaultArgument("10000000")] double I1E, [DefaultArgument("10000000")] double I2E, [DefaultArgument("FemDesign.Bars.Connectivity.Default()")] List <Bars.Connectivity> connectivity, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localY, [DefaultArgument("true")] bool orientLCS, string identifier = "BF") { // convert geometry Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc2(curve); Geometry.FdVector3d y = Geometry.FdVector3d.FromDynamo(localY); // get connectivity Bars.Connectivity startConnectivity; Bars.Connectivity endConnectivity; if (connectivity.Count == 1) { startConnectivity = connectivity[0]; endConnectivity = connectivity[0]; } else if (connectivity.Count == 2) { startConnectivity = connectivity[0]; endConnectivity = connectivity[1]; } else { throw new System.ArgumentException($"Connectivity must contain 1 or 2 items. Number of items is {connectivity.Count}"); } // create virtual bar FictitiousBar bar = new FictitiousBar(edge, edge.CoordinateSystem.LocalY, startConnectivity, endConnectivity, identifier, AE, ItG, I1E, I2E); // set local y-axis if (!localY.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0))) { bar.LocalY = FemDesign.Geometry.FdVector3d.FromDynamo(localY); } // else orient coordinate system to GCS else { if (orientLCS) { bar.OrientCoordinateSystemToGCS(); } } // return return(bar); }
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 }, }); }
/// <summary> /// Create FdCoordinateSystem from Dynamo coordinate system on curve mid u-point. /// </summary> internal static FdCoordinateSystem FromDynamoCurve(Autodesk.DesignScript.Geometry.Curve obj) { // CoordinateSystemAtParameter returns a coordinate system on curve // with origin at the point at the given parameter. // The XAxis is aligned with the curve normal, // the YAxis is aligned with the curve tangent at this point, // and the ZAxis is aligned with the up-vector or binormal at this point Autodesk.DesignScript.Geometry.CoordinateSystem cs = obj.CoordinateSystemAtParameter(0.5); // Note: Arcs and Circles in Dynamo are defined with left-hand rule while coordinate system is defined by right-hand rule if (obj.GetType() == typeof(Autodesk.DesignScript.Geometry.Arc) || obj.GetType() == typeof(Autodesk.DesignScript.Geometry.Circle)) { return(FdCoordinateSystem.FromDynamoCoordinateSystemArcOrCircle(cs)); } else { return(FromDynamoCoordinateSystemLine(cs)); } }
/// <summary> /// Create a brace. /// </summary> /// <param name="curve">The cruve which defines the center line of the brace.</param> /// <param name="level">The level with which you'd like the brace to be associated.</param> /// <param name="structuralFramingType">The structural framing type representing the brace.</param> /// <returns></returns> public static StructuralFraming BraceByCurve(Autodesk.DesignScript.Geometry.Curve curve, Revit.Elements.Level level, Revit.Elements.FamilyType structuralFramingType) { if (curve == null) { throw new System.ArgumentNullException("curve"); } if (level == null) { throw new System.ArgumentNullException("level"); } if (structuralFramingType == null) { throw new System.ArgumentNullException("structuralFramingType"); } return(new StructuralFraming(curve.ToRevitType(), level.InternalLevel, Autodesk.Revit.DB.Structure.StructuralType.Brace, structuralFramingType.InternalFamilySymbol)); }
public static ConnectedLines Define(Autodesk.DesignScript.Geometry.Curve firstCurve, Autodesk.DesignScript.Geometry.Curve secondCurve, Autodesk.DesignScript.Geometry.Vector localX, Autodesk.DesignScript.Geometry.Vector localY, Releases.Motions motions, Releases.Rotations rotations, System.Guid[] references, string identifier, bool movingLocal, double interfaceStart, double interfaceEnd) { // convert geometry Geometry.Edge edge0 = Geometry.Edge.FromDynamoLineOrArc2(firstCurve); Geometry.Edge edge1 = Geometry.Edge.FromDynamoLineOrArc2(secondCurve); Geometry.FdVector3d x = Geometry.FdVector3d.FromDynamo(localX); Geometry.FdVector3d y = Geometry.FdVector3d.FromDynamo(localY); // rigidity Releases.RigidityDataType3 rigidity = new Releases.RigidityDataType3(motions, rotations); // references GuidListType[] refs = new GuidListType[references.Length]; for (int idx = 0; idx < refs.Length; idx++) { refs[idx] = new GuidListType(references[idx]); } return(new ConnectedLines(edge0, edge1, x, y, rigidity, refs, identifier, movingLocal, interfaceStart, interfaceEnd)); }
/// <summary> /// Convert a Dynamo Curve to Edge. /// </summary> /// <param name="obj"></param> public static Geometry.Edge FromDynamo(Autodesk.DesignScript.Geometry.Curve obj) { // if polyline or similar. Autodesk.DesignScript.Geometry.Geometry[] items = obj.Explode(); if (items.Length != 1) { throw new System.ArgumentException("Exploded Curve should only have one item."); } Autodesk.DesignScript.Geometry.Geometry item = items[0]; // if Arc if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Arc)) { // output is a general purpose Edge return(Edge.FromDynamoArc1((Autodesk.DesignScript.Geometry.Arc)item)); } // if Circle else if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Circle)) { return(Edge.FromDynamoCircle((Autodesk.DesignScript.Geometry.Circle)item)); } // if Line else if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Line)) { return(Edge.FromDynamoLine((Autodesk.DesignScript.Geometry.Line)item)); } // if NurbsCurve else if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.NurbsCurve)) { return(Edge.FromDynamoNurbsCurve((Autodesk.DesignScript.Geometry.NurbsCurve)item)); } // else else { throw new System.ArgumentException($"Curve type: {obj.GetType()}, is not supported for conversion to an Edge."); } }
/// <summary> /// 判断两条曲线相等(通过两条曲线上的点来判断精确度越高判断越准确 /// </summary> /// <param name="curve"></param> /// <param name="curve2"></param> /// <param name="Accuracy"></param> /// <returns></returns> public static bool IsAlmostEqualsTo(this DyCurve curve, DyCurve curve2, int Accuracy = 100) { //判断从0到1的 分段点上 点相等 而且 所在点的切线平行 double accuracyPercent = -1; if (Accuracy == 0) { throw new Exception("wrong parameter"); } for (int i = 0; i <= Accuracy; i++) { accuracyPercent = i == 0?0:i / Accuracy; if (!curve.PointAtParameter(accuracyPercent).IsAlmostEqualTo(curve2.PointAtParameter(accuracyPercent)) || !curve.TangentAtParameter(accuracyPercent).IsParallel(curve2.TangentAtParameter(accuracyPercent)) ) { return(false); } } return(true); }
private static double BulgeFromCurve(Autodesk.DesignScript.Geometry.Curve cv, bool clockwise) { double bulge = 0.0; Autodesk.DesignScript.Geometry.Arc a = cv as Autodesk.DesignScript.Geometry.Arc; if (a != null) { double newStart; // The start angle is usually greater than the end // as arcs are all counter-clockwise. // (If it isn't it's because the arc crosses the // 0-degree line, and we can subtract 2PI from the // start angle.) if (a.StartAngle > a.SweepAngle) { newStart = a.StartAngle - 8 * Math.Atan(1); } else { newStart = a.StartAngle; } // Bulge is defined as the tan of // one fourth of the included angle bulge = Math.Tan((a.SweepAngle - newStart) / 4); // If the curve is clockwise, we negate the bulge if (clockwise) { bulge = -bulge; } } return(bulge); }
public static LineSupport Define(Autodesk.DesignScript.Geometry.Curve curve, Motions motions, [DefaultArgument("MotionsPlasticLimits.Default()")] MotionsPlasticLimits motionsPlasticLimits, Rotations rotations, [DefaultArgument("RotationsPlasticLimits.Default()")] RotationsPlasticLimits rotationsPlasticLimits, [DefaultArgument("false")] bool movingLocal, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localY, [DefaultArgument("true")] bool orientLCS, [DefaultArgument("S")] string identifier) { Geometry.Edge edge = Geometry.Edge.FromDynamoLineOrArc1(curve); FemDesign.Supports.LineSupport obj = new LineSupport(edge, motions, motionsPlasticLimits, rotations, rotationsPlasticLimits, movingLocal, identifier); // set local y-axis if (!localY.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0))) { obj.Group.LocalY = FemDesign.Geometry.FdVector3d.FromDynamo(localY); } // else orient coordinate system to GCS else { if (orientLCS) { obj.Group.OrientCoordinateSystemToGCS(); } } return(obj); }
/// <summary> /// 判断能否合并 /// </summary> /// <param name="curve1"></param> /// <param name="curve2"></param> /// <returns></returns> public static bool CanJoin(Autodesk.DesignScript.Geometry.Curve curve1, Autodesk.DesignScript.Geometry.Curve curve2) { Autodesk.DesignScript.Geometry.Point pt1 = curve1.StartPoint; Autodesk.DesignScript.Geometry.Point pt2 = curve1.EndPoint; List <Autodesk.DesignScript.Geometry.Point> crvPts = new List <Autodesk.DesignScript.Geometry.Point>() { curve2.StartPoint, curve2.EndPoint }; bool b = false; foreach (var p in crvPts) { if (JudgeDuplicatePoints(p, pt1) || JudgeDuplicatePoints(p, pt2)) { b = true; break; } } return(b); }
/// <summary> /// Extends a straight line at both ends /// </summary> /// <param name="line"></param> /// <param name="distance"></param> /// <search></search> public static Autodesk.DesignScript.Geometry.Line ExtendAtBothEnds(this Autodesk.DesignScript.Geometry.Curve line, double distance) { Autodesk.DesignScript.Geometry.Point stPt = line.StartPoint; Autodesk.DesignScript.Geometry.Point endPt = line.EndPoint; Autodesk.DesignScript.Geometry.Vector vec1 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(endPt, stPt); Autodesk.DesignScript.Geometry.Vector vec2 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(stPt, endPt); Autodesk.DesignScript.Geometry.Point newStPt = stPt.Translate(vec1, distance) as Autodesk.DesignScript.Geometry.Point; Autodesk.DesignScript.Geometry.Point newEndPt = endPt.Translate(vec2, distance) as Autodesk.DesignScript.Geometry.Point; Autodesk.DesignScript.Geometry.Line newLine = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(newStPt, newEndPt); //Dispose redundant geometry stPt.Dispose(); endPt.Dispose(); vec1.Dispose(); vec2.Dispose(); newStPt.Dispose(); newEndPt.Dispose(); return(newLine); }
public static Autodesk.AutoCAD.DatabaseServices.Polyline ConvertPolyCurveToPolyline(Autodesk.DesignScript.Geometry.PolyCurve polyCurve) { Autodesk.AutoCAD.DatabaseServices.Polyline retVal = new Autodesk.AutoCAD.DatabaseServices.Polyline(); if (polyCurve != null) { // extract each segment Autodesk.DesignScript.Geometry.Curve[] curves = new Autodesk.DesignScript.Geometry.Curve[polyCurve.NumberOfCurves]; // convert segment into AutoCAD polyline int curIndex = 0; while (curIndex < polyCurve.NumberOfCurves) { double bulge = 0.0; Autodesk.DesignScript.Geometry.Curve curCurve = polyCurve.CurveAtIndex(curIndex); // trying to figure out if the segment is an arc or line...for some reason it thinks lines are arcs var typeOfcurve = curCurve.GetType(); if (typeOfcurve == typeof(Autodesk.DesignScript.Geometry.Arc)) { // set the bulge for the curve //bulge = BulgeFromCurve(curCurve, true); bulge = 0.5; } // otherwise, it's a line, and default bulge applies retVal.AddVertexAt(curIndex, new Point2d(curCurve.StartPoint.X, curCurve.StartPoint.Y), bulge, 0.0, 0.0); curIndex = curIndex + 1; } if (polyCurve.StartPoint == polyCurve.EndPoint) { retVal.Closed = true; } else { retVal.AddVertexAt(curIndex, new Point2d(polyCurve.EndPoint.X, polyCurve.EndPoint.Y), 0.0, 0.0, 0.0); } //retVal = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(curves); } return(retVal); }
/// <summary> /// Compares a single curve to a list of curves to find any curves that have the same normalised vector. /// </summary> /// <param name="curve"></param> /// <param name="curves"></param> /// <search></search> public static List <Autodesk.DesignScript.Geometry.Curve> FindMatchingVectorCurves(this Autodesk.DesignScript.Geometry.Curve curve, List <Autodesk.DesignScript.Geometry.Curve> curves) { Autodesk.DesignScript.Geometry.Point stPt1 = curve.StartPoint; Autodesk.DesignScript.Geometry.Point endPt1 = curve.EndPoint; Autodesk.DesignScript.Geometry.Vector vec1 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(stPt1, endPt1).Normalized(); string str1 = vec1.ToString(); List <string> curveList = new List <string>(); foreach (var c in curves) { Autodesk.DesignScript.Geometry.Point stPt2 = c.StartPoint; Autodesk.DesignScript.Geometry.Point endPt2 = c.EndPoint; Autodesk.DesignScript.Geometry.Vector vec2 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(stPt2, endPt2).Normalized(); string str2 = vec2.ToString(); curveList.Add(str2); //Dispose redundant geometry stPt2.Dispose(); endPt2.Dispose(); vec2.Dispose(); } List <Autodesk.DesignScript.Geometry.Curve> matchingCurves = new List <Autodesk.DesignScript.Geometry.Curve>(); for (int i = 0; i < curveList.Count; i++) { if (str1 == curveList[i]) { matchingCurves.Add(curves[i]); } } if (matchingCurves.Count == 0) { List <string> revCurveList = new List <string>(); foreach (var c in curves) { Autodesk.DesignScript.Geometry.Point stPt2 = c.StartPoint; Autodesk.DesignScript.Geometry.Point endPt2 = c.EndPoint; Autodesk.DesignScript.Geometry.Vector vec2 = Autodesk.DesignScript.Geometry.Vector.ByTwoPoints(endPt2, stPt2).Normalized(); string str2 = vec2.ToString(); revCurveList.Add(str2); //Dispose redundant geometry stPt2.Dispose(); endPt2.Dispose(); vec2.Dispose(); } for (int i = 0; i < revCurveList.Count; i++) { if (str1 == revCurveList[i]) { matchingCurves.Add(curves[i]); } } } //Dispose redundant geometry stPt1.Dispose(); endPt1.Dispose(); vec1.Dispose(); return(matchingCurves); }
/// <summary> /// Create an adaptive component referencing the parameters on a Curve reference /// </summary> /// <param name="parameters">The parameters on the curve</param> /// <param name="curve">The curve to reference</param> /// <param name="familyType">The family type to construct</param> /// <returns></returns> public static AdaptiveComponent ByParametersOnCurveReference(double[] parameters, Autodesk.DesignScript.Geometry.Curve curve, FamilyType familyType) { if (parameters == null) { throw new ArgumentNullException("parameters"); } if (curve == null) { throw new ArgumentNullException("curve"); } if (familyType == null) { throw new ArgumentNullException("familyType"); } return(new AdaptiveComponent(parameters, ElementCurveReference.TryGetCurveReference(curve).InternalReference, familyType)); }
/// <summary> /// Create a Revit Floor given it's curve outline and Level /// </summary> /// <param name="outline"></param> /// <param name="floorType"></param> /// <param name="level"></param> /// <returns>The floor</returns> public static Floor ByOutlineTypeAndLevel(Curve[] outline, FloorType floorType, Level level) { if (outline == null) { throw new ArgumentNullException("outline"); } if (floorType == null) { throw new ArgumentNullException("floorType"); } if ( level == null ) { throw new ArgumentNullException("level"); } if (outline.Count() < 3) { throw new Exception("Outline must have at least 3 edges to enclose an area."); } var ca = new CurveArray(); outline.ToList().ForEach(x => ca.Append(x.ToRevitType())); return new Floor(ca, floorType.InternalFloorType, level.InternalLevel ); }