### GET /get_license Example Request Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinocommon/cloudzoo/cloudzoo-implement-http-callbacks/index.md This is an example of a GET request to retrieve information about a specific license. It requires 'aud' (product ID) and 'key' (license key) as query parameters. ```http GET /get_license?aud=PRODUCT_ID&key=A_LICENSE_KEY ``` -------------------------------- ### Node.js Setup: Install Compute Libraries Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/compute/compute-javascript-getting-started/index.md Install the necessary rhino3dm and compute-rhino3d libraries for your Node.js project using npm. ```bash npm i rhino3dm compute-rhino3d ``` -------------------------------- ### Basic Python Syntax Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/samples/rhinopython/hello-python/index.md Introduces basic Python syntax for printing output, assigning variables, and understanding data types. Use this to get started with simple script execution. ```Python # Basic syntax for writing python scripts print("Hello Python!") # <- any line that begins with the pound symbol is a comment # assign a variable x=123 # print out the type of the variable print(type(x)) # print out the value of the variable print(x) # combine statements with commas to print a single line print("x is a {} and has a value of {}".format(type(x), x)) ``` -------------------------------- ### Show MessageBox with Options Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/eto/existing-dialogs/_index.md Use MessageBox.Show to display a message to the user and get their input. This example shows how to present a question with Yes/No options and then display a different message based on the user's response. It's useful for confirming actions or gathering simple user decisions. ```cs using Eto.Forms; var result = MessageBox.Show("Would you like to save before closing?", MessageBoxButtons.YesNo, MessageBoxType.Question, MessageBoxDefaultButton.Yes); if (result != DialogResult.Yes) { MessageBox.Show("Model discarded successfully!", MessageBoxButtons.OK, MessageBoxType.Information); } else { MessageBox.Show("Model saved successfully before closing.", MessageBoxButtons.OK, MessageBoxType.Information); } ``` ```py import scriptcontext as sc import Eto.Forms as ef from Rhino.UI import RhinoEtoApp parent = RhinoEtoApp.MainWindowForDocument(sc.doc) result = ef.MessageBox.Show("Would you like to save before closing?", ef.MessageBoxButtons.YesNo, ef.MessageBoxType.Question, ef.MessageBoxDefaultButton.Yes) if result != ef.DialogResult.Yes: ef.MessageBox.Show("Model discarded successfully!", ef.MessageBoxButtons.OK, ef.MessageBoxType.Information) else: ef.MessageBox.Show("Model saved successfully before closing.", ef.MessageBoxButtons.OK, ef.MessageBoxType.Information) ``` -------------------------------- ### Basic RhinoCommon C# Example Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/layouts/samples/rhinocommon/single.html A simple C# example demonstrating basic RhinoCommon operations. This snippet is useful for getting started with RhinoCommon scripting in C#. ```csharp using Rhino.Geometry; using Rhino.Commands; namespace RhinoCommonSamples { public class SimpleCommand : Command { public override string EnglishName => "SimpleCommand"; protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Create a simple line Point3d startPoint = new Point3d(0, 0, 0); Point3d endPoint = new Point3d(10, 0, 0); Line line = new Line(startPoint, endPoint); Curve curve = Curve.CreateFromLine(line); // Add the curve to the document doc.Objects.AddCurve(curve); doc.Views.Redraw(); return Result.Success; } } } ``` -------------------------------- ### Display 'Hello World' Message Box Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinopython/your-first-python-script-in-rhino-windows/index.md This script imports the rhinoscriptsyntax library and displays a simple message box with 'Hello World'. It's the most basic example for getting started with RhinoPython. ```python import rhinoscriptsyntax as rs rs.MessageBox ("Hello World") ``` -------------------------------- ### ConfigureCell and CreateCell in C# Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/eto/cells/_index.md Example demonstrating how to set up CreateCell for control instantiation and ConfigureCell for updating control properties based on data context in C#. ```cs var customCell = new CustomCell(); customCell.CreateCell = (args) => new TextBox(); customCell.ConfigureCell = (args, control) => { if (control is not TextBox textBox) return; textBox.Text = args.Item?.ToString(); }; ``` -------------------------------- ### Start Renderer Implementation Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinocommon/render-engine-integration-interactive-viewport/index.md Implement the StartRenderer method to initialize the render engine, set up rendering parameters, and begin the rendering thread. This is the entry point for the rendering process. ```cs public override bool StartRenderer(int w, int h, RhinoDoc doc, ViewInfo view, ViewportInfo viewportInfo, bool forCapture, RenderWindow renderWindow) { _started = true; // prepare render, get a changequeue _width = (int)w; _height = (int)h; reng = new MockingRender(Rhino.PlugIns.PlugIn.IdFromName("MockingBirdViewport"), doc.RuntimeSerialNumber, view, renderWindow) { MaxPasses = 50 }; reng.MaxPassesCompleted += Reng_MaxPassesCompleted; reng.PassRendered += Reng_PassRendered; reng.RenderReset += Reng_RenderReset; reng.RenderStarted += Reng_RenderStarted; MaxPassesChanged += MockingRealtimeDisplayMode_MaxPassesChanged; // start rendering _startTime = DateTime.Now; _isCompleted = false; _theThread = new Thread(reng.ColorPixels) {Name = "MockingBirdViewport thread"}; _theThread.Start(); return true; } ``` -------------------------------- ### Configure rhino-compute environment variables Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/compute/compute-linux-getting-started/index.md Copies the example environment file and opens it with nano for editing. Set RHINO_TOKEN and RHINO_COMPUTE_KEY. ```bash cp /etc/rhino-compute/environment.example /etc/rhino-compute/environment nano /etc/rhino-compute/environment # control + x, y, enter to save the file and exit nano ``` -------------------------------- ### Get rhinocode Version Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/scripting/advanced-cli/index.md Verify the installation and version of the rhinocode utility by using the -V argument. ```text $ rhinocode -V 8.11.24224 ``` -------------------------------- ### Example manifest.yml Content Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/yak/creating-a-rhino-plugin-package/index.md This is an example of a completed manifest.yml file. Ensure you fill in all necessary details such as name, version, authors, description, URL, icon, and keywords. ```yaml --- name: tamarin version: 1.0.0 authors: - Park Ranger description: > This plug-in does something. I'm not really sure exactly what it's supposed to do, but it does it better than any other plug-in. url: https://example.com icon: icon.png keywords: - something ``` -------------------------------- ### Ordered List Example Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/general/developer-docs-style-guide/index.md Ordered lists are created by starting each list item with a number followed by a period. ```markdown This is an ordered list: 1. Item one. 1. Item two. 1. Item three. ``` -------------------------------- ### Get Flamingo Plant Points Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/samples/rhinoscript/get-flamingo-plant-points/index.md Use this script to get the file name of a Flamingo plant, retrieve its point cloud data, and add the points to the Rhino scene. Ensure the Flamingo plugin is installed and accessible. ```vbnet Option Explicit Call Main() Sub Main() Dim objPlugIn, plant, points, count On Error Resume Next Set objPlugIn = Rhino.GetPluginObject("8008880f-8d13-4b2d-92b0-727e12878a4c") If Err Then MsgBox Err.Description Exit Sub End If plant = objPlugIn.GetPlantFileName("") If Not IsNull(plant) Then points = objPlugIn.GetPlantPointCloud(plant) If Not IsNull(points) Then count = UBound(points) If count > 0 Then Rhino.AddPointCloud points Rhino.Redraw() End If End If End If Set objPlugIn = Nothing End Sub ``` -------------------------------- ### Rhino 7: Bootstrap Step 1 Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/kr/compute/deploy-to-iis/index.md Use this command to download and run the initial bootstrap script for Rhino 7. This installs Rhino and IIS. You will be prompted for your email, API key, and Rhino token. ```powershell $F="/bootstrap_step-1.zip";$T="$($Env:temp)\tmp$([convert]::tostring((get-random 65535),16).padleft(4,'0')).tmp"; New-Item -ItemType Directory -Path $T; iwr -useb https://raw.githubusercontent.com/mcneel/compute.rhino3d/7.x/script/production/bootstrap_step-1.zip -outfile $T$F; Expand-Archive $T$F -DestinationPath $T; Remove-Item $T$F;& "$T\bootstrap_step-1\boostrap_step-1.ps1" ``` -------------------------------- ### Basic Rhino.Compute Workflow in C# Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/compute/compute-net-getting-started/index.md This example shows the standard workflow for calling methods using Rhino.Compute. It first creates a sphere using Rhino3dm locally, then uses Rhino.Compute to convert the Brep to a mesh, and finally uses Rhino3dm to count the mesh vertices. Assumes Rhino.Compute is running locally at http://localhost:6500. ```C# using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Rhino.Compute; namespace TestCompute { class Program { static void Main(string[] args) { // Uses standard Rhino3dm methods locally to create a sphere. var sphere = new Rhino.Geometry.Sphere(Rhino.Geometry.Point3d.Origin, 12); var sphereAsBrep = sphere.ToBrep(); // the following function calls rhino.compute to get access to something not // available in Rhino3dm. In this case send a Brep to Compute and get a Mesh back. var meshes = MeshCompute.CreateFromBrep(sphereAsBrep); // Use regular Rhino3dm local calls to count the vertices in the mesh. Console.WriteLine($"Got {meshes.Length} meshes"); for (int i = 0; i < meshes.Length; i++) { Console.WriteLine($" {i + 1} mesh has {meshes[i].Vertices.Count} vertices"); } Console.WriteLine("press any key to exit"); Console.ReadKey(); } } } ``` -------------------------------- ### Get Object Guid in Rhino Python Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinopython/python-user-input/index.md Use rs.GetObject() to prompt the user to pick an object in the scene. The function returns the object's Guid, which can be used to reference it in other commands. An optional message can be displayed to the user. ```python import rhinoscriptsyntax as rs objectId = rs.GetObject("Pick any object") if objectId: print objectID ``` -------------------------------- ### Get Curve Tangent Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/grasshopper/csharp-essentials/3-rhinocommon-geometry/index.md Retrieves the tangent vector at the start of a curve. This indicates the curve's direction at its beginning. ```csharp // Get the tangent at start of a curve Vector3d startTangent = crv.TangentAtStart; ``` -------------------------------- ### Example .rhi File Structure (Tree) Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/general/rhino-installer-engine/index.md Demonstrates a tree-like file structure within a .rhi package, organizing plug-ins by Rhino version. ```text Marmoset_tree.rhi/ ├── Rhino 6/ │ ├── Marmoset.rhp │ ├── Marmoset.dll │ └── Marmoset.rui └── Rhino 5.0/ ├── x86/ │ ├── Marmoset.rhp │ └── ... └── x64/ ├── Marmoset.rhp └── ... ``` -------------------------------- ### Working with Python Dictionaries Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinopython/python-datatypes/index.md Provides examples of creating dictionaries, updating values, adding new key-value pairs, and checking for key existence. ```python room_num = {'john': 425, 'tom': 212} room_num['john'] = 645 # set the value associated with the 'john' key to 645 print (room_num['tom']) # print the value of the 'tom' key. room_num['isaac'] = 345 # Add a new key 'isaac' with the associated value print (room_num.keys()) # print out a list of keys in the dictionary print ('isaac' in room_num) # test to see if 'issac' is in the dictionary. This returns true. ``` -------------------------------- ### Get Curve Endpoints Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/grasshopper/csharp-essentials/3-rhinocommon-geometry/index.md Retrieves the start and end points of a curve. These points define the spatial extent of the curve. ```csharp // Get the start & end points of a curve Point3d startPoint = crv.PointAtStart; Point3d endPoint = crv.PointAtEnd; ``` -------------------------------- ### Access Module Procedures Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinopython/python-procedures/index.md Access procedures within an imported module by prefixing the procedure name with the module name and a period. This example shows how to get the current time. ```Python import time print (time.strftime("%H:%M:%S")) #strftime is a proccedure in the time module. ``` -------------------------------- ### ConfigureCell and CreateCell in Python Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/eto/cells/_index.md Example showing the implementation of CreateCell for creating controls and ConfigureCell for setting control properties from data context in Python. ```py def create(args): return ef.TextBox() def config(args, control): control.Text = str(args.Item) custom_cell = ef.CustomCell() custom_cell.CreateCell = create custom_cell.ConfigureCell = config ``` -------------------------------- ### POST /add_license Example Request Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinocommon/cloudzoo/cloudzoo-implement-http-callbacks/index.md This is an example of a POST request to determine if a license can be added to an entity. It includes details about the entity, the license, and the user requesting the addition. The 'precondition' field is optional. ```json { "entityId": "9304194021213-|-Group", "entityType": "Group", "license": { "key": "RH50-ABCD-EFGZ-HIJK-LMNO", "aud": "PRODUCT-ID-HERE" }, "userInfo": { "sub": "43190412048124", "email": "marley_the_dog@mcneel.com", "com.rhino3d.accounts.emails": [ "marley_the_dog@mcneel.com", "marleyz121@gmail.com" ], "com.rhino3d.accounts.member_groups": [ { "id": "9304194021213", "name": "Marley’s Friends LLC" } ], "com.rhino3d.accounts.admin_groups": [], "com.rhino3d.accounts.owner_groups": [], "name": "Marley", "locale": "en-gb", "picture": "http://marley.the.dog.com/images/coolpic.png" }, "precondition": "RH40-ABCD-EFGZ-HIJK-LMNO" } ``` -------------------------------- ### Maelstrom Space Morph Example Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/samples/rhinocommon/space-morph/index.md Applies a Maelstrom space morph to a selected object. This morph deforms geometry based on a starting radius, ending radius, and a twist angle. ```csharp public static Rhino.Commands.Result Maelstrom(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to maelstrom", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) return rc; Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); double radius0 = Rhino.RhinoMath.UnsetValue; rc = Rhino.Input.RhinoGet.GetNumber("Starting radius", false, ref radius0); if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius0)) return rc; double radius1 = Rhino.RhinoMath.UnsetValue; rc = Rhino.Input.RhinoGet.GetNumber("Ending radius", false, ref radius1); if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(radius1)) return rc; double angle = Rhino.RhinoMath.UnsetValue; rc = Rhino.Input.RhinoGet.GetNumber("Twist angle in degrees", false, ref angle); if (rc != Rhino.Commands.Result.Success || !Rhino.RhinoMath.IsValidDouble(angle)) return rc; Rhino.Geometry.Morphs.MaelstromSpaceMorph morph = new Rhino.Geometry.Morphs.MaelstromSpaceMorph(plane, radius0, radius1, Rhino.RhinoMath.ToRadians(angle)); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return Rhino.Commands.Result.Success; } ``` -------------------------------- ### Rounding Examples with Factors Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinoscript/rounding-numbers/index.md Illustrates the effects of different rounding functions with specific factors, showing how to round to various decimal places or increments. ```vbnet AsymArith(2.5) ``` ```vbnet BRound(2.18, 20) ``` ```vbnet SymDown(25, .1) ``` -------------------------------- ### Getting Points from a NurbsSurface using clr.Reference Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinopython/python-reference/index.md Example of calling RhinoCommon's NurbsSurfacePointList.GetPoint method with by-ref parameters using clr.Reference objects. This avoids the need for the Overloads method. ```python import clr import Rhino import rhinoscriptsyntax as rs srf_id = rs.GetObject("Select surface", rs.filter.surface) srf = rs.coercesurface(srf_id) ns = srf.ToNurbsSurface() pt3d = clr.Reference[Rhino.Geometry.Point3d]() for u in range(0, ns.Points.CountU): for v in range(0, ns.Points.CountV): if ns.Points.GetPoint(u, v, pt3d): print pt3d pt4d = clr.Reference[Rhino.Geometry.Point4d]() for u in range(0, ns.Points.CountU): for v in range(0, ns.Points.CountV): if ns.Points.GetPoint(u, v, pt4d): print pt4d ``` -------------------------------- ### Install .NET SDK on Ubuntu/AmazonLinux Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/compute/compute-linux-getting-started/index.md Installs the .NET SDK required for Rhino.Compute. Ensure you use the correct version specified. ```bash wget https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh -O dotnet-install.sh chmod +x ./dotnet-install.sh ./dotnet-install.sh --version 9.0.102 --install-dir /usr/share/ủshare/dotnet ``` -------------------------------- ### Usage Example for Retrieving Object Attributes Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/opennurbs/getting-object-attributes/index.md Demonstrates how to use the helper functions ON_LayerFromAttributes, ON_MaterialFromAttributes, and ON_GroupsFromAttributes to get layer, material, and group information from an object's attributes. ```cpp const ON_3dmObjectAttributes* attributes = model_geometry->Attributes(nullptr); if (nullptr != attributes) { // Try getting layer const ON_Layer* layer = ON_LayerFromAttributes(model, *attributes); if (nullptr != layer) { // TODO... } // Try getting material const ON_Material* material = ON_MaterialFromAttributes(model, *attributes); if (nullptr != material) { // TODO... } // Try getting groups ON_SimpleArray groups; const int group_count = ON_GroupsFromAttributes(model, *attributes, groups); for (int i = 0; i < group_count; i++) { const ON_Group* group = groups[i]; if (nullptr != group) { // TODO... } } } } ``` -------------------------------- ### Example Data Tree Paths (Verbose) Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/grasshopper/the-why-and-how-of-data-trees/index.md Illustrates a data tree with many zero-padded path elements, demonstrating a less economical representation. ```csharp {0;0;0;0;0} {0;0;0;0;1} {0;0;0;0;2} {0;0;0;0;3} {0;0;1;0;0} {0;0;1;0;1} {0;0;1;0;2} {0;0;1;0;3} ``` -------------------------------- ### Cubic Periodic Knot Vector Example Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/opennurbs/periodic-curves-and-surfaces/index.md Illustrates the structure of a cubic periodic knot vector. The pattern of knot value differences repeats, ensuring continuity at the start and end points. ```mathematica {a,b,c,d,e, ..., p+a,p+b,p+c,p+d,p+e} ``` -------------------------------- ### Create targetver.h for Target Platform Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/cpp/migrate-your-plugin-manual-windows/index.md Create a new header file named targetver.h and add the provided content. This file specifies the target Windows platform for your plugin, which is crucial for compatibility. ```cpp #pragma once // Including SDKDDKVer.h defines the highest available Windows platform. // If you wish to build your application for a previous Windows platform, // include WinSDKVer.h and set the _WIN32_WINNT macro to the platform you // wish to support before including SDKDDKVer.h. #include "rhinoSdkWindowsVersion.h" #include ``` -------------------------------- ### Example Data Tree Paths (Economical) Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/grasshopper/the-why-and-how-of-data-trees/index.md Shows a more concise representation of the same data structure, highlighting the benefits of simplified paths. ```csharp {0;0} {0;1} {0;2} {0;3} {1;0} {1;1} {1;2} {1;3} ``` -------------------------------- ### Prompt for Singular TriState Value (C#) Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/grasshopper/simple-parameters/index.md Implement the `Prompt_Singular` method to get a single TriStateType value from the user. This example uses `Rhino.Input.Custom.GetOption` to present 'True', 'False', and 'Unknown' options. ```csharp protected override Kernel.GH_GetterResult Prompt_Singular(ref TriStateType value) { Rhino.Input.Custom.GetOption() go = New Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("TriState value"); go.AcceptNothing(true); go.AddOption("True"); go.AddOption("False"); go.AddOption("Unknown"); switch (go.Get()) { case Rhino.Input.GetResult.Option: if (go.Option().EnglishName == "True") { value = new TriStateType(1); } if (go.Option().EnglishName == "False") { value = new TriStateType(0); } if (go.Option().EnglishName == "Unknown") { value = new TriStateType(-1); } return GH_GetterResult.success; case Rhino.Input.GetResult.Nothing: return GH_GetterResult.accept; default: return GH_GetterResult.cancel; } } ``` -------------------------------- ### Build Project with .NET CLI Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/scripting/projects-publish/index.md After a project is built, you can use the `dotnet` command-line utility to build the project from the command line. This is useful for further customization and development. ```text cd ~/MyProject dotnet build ``` -------------------------------- ### Mark Points on a Line with RhinoScript Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/samples/rhinoscript/mark-points-on-a-line/index.md This script draws a line, adds points at its start, middle, and end, and then removes the line. It includes setup for running the script automatically on Rhino startup. ```vbnet ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' MarkLine.rvb -- March 2010 ' If this code works, it was written by Dale Fugier. ' If not, I don't know who wrote it. ' Works with Rhino 4.0. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub MarkLine() Dim arrLast Call Rhino.Command("_Line _Pause _Pause") If (Rhino.LastCommandResult() = 0) Then Call Rhino.EnableRedraw(False) arrLast = Rhino.LastCreatedObjects() If IsArray(arrLast) Then Call Rhino.AddPoint(Rhino.CurveStartPoint(arrLast(0))) Call Rhino.AddPoint(Rhino.CurveMidPoint(arrLast(0))) Call Rhino.AddPoint(Rhino.CurveEndPoint(arrLast(0))) Call Rhino.DeleteObjects(arrLast) End If Call Rhino.EnableRedraw(True) End If End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Call Rhino.AddStartupScript(Rhino.LastLoadedScriptFile) Call Rhino.AddAlias("MarkLine", "_NoEcho _-RunScript (MarkLine)") ``` -------------------------------- ### Get Flamingo Material List using RhinoScript Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/samples/rhinoscript/get-flamingo-material-list/index.md Use this script to retrieve a list of Flamingo nXt materials from the current Rhino document. Ensure the Flamingo nXt plugin is installed and accessible. ```VBScript Option Explicit Call Main() Sub Main() Dim objPlugIn, materials, i, count, material On Error Resume Next Set objPlugIn = Rhino.GetPluginObject("8008880f-8d13-4b2d-92b0-727e12878a4c") If Err Then MsgBox Err.Description Exit Sub End If materials = objPlugIn.GetMaterials() If IsNull(materials) Then Rhino.Print("Error getting Flamingo nXt material list") Else count = UBound(materials) Rhino.Print("==============================================================================") Rhino.Print("Flamingo nXt Material List") Rhino.Print("------------------------------------------------------------------------------") If count < 0 Then Rhino.Print("No Flamingo materials in the current document") End If For i = 0 to count Set material = materials(i) If IsObject(material) Then Rhino.Print("Material " & (i + 1) & ": ID: " & material.Id & " Name: " & material.Name) End If Next End If Set material = Nothing Set objPlugIn = Nothing End Sub ``` -------------------------------- ### Basic Script-Mode Example in C# Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/scripting/scripting-gh-csharp/index.md A simple C# script demonstrating Script-Mode. Input parameters are automatically available in the global scope. ```csharp a = "Hello " + x; ``` -------------------------------- ### Install Ubuntu via WSL2 Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/compute/compute-linux-getting-started/index.md Installs the default Ubuntu image on Windows using the Windows Subsystem for Linux (WSL2). This command is run in PowerShell. ```powershell wsl --install ``` -------------------------------- ### Get Flamingo Material Assignment Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/samples/rhinoscript/get-flamingo-material/index.md Use this script to select an object in Rhino and retrieve its assigned Flamingo nXt material ID and name. Ensure the Flamingo nXt plugin is installed and loaded. ```vbnet Option Explicit Call Main() Sub Main() Dim objPlugIn, strObject, strMaterial On Error Resume Next Set objPlugIn = Rhino.GetPluginObject("8008880f-8d13-4b2d-92b0-727e12878a4c") If Err Then MsgBox Err.Description Exit Sub End If strObject = Rhino.GetObject("Select object") If Not IsNull(strObject) And Not strObject = "" Then strMaterial = objPlugIn.GetMaterialId(strObject) If Not IsNull(strMaterial) And Not strMaterial = "" Then Rhino.Print("Object assigned to Flamingo nXt material ID: " + strMaterial + " Name: " + objPlugIn.GetMaterialName(strMaterial)) Else Rhino.Print("Object does not have a Flamingo nXt material assigned") End If End If Set objPlugIn = Nothing End Sub ``` -------------------------------- ### RhinoScript vs. Python for Adding a Line Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinopython/what-is-rhinopython/index.md Compares RhinoScript and Python syntax for a common task: getting two points from the user and adding a line. The Python example uses the `rhinoscriptsyntax` package. ```vbnet Dim arrStart, arrEnd arrStart = Rhino.GetPoint("Start of line") If IsArray(arrStart) Then arrEnd = Rhino.GetPoint("End of line") If IsArray(arrEnd) Then Rhino.AddLine arrStart, arrEnd End If End If ``` ```py import rhinoscriptsyntax as rs start = rs.GetPoint("Start of line") if start: end = rs.GetPoint("End of line") if end: rs.AddLine(start,end) ``` -------------------------------- ### View Data and Logic Example (C#) Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/eto/view-and-data/view-models/_index.md Illustrates properties and methods that are specific to the UI, such as visibility, appearance, and view-related actions. This code should be kept separate from core application logic. ```csharp // Data private bool IsButtonVisible { get; } private static float BorderThickness { get; } public Color BackgroundColour { get; } // Methods internal void RedrawView(); internal void CloseView(); ``` -------------------------------- ### Prompt for Singular TriState Value (VB.NET) Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/grasshopper/simple-parameters/index.md Implement the `Prompt_Singular` function to get a single TriStateType value from the user. This VB.NET example uses `Rhino.Input.Custom.GetOption` to present 'True', 'False', and 'Unknown' options. ```vbnet Protected Overrides Function Prompt_Singular(ByRef value As TriStateType) As Kernel.GH_GetterResult Dim go As New Rhino.Input.Custom.GetOption() go.SetCommandPrompt("TriState value") go.AcceptNothing(True) go.AddOption("True") go.AddOption("False") go.AddOption("Unknown") Select Case go.Get() Case Rhino.Input.GetResult.Option If (go.Option().EnglishName = "True") Then value = New TriStateType(1) If (go.Option().EnglishName = "False") Then value = New TriStateType(0) If (go.Option().EnglishName = "Unknown") Then value = New TriStateType(-1) Return GH_GetterResult.success Case Rhino.Input.GetResult.Nothing Return GH_GetterResult.accept Case Else Return GH_GetterResult.cancel End Select End Function ``` -------------------------------- ### Example .rhi File Structure (Flat) Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/general/rhino-installer-engine/index.md Illustrates a flat file structure within a .rhi package, where files are not explicitly organized by Rhino version. ```text Marmoset_flat.rhi/ ├── Marmoset_rhino6.rhp ├── Marmoset_rhino5_x86.rhp ├── Marmoset_rhino5_x64.rhp ├── Marmoset_rhino6.dll ├── ... └── Marmoset.rui ``` -------------------------------- ### Create and Configure a WebView in Eto.Forms Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/rhinopython/eto-controls-python/index.md Instantiate a WebView control, set its dimensions, and specify the initial URL to display. The URL must be a System.Uri object. ```python # Create a WebView self.m_webview = forms.WebView() self.m_webview.Size = drawing.Size(300, 400) self.m_webview.Url = System.Uri('http://developer.rhino3d.com/guides/rhinopython/') ``` -------------------------------- ### C# Custom Cell Example Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/eto/cells/_index.md Demonstrates creating a custom cell in C# that mimics a TextBoxCell for displaying item text in a GridView. This snippet shows the basic setup for CustomCell, CreateCell, and ConfigureCell. ```cs using System.Linq; using Eto.Forms; using Rhino.UI; var items = Enumerable.Range(0, 100).Cast(); var customCell = new CustomCell(); customCell.CreateCell = (args) => new TextBox(); customCell.ConfigureCell = (args, ctrl) => (ctrl as TextBox).Text = args.Item?.ToString(); var dialog = new Dialog() { Height = 200, Content = new GridView() { Columns = { new GridColumn() { HeaderText = "Value", DataCell = customCell }, }, DataStore = items }, }; var parent = RhinoEtoApp.MainWindowForDocument(__rhino_doc__); dialog.ShowModal(parent); ``` -------------------------------- ### Configure Plugin to Load at Startup Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/cpp/loading-plugins-at-startup/index.md Override the CRhinoPlugIn::PlugInLoadTime() virtual function to return CRhinoPlugIn::load_plugin_at_startup. This ensures the plugin is loaded when Rhino initializes. ```cpp // Description: // Called by Rhino when writing plug-in information to the registry. This // information will be read the next time Rhino starts to identify properly // installed plug-ins. CRhinoPlugIn::plugin_load_time CTestPlugIn::PlugInLoadTime() { return CRhinoPlugIn::load_plugin_at_startup; } ``` -------------------------------- ### Get and Set Active View (Python) Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/samples/rhinocommon/get-and-set-the-active-view/index.md This Python snippet achieves the same functionality as the C# example, allowing users to select and set a different view as active. It uses RhinoCommon's input and view management capabilities. ```python from Rhino.Commands import Result from Rhino.Input.Custom import GetString from scriptcontext import doc def RunCommand(): # view and view names active_view_name = doc.Views.ActiveView.ActiveViewport.Name non_active_views = [(view.ActiveViewport.Name, view) for view in doc.Views if view.ActiveViewport.Name != active_view_name] # get name of view to set active gs = GetString() gs.SetCommandPrompt("Name of view to set active") gs.AcceptNothing(True) gs.SetDefaultString(active_view_name) for view_name, _ in non_active_views: gs.AddOption(view_name) result = gs.Get() if gs.CommandResult() != Result.Success: return gs.CommandResult() selected_view_name = "{0}".format(gs.StringResult()) if gs.Option() != None: selected_view_name = gs.Option().EnglishName if selected_view_name != active_view_name: if selected_view_name in [seq[0] for seq in non_active_views]: doc.Views.ActiveView = [seq[1] for seq in non_active_views if seq[0] == selected_view_name][0] else: print("\"{0}\" is not a view name".format(selected_view_name)) return Result.Success if __name__ == "__main__": RunCommand() ``` -------------------------------- ### Add Command Line Options in Python Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/samples/rhinocommon/add-command-line-options/index.md Use RhinoCommon's custom 'Get' classes to add command-line options like integer, double, toggle, and list to your commands. This example shows how to set up and retrieve values for these options. ```Python import Rhino import scriptcontext def CommandLineOptions(): # For this example we will use a GetPoint class, but all of the custom # "Get" classes support command line options. gp = Rhino.Input.Custom.GetPoint() gp.SetCommandPrompt("GetPoint with options") # set up the options intOption = Rhino.Input.Custom.OptionInteger(1, 1, 99) dblOption = Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9) boolOption = Rhino.Input.Custom.OptionToggle(True, "Off", "On") listValues = "Item0", "Item1", "Item2", "Item3", "Item4" gp.AddOptionInteger("Integer", intOption) gp.AddOptionDouble("Double", dblOption) gp.AddOptionToggle("Boolean", boolOption) listIndex = 3 opList = gp.AddOptionList("List", listValues, listIndex) while True: # perform the get operation. This will prompt the user to # input a point, but also allow for command line options # defined above get_rc = gp.Get() if gp.CommandResult()!=Rhino.Commands.Result.Success: return gp.CommandResult() if get_rc==Rhino.Input.GetResult.Point: point = gp.Point() scriptcontext.doc.Objects.AddPoint(point) scriptcontext.doc.Views.Redraw() print("Command line option values are") print(" Integer =", intOption.CurrentValue) print(" Double =", dblOption.CurrentValue) print(" Boolean =", boolOption.CurrentValue) print(" List =", listValues[listIndex]) elif get_rc==Rhino.Input.GetResult.Option: if gp.OptionIndex()==opList: listIndex = gp.Option().CurrentListOptionIndex continue break return Rhino.Commands.Result.Success if __name__ == "__main__": CommandLineOptions() ``` -------------------------------- ### Instantiate and Use a C# Structure Source: https://github.com/mcneel/developer.rhino3d.com/blob/main/content/en/guides/grasshopper/csharp-essentials/2-csharp-basics/index.md Demonstrates instantiating a 'ColorPoint' structure using its default constructor, setting its properties, and comparing two instances. Note that the default constructor initializes fields to zero. ```csharp ColorPoint cp0 = new ColorPoint(); // Using default constructor sets the fields to zero Print("Default ColorPoint 0: X=" + cp0.X + ", Y=" + cp0.Y + ", Z=" + cp0.Z + ", Color=" + cp0.C.Name); // Set fields cp0.X = x; cp0.Y = y; cp0.Z = z; cp0.C = c; Print("ColorPoint 0: X=" + cp0.X + ", Y=" + cp0.Y + ", Z=" + cp0.Z + ", Color=" + cp0.C.Name); ColorPoint cp1 = new ColorPoint(); // Set fields cp1.X = x1; cp1.Y = y1; cp1.Z = z1; cp1.C = c1; Print("ColorPoint 1: X=" + cp1.X + ", Y=" + cp1.Y + ", Z=" + cp1.Z + ", Color=" + cp1.C.Name); // Compare location MatchLoc = false; if(cp0.X == cp1.X && cp0.Y == cp1.Y && cp0.Z == cp1.Z) MatchLoc = true; // Compare color MatchColor = cp0.C.Equals(cp1.C); ```