Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Jan 8, 2025
1 parent c2a7730 commit c9b3ca2
Show file tree
Hide file tree
Showing 336 changed files with 3,286 additions and 3,475 deletions.
4 changes: 2 additions & 2 deletions rhinocommon/cs/SampleCsAutomation/SampleCsConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void Main()
try
{
const string rhino_id = "Rhino.Application";
var type = Type.GetTypeFromProgID(rhino_id);
Type type = Type.GetTypeFromProgID(rhino_id);
rhino = Activator.CreateInstance(type);
}
catch
Expand All @@ -28,7 +28,7 @@ static void Main()

// Wait until Rhino is initialized before calling into it
const int bail_milliseconds = 15 * 1000;
var time_waiting = 0;
int time_waiting = 0;
while (0 == rhino.IsInitialized())
{
Thread.Sleep(100);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;
using Rhino.PlugIns;
using System.Reflection;
using System.Runtime.InteropServices;
using Rhino.PlugIns;

// Plug-in Description Attributes - all of these are optional
// These will show in Rhino's option dialog, in the tab Plug-ins
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.InteropServices;
using Rhino;
using Rhino;
using Rhino.Commands;
using System.Runtime.InteropServices;

namespace SampleCsRhino
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Rhino.Geometry;
using System;
using System.Collections.Generic;
using Rhino.Geometry;

namespace SampleCsRhino
{
Expand All @@ -11,7 +11,7 @@ public class SampleCsRhinoHelpers
/// </summary>
public static bool ConvertToPoint3d(object pointObj, ref Point3d point)
{
var rc = false;
bool rc = false;
if (pointObj is Array point_arr && 3 == point_arr.Length)
{
try
Expand Down Expand Up @@ -43,13 +43,13 @@ public static bool ConvertToPoint3d(object pointObj, ref Point3d point)
/// </summary>
public static bool ConvertToPoint3dList(object pointsObj, ref List<Point3d> points)
{
var rc = false;
var points_count = points.Count;
bool rc = false;
int points_count = points.Count;
if (pointsObj is Array point_arr)
{
for (var i = 0; i < point_arr.Length; i++)
for (int i = 0; i < point_arr.Length; i++)
{
var point = new Point3d();
Point3d point = new Point3d();
if (ConvertToPoint3d(point_arr.GetValue(i), ref point))
points.Add(point);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections;
using Rhino;
using Rhino.Geometry;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Rhino;
using Rhino.Geometry;

namespace SampleCsRhino
{
Expand Down Expand Up @@ -39,7 +39,7 @@ public string GetString()
/// </summary>
public object GetPoint()
{
var pt = new ArrayList(3) {2.0, 1.0, 0.0};
ArrayList pt = new ArrayList(3) { 2.0, 1.0, 0.0 };
return pt.ToArray();
}

Expand All @@ -48,18 +48,18 @@ public object GetPoint()
/// </summary>
public object GetPoints()
{
var pts = new ArrayList();
ArrayList pts = new ArrayList();

var p0 = new ArrayList {0.0, 0.0, 0.0};
ArrayList p0 = new ArrayList { 0.0, 0.0, 0.0 };
pts.Add(p0.ToArray());

var p1 = new ArrayList {10.0, 0.0, 0.0};
ArrayList p1 = new ArrayList { 10.0, 0.0, 0.0 };
pts.Add(p1.ToArray());

var p2 = new ArrayList {10.0, 10.0, 0.0};
ArrayList p2 = new ArrayList { 10.0, 10.0, 0.0 };
pts.Add(p2.ToArray());

var p3 = new ArrayList {0.0, 10.0, 0.0};
ArrayList p3 = new ArrayList { 0.0, 10.0, 0.0 };
pts.Add(p3.ToArray());

return pts.ToArray();
Expand All @@ -70,13 +70,13 @@ public object GetPoints()
/// </summary>
public object AddPoint(object pointObj)
{
var point = new Point3d();
Point3d point = new Point3d();
if (SampleCsRhinoHelpers.ConvertToPoint3d(pointObj, ref point))
{
var doc = RhinoDoc.ActiveDoc;
RhinoDoc doc = RhinoDoc.ActiveDoc;
if (null != doc)
{
var object_id = doc.Objects.AddPoint(point);
System.Guid object_id = doc.Objects.AddPoint(point);
if (!object_id.Equals(System.Guid.Empty))
{
doc.Views.Redraw();
Expand All @@ -92,16 +92,16 @@ public object AddPoint(object pointObj)
/// </summary>
public object AddPoints(object pointsObj)
{
var points = new List<Point3d>();
List<Point3d> points = new List<Point3d>();
if (SampleCsRhinoHelpers.ConvertToPoint3dList(pointsObj, ref points))
{
var doc = RhinoDoc.ActiveDoc;
RhinoDoc doc = RhinoDoc.ActiveDoc;
if (null != doc)
{
var object_ids = new ArrayList();
for (var i = 0; i < points.Count(); i++)
ArrayList object_ids = new ArrayList();
for (int i = 0; i < points.Count(); i++)
{
var object_id = doc.Objects.AddPoint(points[i]);
System.Guid object_id = doc.Objects.AddPoint(points[i]);
if (!object_id.Equals(System.Guid.Empty))
object_ids.Add(object_id.ToString());
}
Expand All @@ -121,7 +121,7 @@ public object AddPoints(object pointsObj)
public bool RunScript(string script, bool echo)
{
script = script.TrimStart('!');
var rc = RhinoApp.RunScript(script, echo);
bool rc = RhinoApp.RunScript(script, echo);
return rc;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;
using Rhino;
using Rhino;
using Rhino.PlugIns;
using System.Reflection;

namespace SampleCsRhino
{
Expand Down Expand Up @@ -31,8 +31,8 @@ public static SampleCsRhinoPlugIn Instance
/// </summary>
protected override LoadReturnCode OnLoad(ref string errorMessage)
{
var app_name = Assembly.GetExecutingAssembly().GetName().Name;
var app_version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
string app_name = Assembly.GetExecutingAssembly().GetName().Name;
string app_version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
RhinoApp.WriteLine("{0} {1} loaded.", app_name, app_version);
return LoadReturnCode.Success;
}
Expand All @@ -43,7 +43,7 @@ protected override LoadReturnCode OnLoad(ref string errorMessage)
/// </summary>
public override object GetPlugInObject()
{
var rhino_obj = new SampleCsRhinoObject();
SampleCsRhinoObject rhino_obj = new SampleCsRhinoObject();
return rhino_obj;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using Rhino;
using Rhino;
using Rhino.Commands;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;

namespace Project
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using Rhino;
using Rhino.Commands;
using Eto.Forms;
using Rhino.UI.Controls;
using Eto.Forms;

namespace Project
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;
using Rhino.PlugIns;
using System.Reflection;
using System.Runtime.InteropServices;
using Rhino.PlugIns;

// Plug-in Description Attributes - all of these are optional
// These will show in Rhino's option dialog, in the tab Plug-ins
Expand Down
4 changes: 2 additions & 2 deletions rhinocommon/cs/SampleCsCollapsibleSectionETO_UI/SectionOne.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Eto.Forms;
using Eto.Forms;
using Rhino.UI;
using System;

namespace Project
{
Expand Down
4 changes: 2 additions & 2 deletions rhinocommon/cs/SampleCsCollapsibleSectionETO_UI/SectionTwo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Eto.Forms;
using Eto.Forms;
using Rhino.UI;
using System;

namespace Project
{
Expand Down
29 changes: 14 additions & 15 deletions rhinocommon/cs/SampleCsCommands/SampleCSParseTextFields.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Rhino;
using Rhino;
using Rhino.Commands;
using Rhino.Input.Custom;

Expand All @@ -26,9 +25,9 @@ public override string EnglishName

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{

//Select some objects to add attribute user text to
var go = new GetObject();
GetObject go = new GetObject();
go.SetCommandPrompt("Select objects");
go.GroupSelect = true;
go.GetMultiple(1, 0);
Expand All @@ -37,46 +36,46 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)


//Apply the ObjectName textfield as the user text value to the selected objects
for (var i = 0; i < go.ObjectCount; i++)
for (int i = 0; i < go.ObjectCount; i++)
{
var obj_ref = go.Object(i);
var obj = obj_ref.Object();
Rhino.DocObjects.ObjRef obj_ref = go.Object(i);
Rhino.DocObjects.RhinoObject obj = obj_ref.Object();
if (null != obj)
{
//Create an ObjectName TextField and apply it as the value of the user text
var fx = $"%<ObjectName(\"{obj_ref.ObjectId}\")>%";
string fx = $"%<ObjectName(\"{obj_ref.ObjectId}\")>%";
obj.Attributes.SetUserString("ObjectName", fx);
}
}



//Now retrieve the values we just set and parse them
for (var i = 0; i < go.ObjectCount; i++)
for (int i = 0; i < go.ObjectCount; i++)
{
var obj_ref = go.Object(i);
var obj = obj_ref.Object();
Rhino.DocObjects.ObjRef obj_ref = go.Object(i);
Rhino.DocObjects.RhinoObject obj = obj_ref.Object();
if (null == obj)
continue;

//Read user text value and parse it as a textfield
var user_string_value = obj.Attributes.GetUserString("ObjectName");
string user_string_value = obj.Attributes.GetUserString("ObjectName");
if (!string.IsNullOrEmpty(user_string_value))
{
if (user_string_value.StartsWith("%<") && user_string_value.EndsWith(">%"))
{
//RhinoApp.ParseTextField will try to automatically parse any string that looks like a valid textfield containing
//a formula. %<ObjectName("E3D64B7C-3AE7-4390-B983-82730091B8CD")>% for example and return the results.
//The parent object parameter is required only for page objects such as detail object viewport info.
var parsed_string = RhinoApp.ParseTextField(user_string_value, obj_ref.Object(), null);
string parsed_string = RhinoApp.ParseTextField(user_string_value, obj_ref.Object(), null);
RhinoApp.WriteLine($"Parsed TextField: {parsed_string}");
}
}

//Direct method call to TextField ObjectName Example
//You can also call the ObjectName and other TextField functions directly instead of using ParseTextField should you wish to do so.
var direct_string = Rhino.Runtime.TextFields.ObjectName(obj_ref.ObjectId.ToString());
var direct_area = Rhino.Runtime.TextFields.Area(obj_ref.ObjectId.ToString(), UnitSystem.Millimeters.ToString());
string direct_string = Rhino.Runtime.TextFields.ObjectName(obj_ref.ObjectId.ToString());
double direct_area = Rhino.Runtime.TextFields.Area(obj_ref.ObjectId.ToString(), UnitSystem.Millimeters.ToString());
RhinoApp.WriteLine($"Direct ObjectName call: {direct_string}");
RhinoApp.WriteLine($"Direct Area call: {direct_area}");
}
Expand Down
12 changes: 6 additions & 6 deletions rhinocommon/cs/SampleCsCommands/SampleCSQuadRemesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override string EnglishName
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
//Select some object
var go = new GetObject();
GetObject go = new GetObject();
go.SetCommandPrompt("Select object to remesh");
go.GeometryFilter = ObjectType.Brep | ObjectType.Mesh;
go.Get();
Expand All @@ -38,11 +38,11 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)
return Result.Cancel;

//Grab the results of the object picker.
var rhino_object = go.Object(0).Object();
RhinoObject rhino_object = go.Object(0).Object();


//Set our desired quad remesh parameters
var quad_remesh_parameters = new QuadRemeshParameters()
QuadRemeshParameters quad_remesh_parameters = new QuadRemeshParameters()
{
TargetQuadCount = 2000,
AdaptiveQuadCount = true,
Expand All @@ -62,7 +62,7 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)
//Optionally this method also accepts an IEnumerable<Curve> overload.
//Pass it your curve object array/list if you want guide curves)
//If guide curves, lastly change your quad_remesh_parameters.GuideCurveInfluence if using curves
var remeshed = Mesh.QuadRemeshBrep(brep, quad_remesh_parameters);
Mesh remeshed = Mesh.QuadRemeshBrep(brep, quad_remesh_parameters);

if (remeshed == null)
return Result.Cancel;
Expand All @@ -73,7 +73,7 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)
RhinoApp.WriteLine("1 Brep successfully remeshed");
}
//Remesh a selected Mesh
else if(rhino_object.ObjectType == ObjectType.Mesh)
else if (rhino_object.ObjectType == ObjectType.Mesh)
{
if (!(rhino_object is MeshObject mesh_object))
return Result.Cancel;
Expand All @@ -83,7 +83,7 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)
return Result.Cancel;

//Do the remeshing of the Mesh Objects Mesh Geometry
var remeshed = mesh_object.MeshGeometry.QuadRemesh(quad_remesh_parameters);
Mesh remeshed = mesh_object.MeshGeometry.QuadRemesh(quad_remesh_parameters);

if (remeshed == null)
return Result.Cancel;
Expand Down
Loading

0 comments on commit c9b3ca2

Please sign in to comment.