HostUtils

public static class HostUtils
Contains static methods to deal with the runtime environment.

Properties

ComputerSerialNumber

#Since v6.0
public static string ComputerSerialNumber { get; }
Gets the serial number of the computer running Rhino.

CurrentOSLanguage

#Since v6.8
[CLSCompliant(false)] public static uint CurrentOSLanguage { get; }
Get the current operating system language.
A Windows LCID (on Windows and macOS). On Windows, this will be LCID value regardless of those languages that Rhino supports. On macOS, this only returns LCID values for languages that Rhino does support.

DeviceId

#Since v6.0
public static Guid DeviceId { get; }
The DeviceId is a unique, stable ID that anonymously identifies the device that Rhino is running on. It is computed based on hardware information that should not change when the OS is upgraded, or if commonly modified hardware are added or removed from the computer. The machine-specific information is hashed using a cryptographic hash to make it anonymous.

DeviceName

#Since v6.0
public static string DeviceName { get; }
Name of the computer running Rhino. If the computer is part of a Windows Domain, the computer name has "@[DOMAIN]" appended.

IsPreRelease

#Since v7.22
public static bool IsPreRelease { get; }
Returns true when Rhino build is Beta or WIP, false otherwise

OperatingSystemBuildNumber

#Since v6.15
public static string OperatingSystemBuildNumber { get; }
Returns Operating System Build Number "11763" | "7601" | ... | "Unknown"

OperatingSystemEdition

#Since v6.15
public static string OperatingSystemEdition { get; }
Returns Operating System Edition: "Professional" | "ServerDatacenter" | ... | "Unknown"

OperatingSystemInstallationType

#Since v6.15
public static string OperatingSystemInstallationType { get; }
Returns Operating System Installation Type: "Client" | "Server" | "Unknown"

OperatingSystemProductName

#Since v6.15
public static string OperatingSystemProductName { get; }
Returns Operating System Edition: "Professional" | "ServerDatacenter" | ... | "Unknown"

OperatingSystemVersion

#Since v6.15
public static string OperatingSystemVersion { get; }
Returns Operating System Version "6.1" | "6.3" | ... | "Unknown"

RhinoAssemblyDirectory

#Since v8.0
public static string RhinoAssemblyDirectory { get; }
Gets the Rhino system managed assembly directory.

RunningAsRhinoInside

#Since v7.0
public static bool RunningAsRhinoInside { get; }
Indicates whether Rhino is running inside another application. returns false if Rhino.exe is the top-level application. returns true if some other application is the top-level application.

RunningInDarkMode

#Since v6.19
public static bool RunningInDarkMode { get; }
Returns true if the host operating system is in dark mode and Rhino supports dark mode.

RunningInMono

#Since v5.0
public static bool RunningInMono { get; }
Tests if this process is currently executing under the Mono runtime.

RunningInNetCore

#Since v8.0
public static bool RunningInNetCore { get; }
Tests if this process is currently executing under the .NET Core runtime.

RunningInNetFramework

#Since v8.0
public static bool RunningInNetFramework { get; }
Tests if this process is currently executing under the .NET Framework runtime.

RunningInRhino

#Since v5.0
public static bool RunningInRhino { get; }
Tests if RhinoCommon is currently executing inside of the Rhino.exe process. There are other cases where RhinoCommon could be running; specifically inside of Visual Studio when something like a windows form is being worked on in the resource editor or running stand-alone when compiled to be used as a version of OpenNURBS.

RunningInWindowsContainer

#Since v7.1
public static bool RunningInWindowsContainer { get; }
Tests if this process is currently executing inside a Windows Container.

RunningOniOS

#Since v5.0
public static bool RunningOniOS { get; }
Tests if this process is currently executing on the iOS platform.

RunningOnLinux

#Since v9.0
public static bool RunningOnLinux { get; }
Tests if this process is currently executing on the Linux platform.

RunningOnOSX

#Since v5.0
public static bool RunningOnOSX { get; }
Tests if this process is currently executing on the Mac OSX platform.

RunningOnServer

#Since v7.8
public static bool RunningOnServer { get; }
Tests if this process is currently executing in a server-like installation environment: Windows Server, or an AWS Marketplace instance (OperatingSystemInstallationType = "MarketplaceAWS"). Both share the headless-server behavior model — RHINO_TOKEN-based auth, non-interactive licensing UI, no local license discovery.

RunningOnWindows

#Since v5.0
public static bool RunningOnWindows { get; }
Tests if this process is currently executing on the Windows platform.

SendDebugToCommandLine

#Since v5.0
public static bool SendDebugToCommandLine { get; set; }
Gets or sets whether debug messages are printed to the command line.

Methods

AutoInstallPlugInFolder

#Since v6.0
public static string AutoInstallPlugInFolder(bool currentUser)
Gets the auto install plug-in folder for machine or current user.
currentUser (bool)true if the query relates to the current user.
The full path to the revelant auto install plug-in directory.

CallFromCoreRhino

#Since v6.0
public static int CallFromCoreRhino(string task)
Don't change this function in ANY way unless you chat with Steve first! This function is called by Rhino on initial startup and the signature must be exact
task (string)

CheckForRdk

#Since v5.0
public static bool CheckForRdk(bool throwOnFalse, bool usePreviousResult)
Determines if the RDK is loaded.
throwOnFalse (bool)if the RDK is not loaded, then throws a RdkNotLoadedException.
usePreviousResult (bool)if true, then the last result can be used instaed of performing a full check.
true if the RDK is loaded; false if the RDK is not loaded. Note that the RdkNotLoadedException will hinder the retrieval of any return value.

ClearFpuExceptionStatus

#Since v6.0
public static void ClearFpuExceptionStatus()
Clear FPU exception and busy flags (Intel assembly fnclex)

CreateCommands

#Since v5.0
public static int CreateCommands(nint pPlugIn, Assembly pluginAssembly)
Parses a plugin and create all the commands defined therein.
pPlugIn (nint)Plugin to harvest for commands.
pluginAssembly (Assembly)Assembly associated with the plugin.
The number of newly created commands.

CreateCommands

#Since v5.0
public static void CreateCommands(PlugIn plugin)
Parses a plugin and create all the commands defined therein.
plugin (PlugIn)Plugin to harvest for commands.

CreatePlugIn

#Since v5.0
public static PlugIn CreatePlugIn(Type pluginType, bool printDebugMessages)
Instantiates a plug-in type and registers the associated commands and classes.
pluginType (Type)A plug-in type. This type must derive from PlugIn.
printDebugMessages (bool)true if debug messages should be printed.
A new plug-in instance.

DebugDumpToString

#Since v5.0
public static string DebugDumpToString(BezierCurve bezierCurve)
Gets the debug dumps. This is a text description of the geometric contents. DebugDump() is intended for debugging and is not suitable for creating high quality text descriptions of an object.
bezierCurve (BezierCurve)curve to evaluate
A debug dump text.

DebugDumpToString

#Since v5.0
public static string DebugDumpToString(GeometryBase geometry)
Gets the debug dumps. This is a text description of the geometric contents. DebugDump() is intended for debugging and is not suitable for creating high quality text descriptions of an object.
geometry (GeometryBase)Some geometry.
A debug dump text.

DebugString

#Since v5.0
public static void DebugString(string format, params object[] args)
Prints a debug message to the Rhino Command Line. The message will only appear if the SendDebugToCommandLine property is set to true.
format (string)Message to format and print.
args (params object[])An Object array containing zero or more objects to format.

DebugString

#Since v5.0
public static void DebugString(string msg)
Prints a debug message to the Rhino Command Line. The message will only appear if the SendDebugToCommandLine property is set to true.
msg (string)Message to print.

DescribeGeometry

#Since v8.0
public static string DescribeGeometry(GeometryBase geometry)
Returns a description that is similar to the one in the _What command, except for not mentioning units and other attribute data. This description is translated in the current Rhino version.
geometry (GeometryBase)

DisplayOleAlerts

#Since v5.0
public static void DisplayOleAlerts(bool display)
Defines if Ole alerts ("Server busy") alerts should be visualized.

This function makes no sense on Mono.

display (bool)Whether alerts should be visible.

ExceptionReport

#Since v5.0
public static void ExceptionReport(Exception ex)
Informs RhinoCommon of an exception that has been handled but that the developer wants to screen.
ex (Exception)An exception.

ExceptionReport

#Since v5.0
public static void ExceptionReport(string source, Exception ex)
Informs RhinoCommon of an exception that has been handled but that the developer wants to screen.
source (string)An exception source text.
ex (Exception)An exception.

ExecuteNamedCallback

#Since v7.0
public static bool ExecuteNamedCallback(string name, NamedParametersEventArgs args)
Execute a named callback
name (string)
args (NamedParametersEventArgs)

FileNameEndsWithRhinoBackupExtension

#Since v6.0
public static bool FileNameEndsWithRhinoBackupExtension(string fileName)
Strip file extension from file name and check to see if it is a valid Rhino backup file extension.
fileName (string)File name to check.
Returns true if the file name has an extension like 3dmbak.

FileNameEndsWithRhinoExtension

#Since v6.0
public static bool FileNameEndsWithRhinoExtension(string fileName)
Strip file extension from file name and check to see if it is a valid Rhino file extension.
fileName (string)File name to check.
Returns true if the file name has an extension like 3dm.

GetAbsolutePath

#Since v6.0
public static bool GetAbsolutePath(string relativePath, bool bRelativePathisFileName, string relativeTo, bool bRelativeToIsFileName, out string pathOut)
Call this method to convert a relative path to an absolute path relative to the specified path.
relativePath (string)Relative path to convert to an absolute path
bRelativePathisFileName (bool)If true then lpsFrom is treated as a file name otherwise it is treated as a directory name
relativeTo (string)File or folder the path is relative to
bRelativeToIsFileName (bool)If true then lpsFrom is treated as a file name otherwise it is treated as a directory name
pathOut (out string)Reference to string which will receive the computed absolute path
Returns true if parameters are valid and lpsRelativePath is indeed relative to lpsRelativeTo otherwise returns false

GetActivePlugInVersionFolders

#Since v7.17
public static IEnumerable<DirectoryInfo> GetActivePlugInVersionFolders()
Recurses through the auto install plug-in folders and returns the directories containing "active" versions of plug-ins.
Remarks: If the same package is installed in both the user and machine locations, the newest directory wins.

GetActivePlugInVersionFolders

#Since v6.0
public static IEnumerable<DirectoryInfo> GetActivePlugInVersionFolders(bool currentUser)
Recurses through the auto install plug-in folders and returns the directories containing "active" versions of plug-ins.
currentUser (bool)Current user (true) or machine (false).

GetAssemblySearchPaths

#Since v5.0
public static string[] GetAssemblySearchPaths()
Returns list of directory names where additional assemblies (plug-ins, DLLs, Grasshopper components) may be located

GetCurrentProcessInfo

#Since v6.15
public static void GetCurrentProcessInfo(out string processName, out Version processVersion)
Returns information about the current process. If Rhino is the top level process, processName is "Rhino". Otherwise, processName is the name, without extension, of the main module that is executing. For example, "compute.backend" or "Revit". processVersion is the System.Version of the running process. It is the FileVersion of the executable.
processName (out string)
processVersion (out Version)

GetCustomComputeEndpoints

#Since v7.0
public static Tuple<string, Type>[] GetCustomComputeEndpoints()
Used by compute to define custom endpoints

GetPlatformService<T>

#Since v6.0
public static T GetPlatformService<T>(string assemblyPath = null, string typeFullName = null)
For internal use only. Loads an assembly for dependency injection via IPlatformServiceLocator.
assemblyPath (string = null)The relative path of the assembly, relative to the position of RhinoCommon.dll
typeFullName (string = null)The full name of the type that is IPlatformServiceLocator. This is optional.
An instance, or null.

GetPrinterDPI

#Since v8.2
public static double GetPrinterDPI(string printerName, bool horizontal)
Get the output resolution for a given printer.
printerName (string)
horizontal (bool)get the horizontal or vertical resolution
Dot per inch resolution for a given printer on success. 0 if an error occurred

GetPrinterFormMargins

#Since v8.5
public static bool GetPrinterFormMargins(string printerName, string formName, bool portrait, out double leftMillimeters, out double topMillimeters, out double rightMillimeters, out double bottomMillimeters)
Get limit margins for a given form (page size) and a given printer. This is the physical limit area that a printer can print on a given page
printerName (string)
formName (string)
portrait (bool)
leftMillimeters (out double)
topMillimeters (out double)
rightMillimeters (out double)
bottomMillimeters (out double)
true on success

GetPrinterFormNames

#Since v8.0
public static string[] GetPrinterFormNames(string printerName)
Get list of form names available for a given printer
printerName (string)name or printer to query

GetPrinterFormSize

#Since v8.0
public static bool GetPrinterFormSize(string printerName, string formName, out double widthMillimeters, out double heightMillimeters)
Get the size of a sheet for a given form name / printer combination
printerName (string)
formName (string)
widthMillimeters (out double)
heightMillimeters (out double)
true on success

GetPrinterNames

#Since v8.0
public static string[] GetPrinterNames()
Get list of printers available on this system

GetRhinoDotNetAssembly

#Since v5.0
public static Assembly GetRhinoDotNetAssembly()
Only works on Windows. Returns null on Mac.
An assembly.

GetSystemProcessorCount

#Since v7.4
public static int GetSystemProcessorCount()
Get the processor count on this hardware. It supports querying on CPUs with more than 64 processors (Windows).

GetSystemReferenceAssemblies

#Since v8.0
public static IEnumerable<string> GetSystemReferenceAssemblies()
Gets the system reference assemblies to use when compiling code dynamically with Roslyn. Includes RhinoCommon, Rhino.UI, and Eto.
Remarks: Note that this list of assemblies is not guaranteed to be loadable and should only be used when compiling code dynamically.
An enumeration of paths to each of the rhino system assemblies to be used for compilation

InitializeRhinoCommon

#Since v5.0
public static void InitializeRhinoCommon()
Makes sure all static RhinoCommon components is set up correctly. This happens automatically when a plug-in is loaded, so you probably won't have to call this method.
Remarks: Subsequent calls to this method will be ignored.

InitializeRhinoCommon_RDK

#Since v6.0
[MonoPInvokeCallback(HostUtils.InitializeRDKCallback)] public static void InitializeRhinoCommon_RDK()
Makes sure all static RhinoCommon RDK components are set up correctly. This happens automatically when the RDK is loaded, so you probably won't have to call this method.
Remarks: Subsequent calls to this method will be ignored.

InitializeZooClient

#Since v5.6
public static void InitializeZooClient()
Initializes the ZooClient and Rhino license manager, this should get called automatically when RhinoCommon is loaded so you probably won't have to call this method.

InPlaceConstCast

#Since v5.0
public static void InPlaceConstCast(GeometryBase geometry, bool makeNonConst)
DO NOT USE UNLESS YOU ARE CERTAIN ABOUT THE IMPLICATIONS.

This is an expert user function which should not be needed in most cases. This function is similar to a const_cast in C++ to allow an object to be made temporarily modifiable without causing RhinoCommon to convert the class from const to non-const by creating a duplicate.

You must call this function with a true parameter, make your modifications, and then restore the const flag by calling this function again with a false parameter. If you have any questions, please contact McNeel developer support before using!

geometry (GeometryBase)Some geometry.
makeNonConst (bool)A boolean value.

IsManagedDll

#Since v6.0
public static bool IsManagedDll(string path)
Inspects a dll to see if it is compiled as native code or as a .NET assembly
path (string)

IsRhinoBackupFileExtension

#Since v6.0
public static bool IsRhinoBackupFileExtension(string fileExtension)
Check to see if the file extension is a valid Rhino file extension.
fileExtension (string)
Return true if fileExtension is ".3dmbak", "3dmbak", ".3dm.bak", "3dm.bak", ".3dx.bak" or "3dx.bak", ignoring case.

IsRhinoFileExtension

#Since v6.0
public static bool IsRhinoFileExtension(string fileExtension)
Check to see if the file extension is a valid Rhino file extension.
fileExtension (string)
Returns true if fileExtension is ".3dm", "3dm", ".3dx" or "3dx", ignoring case.

LoadAssemblyFrom

#Since v8.0
public static Assembly LoadAssemblyFrom(string path)
Calls Assembly.LoadFrom in .NET 4.8. May call a different routine under .NET Core
path (string)

LoadAssemblyFromName

#Since v8.32
public static Assembly LoadAssemblyFromName(AssemblyName assemblyName)
Calls Assembly.Load(AssemblyName) in .NET 4.8. May call a different routine under .NET Core
assemblyName (AssemblyName)

LoadAssemblyFromStream

#Since v8.23
public static Assembly LoadAssemblyFromStream(Stream stream)
Calls Assembly.Load(byte[]) in .NET 4.8. May call a different routine under .NET Core
stream (Stream)

LogDebugEvent

#Since v8.5
public static void LogDebugEvent(string message)
Logs a debug event. The function will log the filename and line number from where this function is called, in addition to the input message.
message (string)The event message.

RecordInitInstanceTime

#Since v6.0
public static void RecordInitInstanceTime(string description)
Used to help record times at startup with the -stopwatch flag to help determine bottlenecks in start up speed
description (string)

RegisterComputeEndpoint

#Since v7.0
public static void RegisterComputeEndpoint(string endpointPath, Type t)
Register a class that can participate as a compute endpoint
endpointPath (string)
t (Type)

RegisterDynamicCommand

#Since v5.0
public static bool RegisterDynamicCommand(PlugIn plugin, Command cmd)
Adds a new dynamic command to Rhino.
plugin (PlugIn)Plugin that owns the command.
cmd (Command)Command to add.
true on success, false on failure.

RegisterNamedCallback

#Since v6.15
public static void RegisterNamedCallback(string name, EventHandler<NamedParametersEventArgs> callback)
Register a named callback
name (string)
callback (EventHandler<NamedParametersEventArgs>)

RegisterStaticIDisposable

#Since v9.0
public static void RegisterStaticIDisposable(IDisposable disposable)
Statics do not get disposed of in .NET. If you have a static IDisposable that you want to be disposed during shutdown, add your disposable to this list.
disposable (IDisposable)

RemoveNamedCallback

#Since v7.18
public static void RemoveNamedCallback(string name)
Remove a named callback from the dictionary of callbacks
name (string)

RhinoCommonExceptionHandler

#Since v6.0
public static void RhinoCommonExceptionHandler(string title, object sender, Exception ex)
For internal use only!!! Unhanded exception handler, writes stack trace to RhinoDotNet.txt file
title (string)Exception title to write to text file
sender (object)
ex (Exception)

SendLogMessageToCloudCallbackProc

#Since v6.4
[MonoPInvokeCallback(HostUtils.SendLogMessageToCloudCallback)] public static void SendLogMessageToCloudCallbackProc(LogMessageType msg_type, nint pwStringClass, nint pwStringDesc, nint pwStringMessage)
Informs RhinoCommon of an message that has been handled but that the developer wants to screen.
msg_type (HostUtils.LogMessageType)The messag type
pwStringClass (nint)The top level message type.
pwStringDesc (nint)Finer grained description of the message.
pwStringMessage (nint)The message.

SetInShutDown

#Since v5.0
public static void SetInShutDown()
Informs the runtime that the application is shutting down.

ShutDownRhinoCommon_RDK

#Since v6.0
[MonoPInvokeCallback(HostUtils.ShutdownRDKCallback)] public static void ShutDownRhinoCommon_RDK()
Makes sure all static RhinoCommon RDK components are de-initialized so they aren't calling into space when the RDK is unloaded.
Remarks: Subsequent calls to this method will be ignored.

UnhandledThreadException

#Since v6.0
public static void UnhandledThreadException(object sender, ThreadExceptionEventArgs e)
Exception handler for exceptions occurring on the UI thread
sender (object)
e (ThreadExceptionEventArgs)

Events

OnExceptionReport

#Since v5.0
public static event HostUtils.ExceptionReportDelegate OnExceptionReport
Is raised when an exception is reported with one of the ExceptionReport(Exception) method.

OnSendLogMessageToCloud

#Since v6.4
public static event HostUtils.SendLogMessageToCloudDelegate OnSendLogMessageToCloud
Is raised when an exception is reported with one of the method.