Skip to content

Commit 46c0d69

Browse files
committed
better AddPolyline
1 parent 9fcaab2 commit 46c0d69

3 files changed

Lines changed: 66 additions & 56 deletions

File tree

Src/AutoGeneratedCode/AllScriptingFilesCombinedIntoOne_DontEditThisFile.fs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,42 +3271,47 @@ type RhinoScriptSyntax private () =
32713271

32723272

32733273
/// <summary>Adds a Polyline Curve.</summary>
3274-
/// <param name="points">(Point3d seq) List of 3D points. The list must contain at least two points. If the
3275-
/// list contains less than four points, then the first point and
3276-
/// last point must be different.</param>
3277-
/// <returns>(Guid) ObjectId of the new curve object.</returns>
3278-
static member AddPolyline(points:Point3d seq) : Guid =
3274+
/// <param name="points">(Point3d seq) List of 3D points. The list must contain at least two points. If the list contains less than four points, then the first point and last point must be different.</param>
3275+
/// <param name="deleteShortSegments">(bool) Optional, default value: <c>true</c>. If true, segments shorter than the document's absolute tolerance will be deleted.</param>
3276+
/// <param name="drawDotsAndRaiseIfFailed">(bool) Optional, default value: <c>false</c>. If true, text dots will be drawn on layer `ERROR-AddPolyline` at each point and an exception will be raised if the operation fails.</param>
3277+
/// <returns>(Guid) ObjectId of the new curve object. Empty Guid if the operation fails.</returns>
3278+
static member AddPolyline(points:Point3d seq, [<OPT;DEF(true)>]deleteShortSegments: bool, [<OPT;DEF(false)>]drawDotsAndRaiseIfFailed: bool) : Guid =
32793279
let pl = Polyline(points)
3280-
//pl.DeleteShortSegments(State.Doc.ModelAbsoluteTolerance) |> ignore<bool>
3280+
if deleteShortSegments then
3281+
pl.DeleteShortSegments(State.Doc.ModelAbsoluteTolerance) |> ignore<int>
32813282
let rc = State.Doc.Objects.AddPolyline(pl)
3282-
if rc = Guid.Empty then
3283+
if drawDotsAndRaiseIfFailed && rc = Guid.Empty then
32833284
for i,pt in Seq.indexed(points) do
3284-
let d = State.Doc.Objects.AddTextDot(string i, pt) // TODO really draw debug objects ?
3285+
let d = State.Doc.Objects.AddTextDot(string i, pt)
32853286
RhinoScriptSyntax.ObjectLayer(d,"ERROR-AddPolyline", createLayerIfMissing=true)
3286-
eprintfn "See %d TextDots on layer 'ERROR-AddPolyline'" (Seq.length points)
3287+
// eprintfn "See %d TextDots on layer 'ERROR-AddPolyline'" (Seq.length points)
32873288
RhinoScriptingException.Raise "AddPolyline: Unable to add polyline to document form points:%s'%A'" Environment.NewLine (Pretty.str points)
32883289
State.Doc.Views.Redraw()
32893290
rc
32903291

3291-
/// <summary>Adds a closed Polyline Curve ,
3292-
/// if the endpoint is already closer than State.Doc.ModelAbsoluteTolerance to the start it wil be set to start point
3293-
/// else an additional point will be added with the same position as start.</summary>
3292+
/// <summary>Adds a closed Polyline Curve.
3293+
/// If the endpoint is already closer than State.Doc.ModelAbsoluteTolerance to the start it wil be set to start point
3294+
/// else an additional point will be added with the same position as start.
3295+
/// </summary>
32943296
/// <param name="points">(Point3d seq) List of 3D points. The list must contain at least three points.</param>
3295-
/// <returns>(Guid) ObjectId of the new curve object.</returns>
3296-
static member AddPolylineClosed(points:Point3d seq) : Guid =
3297+
/// <param name="deleteShortSegments">(bool) Optional, default value: <c>true</c>. If true, segments shorter than the document's absolute tolerance will be deleted.</param>
3298+
/// <param name="drawDotsAndRaiseIfFailed">(bool) Optional, default value: <c>false</c>. If true, text dots will be drawn on layer `ERROR-AddPolylineClosed` at each point and an exception will be raised if the operation fails.</param>
3299+
/// <returns>(Guid) ObjectId of the new curve object. Empty Guid if the operation fails.</returns>
3300+
static member AddPolylineClosed(points:Point3d seq, [<OPT;DEF(true)>]deleteShortSegments: bool, [<OPT;DEF(false)>]drawDotsAndRaiseIfFailed: bool) : Guid =
32973301
let pl = Polyline(points)
32983302
if pl.Count < 3 then RhinoScriptingException.Raise "AddPolylineClosed: Unable to add closed polyline to document from points:%s'%A'" Environment.NewLine (Pretty.str points)
32993303
if (pl.First-pl.Last).Length <= State.Doc.ModelAbsoluteTolerance then
33003304
pl.[pl.Count-1] <- pl.First
33013305
else
33023306
pl.Add pl.First
3303-
//pl.DeleteShortSegments(State.Doc.ModelAbsoluteTolerance) |> ignore<bool>
3307+
if deleteShortSegments then
3308+
pl.DeleteShortSegments(State.Doc.ModelAbsoluteTolerance) |> ignore<int>
33043309
let rc = State.Doc.Objects.AddPolyline(pl)
3305-
if rc = Guid.Empty then
3310+
if drawDotsAndRaiseIfFailed && rc = Guid.Empty then
33063311
for i,pt in Seq.indexed(points) do
3307-
let d = State.Doc.Objects.AddTextDot(string i, pt) // TODO really draw debug objects ?
3312+
let d = State.Doc.Objects.AddTextDot(string i, pt)
33083313
RhinoScriptSyntax.ObjectLayer(d,"ERROR-AddPolylineClosed", createLayerIfMissing=true)
3309-
eprintfn "See %d TextDots on layer 'ERROR-AddPolylineClosed'" (Seq.length points)
3314+
// eprintfn "See %d TextDots on layer 'ERROR-AddPolylineClosed'" (Seq.length points)
33103315
RhinoScriptingException.Raise "AddPolylineClosed: Unable to add closed polyline to document. points:'%A'" points
33113316
State.Doc.Views.Redraw()
33123317
rc
@@ -18321,17 +18326,15 @@ type RhinoScriptSyntax private () =
1832118326

1832218327

1832318328

18324-
/// <summary>Return true if the script is being executed in the context of Rhino (currently always true).</summary>
18325-
/// <returns>(bool) True if the script is being executed in the context of Rhino (currently always true).</returns>
18329+
/// <summary>Return true if the script is being executed in the context of Rhino (Rhino.Runtime.HostUtils.RunningInRhino).</summary>
1832618330
static member ContextIsRhino() : bool =
18327-
true //TODO implement correctly
18328-
18331+
Rhino.Runtime.HostUtils.RunningInRhino
1832918332

18330-
/// <summary>Return true if the script is being executed in a Grasshopper component (currently always false).</summary>
18331-
/// <returns>(bool) True if the script is being executed in a Grasshopper component (currently always false).</returns>
18332-
static member ContextIsGrasshopper() : bool =
18333-
false //TODO implement correctly
1833418333

18334+
// /// <summary>Return true if the script is being executed in a Grasshopper component (currently always false).</summary>
18335+
// static member ContextIsGrasshopper() : bool =
18336+
// false //TODO implement correctly
18337+
// // https://github.com/mcneel/rhinoscriptsyntax/blob/86c9ab1e97df384662a8548b4accee45dfd77a8c/Scripts/scriptcontext.py#L12
1833518338

1833618339
/// <summary>Measures the angle between two points.</summary>
1833718340
/// <param name="point1">(Point3d) Point1 of input points</param>
@@ -18343,7 +18346,8 @@ type RhinoScriptSyntax private () =
1834318346
/// element 1 = the elevation
1834418347
/// element 2 = delta in the X direction
1834518348
/// element 3 = delta in the Y direction
18346-
/// element 4 = delta in the Z direction.</returns>
18349+
/// element 4 = delta in the Z direction.
18350+
/// </returns>
1834718351
static member Angle(point1:Point3d, point2:Point3d, [<OPT;DEF(Plane())>]plane:Plane) : float * float * float * float * float =
1834818352
let plane = if plane.IsValid then plane else Plane.WorldXY
1834918353
let vector = point2 - point1
@@ -18366,7 +18370,8 @@ type RhinoScriptSyntax private () =
1836618370
/// <param name="line2">(Line) List of 6 numbers or 2 Point3d</param>
1836718371
/// <returns>(float * float) containing the following elements:
1836818372
/// 0 = The angle in degrees.
18369-
/// 1 = The reflex angle in degrees.</returns>
18373+
/// 1 = The reflex angle in degrees.
18374+
/// </returns>
1837018375
static member Angle2(line1:Line, line2:Line) : float * float =
1837118376
let vec0 = line1.To - line1.From
1837218377
let vec1 = line2.To - line2.From

Src/Scripting_Curve.fs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -342,42 +342,47 @@ module AutoOpenCurve =
342342

343343

344344
/// <summary>Adds a Polyline Curve.</summary>
345-
/// <param name="points">(Point3d seq) List of 3D points. The list must contain at least two points. If the
346-
/// list contains less than four points, then the first point and
347-
/// last point must be different.</param>
348-
/// <returns>(Guid) ObjectId of the new curve object.</returns>
349-
static member AddPolyline(points:Point3d seq) : Guid =
345+
/// <param name="points">(Point3d seq) List of 3D points. The list must contain at least two points. If the list contains less than four points, then the first point and last point must be different.</param>
346+
/// <param name="deleteShortSegments">(bool) Optional, default value: <c>true</c>. If true, segments shorter than the document's absolute tolerance will be deleted.</param>
347+
/// <param name="drawDotsAndRaiseIfFailed">(bool) Optional, default value: <c>false</c>. If true, text dots will be drawn on layer `ERROR-AddPolyline` at each point and an exception will be raised if the operation fails.</param>
348+
/// <returns>(Guid) ObjectId of the new curve object. Empty Guid if the operation fails.</returns>
349+
static member AddPolyline(points:Point3d seq, [<OPT;DEF(true)>]deleteShortSegments: bool, [<OPT;DEF(false)>]drawDotsAndRaiseIfFailed: bool) : Guid =
350350
let pl = Polyline(points)
351-
//pl.DeleteShortSegments(State.Doc.ModelAbsoluteTolerance) |> ignore<bool>
351+
if deleteShortSegments then
352+
pl.DeleteShortSegments(State.Doc.ModelAbsoluteTolerance) |> ignore<int>
352353
let rc = State.Doc.Objects.AddPolyline(pl)
353-
if rc = Guid.Empty then
354+
if drawDotsAndRaiseIfFailed && rc = Guid.Empty then
354355
for i,pt in Seq.indexed(points) do
355-
let d = State.Doc.Objects.AddTextDot(string i, pt) // TODO really draw debug objects ?
356+
let d = State.Doc.Objects.AddTextDot(string i, pt)
356357
RhinoScriptSyntax.ObjectLayer(d,"ERROR-AddPolyline", createLayerIfMissing=true)
357-
eprintfn "See %d TextDots on layer 'ERROR-AddPolyline'" (Seq.length points)
358+
// eprintfn "See %d TextDots on layer 'ERROR-AddPolyline'" (Seq.length points)
358359
RhinoScriptingException.Raise "AddPolyline: Unable to add polyline to document form points:%s'%A'" Environment.NewLine (Pretty.str points)
359360
State.Doc.Views.Redraw()
360361
rc
361362

362-
/// <summary>Adds a closed Polyline Curve ,
363-
/// if the endpoint is already closer than State.Doc.ModelAbsoluteTolerance to the start it wil be set to start point
364-
/// else an additional point will be added with the same position as start.</summary>
363+
/// <summary>Adds a closed Polyline Curve.
364+
/// If the endpoint is already closer than State.Doc.ModelAbsoluteTolerance to the start it wil be set to start point
365+
/// else an additional point will be added with the same position as start.
366+
/// </summary>
365367
/// <param name="points">(Point3d seq) List of 3D points. The list must contain at least three points.</param>
366-
/// <returns>(Guid) ObjectId of the new curve object.</returns>
367-
static member AddPolylineClosed(points:Point3d seq) : Guid =
368+
/// <param name="deleteShortSegments">(bool) Optional, default value: <c>true</c>. If true, segments shorter than the document's absolute tolerance will be deleted.</param>
369+
/// <param name="drawDotsAndRaiseIfFailed">(bool) Optional, default value: <c>false</c>. If true, text dots will be drawn on layer `ERROR-AddPolylineClosed` at each point and an exception will be raised if the operation fails.</param>
370+
/// <returns>(Guid) ObjectId of the new curve object. Empty Guid if the operation fails.</returns>
371+
static member AddPolylineClosed(points:Point3d seq, [<OPT;DEF(true)>]deleteShortSegments: bool, [<OPT;DEF(false)>]drawDotsAndRaiseIfFailed: bool) : Guid =
368372
let pl = Polyline(points)
369373
if pl.Count < 3 then RhinoScriptingException.Raise "AddPolylineClosed: Unable to add closed polyline to document from points:%s'%A'" Environment.NewLine (Pretty.str points)
370374
if (pl.First-pl.Last).Length <= State.Doc.ModelAbsoluteTolerance then
371375
pl.[pl.Count-1] <- pl.First
372376
else
373377
pl.Add pl.First
374-
//pl.DeleteShortSegments(State.Doc.ModelAbsoluteTolerance) |> ignore<bool>
378+
if deleteShortSegments then
379+
pl.DeleteShortSegments(State.Doc.ModelAbsoluteTolerance) |> ignore<int>
375380
let rc = State.Doc.Objects.AddPolyline(pl)
376-
if rc = Guid.Empty then
381+
if drawDotsAndRaiseIfFailed && rc = Guid.Empty then
377382
for i,pt in Seq.indexed(points) do
378-
let d = State.Doc.Objects.AddTextDot(string i, pt) // TODO really draw debug objects ?
383+
let d = State.Doc.Objects.AddTextDot(string i, pt)
379384
RhinoScriptSyntax.ObjectLayer(d,"ERROR-AddPolylineClosed", createLayerIfMissing=true)
380-
eprintfn "See %d TextDots on layer 'ERROR-AddPolylineClosed'" (Seq.length points)
385+
// eprintfn "See %d TextDots on layer 'ERROR-AddPolylineClosed'" (Seq.length points)
381386
RhinoScriptingException.Raise "AddPolylineClosed: Unable to add closed polyline to document. points:'%A'" points
382387
State.Doc.Views.Redraw()
383388
rc

Src/Scripting_Utility.fs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ module AutoOpenUtility =
1717

1818

1919

20-
/// <summary>Return true if the script is being executed in the context of Rhino (currently always true).</summary>
21-
/// <returns>(bool) True if the script is being executed in the context of Rhino (currently always true).</returns>
20+
/// <summary>Return true if the script is being executed in the context of Rhino (Rhino.Runtime.HostUtils.RunningInRhino).</summary>
2221
static member ContextIsRhino() : bool =
23-
true //TODO implement correctly
22+
Rhino.Runtime.HostUtils.RunningInRhino
2423

2524

26-
/// <summary>Return true if the script is being executed in a Grasshopper component (currently always false).</summary>
27-
/// <returns>(bool) True if the script is being executed in a Grasshopper component (currently always false).</returns>
28-
static member ContextIsGrasshopper() : bool =
29-
false //TODO implement correctly
30-
25+
// /// <summary>Return true if the script is being executed in a Grasshopper component (currently always false).</summary>
26+
// static member ContextIsGrasshopper() : bool =
27+
// false //TODO implement correctly
28+
// // https://github.com/mcneel/rhinoscriptsyntax/blob/86c9ab1e97df384662a8548b4accee45dfd77a8c/Scripts/scriptcontext.py#L12
3129

3230
/// <summary>Measures the angle between two points.</summary>
3331
/// <param name="point1">(Point3d) Point1 of input points</param>
@@ -39,7 +37,8 @@ module AutoOpenUtility =
3937
/// element 1 = the elevation
4038
/// element 2 = delta in the X direction
4139
/// element 3 = delta in the Y direction
42-
/// element 4 = delta in the Z direction.</returns>
40+
/// element 4 = delta in the Z direction.
41+
/// </returns>
4342
static member Angle(point1:Point3d, point2:Point3d, [<OPT;DEF(Plane())>]plane:Plane) : float * float * float * float * float =
4443
let plane = if plane.IsValid then plane else Plane.WorldXY
4544
let vector = point2 - point1
@@ -62,7 +61,8 @@ module AutoOpenUtility =
6261
/// <param name="line2">(Line) List of 6 numbers or 2 Point3d</param>
6362
/// <returns>(float * float) containing the following elements:
6463
/// 0 = The angle in degrees.
65-
/// 1 = The reflex angle in degrees.</returns>
64+
/// 1 = The reflex angle in degrees.
65+
/// </returns>
6666
static member Angle2(line1:Line, line2:Line) : float * float =
6767
let vec0 = line1.To - line1.From
6868
let vec1 = line2.To - line2.From

0 commit comments

Comments
 (0)