Macro for viewport

Hi to everybody!

I’m trying to build a little macro for a button that creates a viewport with the size I write into this macro.
I need to indicate the size as a fraction. This works if the result of the fraction is an integer value (in this case 400) but it doesn’t work if the denominator is a number that produces a non-integer value (for example, if I put 3 in the denominator the macro doesn’t work).
1- is there a way to avoid this?
2- I often need to change the denominator so… is there a way to put the number of the denominator in a window without opening the macro’s button?

This is the work in progress macro: thank you in advanced

! _NewFloatingViewport
_Projection _Perspective

Hi @fifino,

Try using some RhinoScript.

_-NoEcho _-RunScript (
w = CStr(CInt(800 / 3))
h = CStr(CInt(800 / 3))
Call Rhino.Command("_-NewFloatingViewport _Projection _Perspective", 0)
Call Rhino.Command("_-ViewportProperties _Size " & w & " " & h & " _Enter", 0)

– Dale

Thank you very much Dale! You made my day!

Anywhere…I’m not a programmer so…script for me is like writing in Chinese :slight_smile:


as explained in my first post, I often need to change the denominator so it would be very useful to insert this value on the command line. I tried to understand how to to it in the script but I’m not able…can you help me?

Thank you in advanced

This is my WIP:

_-NoEcho -RunScript (
A = Rhino.GetReal(“Insert percentage”, 50, 10)
If Not IsNull(A) Then
w = CStr(CInt(100 * A / 100))
h = CStr(CInt(100 *A / 100))
Call Rhino.Command("
-NewFloatingViewport _Projection Perspective", 0)
Call Rhino.Command("
-ViewportProperties _Size " & w & " " & h & " _Enter", 0)
End If

I can’t code this:
if w or h is < 20 then print on command line: “the frame is too smal: please, increase the percentage”. Do the script again
Can you help me?

thanks a lot

Something like this?

Option Explicit

Call Main()
Sub Main()
	Dim a,w,h,msg
	'initial message
	msg = "Insert percentage"
	'create a loop to repeat process indefinitely
		A = Rhino.GetReal(msg, 50, 10)
		'exit script is A is not entered
		If Not IsNumeric(A) Then Exit Sub
		w = CStr(CInt(100 * A / 100))
		h = CStr(CInt(100 * A / 100))
		'check values and exit the loop if they are acceptable
		If w >= 20 And h >= 20 Then Exit Do
		'if not, change message and go back to the beginning of loop
		msg = "Frame is too small, please increase the percentage"
	'execute command onec data is OK
	Call Rhino.Command("-_NewFloatingViewport _Projection Perspective", 0)
	Call Rhino.Command("-_ViewportProperties _Size " & w & " " & h & " _Enter", 0)
End Sub

Hi Helvetosaur and thanks for your script.
I put this script on the button with " _-NoEcho -RunScript (" on the beginning and !)! on the end but seems not to work

The two rhino commands were missing the _underscore, so it would fail in non-English Rhinos. I fixed that above, does it work now?


this script works perfect!!!
Thank you very much!!!

BTW: yes, 2 command were missing _ but for non english rhino the right comand is: _-NewFloatingViewport and not -_NewFloatingViewport


The order of the dashes shouldn’t actually matter I think… --Mitch

oooppssss…you are right…sorry :slight_smile: