HostUtils

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

Properties

ComputerSerialNumber

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

CurrentOSLanguage

#Since v6.8
Get the current operating system language.
[CLSCompliant(false)] public static uint CurrentOSLanguage { get; }
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
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.
public static Guid DeviceId { get; }

DeviceName

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

IsPreRelease

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

OperatingSystemBuildNumber

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

OperatingSystemEdition

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

OperatingSystemInstallationType

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

OperatingSystemProductName

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

OperatingSystemVersion

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

RhinoAssemblyDirectory

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

RunningAsRhinoInside

#Since v7.0
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.
public static bool RunningAsRhinoInside { get; }

RunningInDarkMode

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

RunningInMono

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

RunningInNetCore

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

RunningInNetFramework

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

RunningInRhino

#Since v5.0
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.
public static bool RunningInRhino { get; }

RunningInWindowsContainer

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

RunningOniOS

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

RunningOnLinux

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

RunningOnOSX

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

RunningOnServer

#Since v7.8
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.
public static bool RunningOnServer { get; }

RunningOnWindows

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

SendDebugToCommandLine

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

Methods

AutoInstallPlugInFolder

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

CallFromCoreRhino

#Since v6.0
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
public static int CallFromCoreRhino(
task
)

CheckForRdk

#Since v5.0
Determines if the RDK is loaded.
public static bool CheckForRdk(
throwOnFalse,
if the RDK is not loaded, then throws a RdkNotLoadedException.
usePreviousResult
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
Clear FPU exception and busy flags (Intel assembly fnclex)
public static void ClearFpuExceptionStatus()

CreateCommands

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

CreateCommands

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

CreatePlugIn

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

DebugDumpToString

#Since v5.0
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.
public static string DebugDumpToString(
bezierCurve
curve to evaluate
)
A debug dump text.

DebugDumpToString

#Since v5.0
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.
public static string DebugDumpToString(
geometry
Some geometry.
)
A debug dump text.

DebugString

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

DebugString

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

DescribeGeometry

#Since v8.0
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.
public static string DescribeGeometry(
geometry
)

DisplayOleAlerts

#Since v5.0
Defines if Ole alerts ("Server busy") alerts should be visualized.

This function makes no sense on Mono.

public static void DisplayOleAlerts(
display
Whether alerts should be visible.
)

ExceptionReport

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

ExceptionReport

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

ExecuteNamedCallback

#Since v7.0
Execute a named callback
public static bool ExecuteNamedCallback()

FileNameEndsWithRhinoBackupExtension

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

FileNameEndsWithRhinoExtension

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

GetAbsolutePath

#Since v6.0
Call this method to convert a relative path to an absolute path relative to the specified path.
public static bool GetAbsolutePath(
relativePath,
Relative path to convert to an absolute path
bRelativePathisFileName,
If true then lpsFrom is treated as a file name otherwise it is treated as a directory name
relativeTo,
File or folder the path is relative to
bRelativeToIsFileName,
If true then lpsFrom is treated as a file name otherwise it is treated as a directory name
out string
pathOut
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
Recurses through the auto install plug-in folders and returns the directories containing "active" versions of plug-ins.
public static IEnumerable<DirectoryInfo> GetActivePlugInVersionFolders()
Remarks: If the same package is installed in both the user and machine locations, the newest directory wins.

GetActivePlugInVersionFolders

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

GetAssemblySearchPaths

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

GetCurrentProcessInfo

#Since v6.15
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.
public static void GetCurrentProcessInfo(
out string
processName,
out Version
processVersion
)

GetCustomComputeEndpoints

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

GetPlatformService<T>

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

GetPrinterDPI

#Since v8.2
Get the output resolution for a given printer.
public static double GetPrinterDPI(
printerName,
horizontal
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
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
public static bool GetPrinterFormMargins(
printerName,
formName,
portrait,
out double
leftMillimeters,
out double
topMillimeters,
out double
rightMillimeters,
out double
bottomMillimeters
)
true on success

GetPrinterFormNames

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

GetPrinterFormSize

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

GetPrinterNames

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

GetRhinoDotNetAssembly

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

GetSystemProcessorCount

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

GetSystemReferenceAssemblies

#Since v8.0
Gets the system reference assemblies to use when compiling code dynamically with Roslyn. Includes RhinoCommon, Rhino.UI, and Eto.
public static IEnumerable<string> GetSystemReferenceAssemblies()
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
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.
public static void InitializeRhinoCommon()
Remarks: Subsequent calls to this method will be ignored.

InitializeRhinoCommon_RDK

#Since v6.0
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.
[MonoPInvokeCallback(HostUtils.InitializeRDKCallback)] public static void InitializeRhinoCommon_RDK()
Remarks: Subsequent calls to this method will be ignored.

InitializeZooClient

#Since v5.6
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.
public static void InitializeZooClient()

InPlaceConstCast

#Since v5.0
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!

public static void InPlaceConstCast(
geometry,
Some geometry.
makeNonConst
A boolean value.
)

IsManagedDll

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

IsRhinoBackupFileExtension

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

IsRhinoFileExtension

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

LoadAssemblyFrom

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

LoadAssemblyFromName

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

LoadAssemblyFromStream

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

LogDebugEvent

#Since v8.5
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.
public static void LogDebugEvent(
message
The event message.
)

RecordInitInstanceTime

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

RegisterComputeEndpoint

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

RegisterDynamicCommand

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

RegisterNamedCallback

#Since v6.15
Register a named callback
public static void RegisterNamedCallback()

RegisterStaticIDisposable

#Since v9.0
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.
public static void RegisterStaticIDisposable(
disposable
)

RemoveNamedCallback

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

RhinoCommonExceptionHandler

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

SendLogMessageToCloudCallbackProc

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

SetInShutDown

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

ShutDownRhinoCommon_RDK

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

UnhandledThreadException

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

Events

OnExceptionReport

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

OnSendLogMessageToCloud

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