Next named view scrip


#1

Hello everyone,
In some case at my work,I use the named view function very often.The animation effect when I switch between different views are very useful.and looks good.
But the named view function didn’t have a switch view button.when I use rtt(now it change name to 3d excite),I can assign a key to the variation set to control toggle between stored views.it’s a very quick and useful function when I need to present something 3d.So I can just press one key to go the next view.
I had check over rhinos settings panel and related command parameter with no result.
So I think making a script will help a lot.
I had try to use rhino python script but the restorenamedview rs function do the job without animation effect,I want a switch next view(sort name in alphabetical or number) script with animation effect, can anyone help me? Thanks.


(Wim Dekeyser) #2

Not quite the same as a one-click go-to-next-NamedView but this might be useful anyway:
I used to call my NamedViews v1, v2, v3, etc. Just typing the name (in this case 3 keys including space or enter) will set the viewport to the NamedView. So you don’t need to have the NamedView dialog box open and pick views in that one.


#3

wow,very handy feature! I didn’t notice this detail before.

but I intend to present my named views in full screen mode,and I got dozens of views to present.
so even just type 01/02/03… can call the view is not suitable for my case.

thank you wim


(Willem Derks) #4

Hi asdfsjal,

How about this setup, it allows the + and - key entered to go view up / view down:

import rhinoscriptsyntax as rs

def CycleNamedViews():
    named_views = sorted(rs.NamedViews())
    if not named_views:
        return
        
    length = len(named_views)
    N=0
    
    while True:
        rs.RestoreNamedView(named_views[N])
        key = rs.GetString('Enter "+" or "-" for view up/down')
        if key:
            if key == '-':
                N -=1
            if key == '+':
                N +=1
            N = N%length
        else:
            break
CycleNamedViews()

HTH
-Willem


#5

Hi Willem,

Many thanks to your help,your script works very well, but except one thing, it loses animation effect, and the restorenamedview function have no animation parameter,since I’m intend to use rhino as a presentation tool,the animation effect is a must.

And I was thinking if using scrip to output a command line string can do some help,so the named views animation option on will make scenes.

I’m new to script,can you help me again?


(Willem Derks) #6

Hi asdfsjal,

I think this does what you want; I scripted the -NamedView command.
Note that you can change the delay and frames values in the script.
Watch out for linewrapping on the long line setting the command_string.

import rhinoscriptsyntax as rs

def CycleNamedViews():
    named_views = sorted(rs.NamedViews())
    if not named_views:
        return
        
    delay = 10 # set your desired delay
    frames = 100# set your desired frames here
    
    length = len(named_views)
    N=0
    command_string = '_-NamedView Restore Animate=Enabled Delay={0} Frames={1} "{2}" _Enter'
    while True:
        
        rs.Command(command_string.format(delay,frames,named_views[N]))
        #rs.RestoreNamedView(named_views[N])
        
        
        key = rs.GetString('Enter "+" or "-" for view up/down')
        if key:
            if key == '-':
                N -=1
            if key == '+':
                N +=1
            N = N%length
        else:
            break
CycleNamedViews()

HTH
-Willem