Rhino3DE
develop
design
educate
v3 plugins
v3 vbscript
v2 vbscript
tutorial
color match
convert curve equichordal
history hide
mesh mapper
open with V4
sel pts on crv
whats that
errors
pure code
clean code
     
 

Pure Code

As said, now we do some dirty scripting without any error checking. That means if you don't exactly do what the script expects, the you might get an error. Test this in the _EditScript window:

 

 

 

 

arrPoint1 = Rhino.GetPoint("First point")

arrPoint2 = Rhino.GetPoint("Second point")

dblDistance = Rhino.Distance(arrPoint1, arrPoint2)

Rhino.Print "Distance: " & CStr(dblDistance)

dblNewDistance = Rhino.GetReal("Enter New Distance")

 

SetLocale ("en-us")

dblSkalFaktor = dblNewDistance / dblDistance

Rhino.Command "_Scale2D _Copy=No _Pause _Pause " & CStr(dblSkalFaktor)

 

 

The second part is new, what happens here? Before the script calculates the scaling factor I added SetLocale ("en-us"). This forces the script to use "." as a decimal separator, otherwise VBscript uses the local settings and the script might fail if you have "," as a decimal separator in your computers "regional settings".

With the Rhino.Command you can send a string to the command line like you might know it from macros. The advantage of VBscript is, that you can create that text dynamically like shown above. The scale value has been calculated based on our input in the line before.

Of course you could do the scaling also with RhinoScript methods, but the native Rhino command handles a lot of error checking for us.

But how to use such a RhinoScript if we don't want to run it from the _EditScript window each time? Well there are many ways to implement scripts and each has its pros and contras. For now we simply attach it to the _RunScript command, which you can put into a button, alias or shortcut:

   
 

 

-_Runscript (

arrPoint1 = Rhino.GetPoint("First point")

arrPoint2 = Rhino.GetPoint("Second point")

dblDistance = Rhino.Distance(arrPoint1, arrPoint2)

Rhino.Print "Distance: " & CStr(dblDistance)

dblNewDistance = Rhino.GetReal("Enter New Distance")

 

SetLocale ("en-us")

dblSkalFaktor = dblNewDistance / dblDistance

Rhino.Command "_Scale2D _Copy=No _Pause _Pause " & CStr(dblSkalFaktor)

)

 

© 3DE < ^ >