Rs.ViewRadius not working when chosing a new radius - Bug

Hello,

when the rs.ViewRadius command is used in Rhino Python without specifying a new radius it will work normally and return the current radius value.

however if I run rs.ViewRadius and specify a new radius it will return this error :

for testing here is a script example (it is taken from the Help file of RhinoPython) :


import rhinoscriptsyntax as rs

rhParallelView = 1

views = rs.ViewNames()

if views:

for view in views:

    if rs.ViewProjection(view)==rhParallelView:

        rs.ViewRadius(view, 10.0)

Yes, @Alain, this looks like a bug in rhinoscriptsyntax. In view.py, the RhinoViewport.Magnify method is indeed missing the second argument, which is a Boolean value to either normal or dolly zoom. I will assume normal zoom is used here.

If you feel comfortable modifying your rhinoscriptsyntax file, you can simply change that line to

viewport.Magnify(d,True)

  1. Close Rhino
  2. Navigate to
    C:\Users\<username>\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript
  3. Open the file views.py in a text editor such as notepad.
  4. Change the line indicated, save the file
  5. Reopen Rhino, it should now work.

–Mitch

Thanks Mitch,

I’ll make the fix.
http://mcneel.myjetbrains.com/youtrack/issue/RH-29774

Alain

Thanks Mitch now it’s not doing the error anymore but it still doesn’t seems to work, here is an example for testing :


import rhinoscriptsyntax as rs

current = rs.CurrentView()
rs.ViewProjection(current,1)

radiusBefore = rs.ViewRadius(view=current, radius=5000)
radiusAfter = rs.ViewRadius(current)

print radiusBefore
print radiusAfter

notice how the radius is not changed and no differance is seen in the viewport

Yeah, I don’t know what’s going on there… Looks like RhinoViewport.Magnify is always failing for some reason. @Alain or @stevebaer can you figure this out? --Mitch

For some reason the viewport.Magnify method fails when Point hasn’t been assigned as the third argument. When you assign it, it works without a problem:

import System

def ViewRadius(view=None, radius=None):
    """Returns or sets the radius of a parallel-projected view. Useful
    when you need an absolute zoom factor for a parallel-projected view
    Parameters:
      view:[opt] title or id of the view. If omitted, current active view is used
      radius:[opt] the view radius
    Returns:
      if radius is not specified, the current view radius for the specified view
      if radius is specified, the previous view radius for the specified view
    """
    view = __viewhelper(view)
    viewport = view.ActiveViewport
    if not viewport.IsParallelProjection: return scriptcontext.errorhandler()
    fr = viewport.GetFrustum()
    frus_right = fr[2]
    frus_top = fr[4]
    old_radius = min(frus_top, frus_right)
    if radius is None: return old_radius
    magnification_factor = radius / old_radius
    d = 1.0 / magnification_factor
    x = viewport.Bounds.Width
    y = viewport.Bounds.Height
    viewport.Magnify(d, True, System.Drawing.Point(int(x/2), int(y/2)))
    #viewport.Magnify(d, True)
    view.Redraw()
    return old_radius

OK, thanks for checking further Djordje, I didn’t have time… --Mitch