Changing units causes viewport scaling wish it didn't

Hi @dale
I went over your kindly supplied Vb script and was able to add the choice of my custom units. The only problem is that when I choose my units Rhino scales the viewport and I have to zoom extents or zoom selected to measure the object, then do a zoom extents after the command ends to get the original view back.

Maybe this is how it’s been, but why can’t the view not redraw? in the real world the object doesn’t change just the tape measure is changed.
Try the script and select Palladian module or minutes and notice how the view port scales.
Thanks for the script if I can get around this I can really start to make progress using custom units.
RM

DistanceDialog2.rvb (2.9 KB)

Hi @3dsynergy,

The reason for the view change is becuase you are changing Rhino’s unit system and scale existing geometry based on the new unit system.

' Reset units if Palladian Tuscan Module was chosen
Rhino.UnitSystem intSystemold, True

Rather than try to make Rhino’s Distance command work the way you want, maybe you should just write your own script to calculate it in the manner you need.

For example:

Option Explicit

Sub CubitDistance()
	
	' Local constants
	Const MM = 2 ' millimeter unit system
	Const CB = 417 ' millimeter per cubit
	
	' Local variables
	Dim p0, p1, du, dm, p
	
	' First point
	p0 = Rhino.GetPoint("First point for cubit distance")
	If IsNull(p0) Then Exit Sub
	
	' Second point
	p1 = Rhino.GetPoint("First point for cubit 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) & " cubits")
	
End Sub

– Dale

1 Like

Hi @dale

Yep I knew that. I was asking if there is a snippet of code that could suppress that behavior?

You’re quite right but I also need all the Rhino commands to work in “my unit system” not just distance when I model. But I use these scripts to check models when not in my custom units.

Your coding is so elegant I would never have known how to craft what you just did.
This snippet is enlightening along with the local constants:

’ Convert distance to cubits
If Rhino.UnitSystem <> MM Then
dm = du * Rhino.UnitScale(MM)
Else
dm = du
End If

You are always measuring in mm no matter what my file units are set to? It seems so, since I used your script with the units set to inches and it reported in inches and cubits? Is that what the <> does if unit system is millimeters or anything else report in anything else but measure in MM? I really like the way both distance unit systems are displayed at the command there you can really see what the numbers look like, that is really cool.

Is your cubit is too small? Unless it’s for smaller people? Standards are from 457.2 - 559 mm, My elbow to index finger ratio is 18.1 inches. Just wondering where you got the constant from since all published cubits are 18 inches or above that I know of.
“Const CB = 417 ’ millimeter per cubit”

Thanks for your help and for providing such elegant examples,
RM

Hi @3dsynergy,

The script always computes distance in the current unit system. It then converts the distance to millimeters, if needed, before converting to cubits.

My millimeters-to-cubits conversion scale factor may be incorrect - I just Googled something…

– D