Distance function enhancement ... possible with sdk?

I would like an option in the distance function to show the resulting measured distance in multiple units … like mm and feet

is something like that possible via the sdk?

Hi @andrew_taylor1,

Use the RhinoMath.UnitScale method to get the scale factor between one unit and another. Then multiply your measured distance by the scale factor.

For example:

import Rhino

distance_inches = 125.0

inches = Rhino.UnitSystem.Inches
meters = Rhino.UnitSystem.Meters
scale = Rhino.RhinoMath.UnitScale(inches, meters)

distance_meters = distance_inches * scale
print(distance_meters)

– Dale

Thanks for the details. Is it possible to “tie” into the actual distance function, and print this out as part of the output for that function?

Or possible to create my own Distance2 function that kicks off the same “selector” function that the original distance function uses (ie where the user clicks 2 points)

Hi @andrew_taylor1,

What "distance’ function are you referring to? Sample code might be helpful.

Thanks,

– Dale

I am a dotnet/python/ruby/etc dev … but have not starting writing code yet … so far just researching and looking at sample code.

The distance function I am talking about is the one in the actual product, so when you type “distance” at the command prompt in the rhino UI … I guess it’s properly called a “command”.

Again … thanks for the help !

Hey @andrew_taylor1

image

You can change the reported unit from the command line. Check the help file for details.

https://docs.mcneel.com/rhino/7/help/en-us/index.htm#commands/distance.htm#(null)

– Dale

Yep … and I do that often.

What I am hoping to do via the SDK is show the result in multiple units at the SAME time

So instead of this …

“Distance = 2.31 feet”

this

“Distance = 2.31 feet, 704mm”

Hi @andrew_taylor1,
I do the same thing and I think it was Dale who kindly provided me this solution to my cubit’s custom unit problem.

You can paste this onto an icon, it’s Vbscript though it says cubits I adopted it for Meters and inches.
I use this all the time as I have to work in meters but was raised on imperial units.

Sorry I didn’t extend the logic you have to be in a meters template for it to work if you’re in an inches or feet template it won’t work.
RM

noecho
-RunScript (
Option Explicit
Call CubitDistance
Sub CubitDistance()
	
	' Local constants
	Const MM = 2 ' millimeter unit system
	Const CB = 25.4 ' millimeter per inch
	
	' Local variables
	Dim p0, p1, du, dm, p
	
	' First point
	p0 = Rhino.GetPoint("First point for inch distance")
	If IsNull(p0) Then Exit Sub
	
	' Second point
	p1 = Rhino.GetPoint("First point for inch distance", p0)
	If IsNull(p1) Then Exit Sub
	
	' Compute distance in current units
	du = Rhino.Distance(p0, p1)
	
	' Print distance in current units
	p = Rhino.UnitDistanceDisplayPrecision
	Call Rhino.Print("Distance = " & FormatNumber(du, p, -1) & " " & Rhino.UnitSystemName(False, False))
	
	' Convert distance to cubits
	If Rhino.UnitSystem <> MM Then
		dm = du * Rhino.UnitScale(MM) 
	Else
		dm = du
	End If
	
	' Print distance in cubits
	Call Rhino.Print("Distance = " & FormatNumber(dm / CB, p, -1) & " inches")
	
End Sub
)

wow … perfect

I am in the same situation, used to imperial, but slowly getting comfortable in metric … and having both is going to help with that immensely