Forgot password?

Create an account!

Forum

« back

RhinoScript – Saving sun position with views

Messages

Please log in to write a message.

  • 39. palosanto (Feb 23, 2016 18.35):

    Hi,
    I'm sorry to hear that you can't access Rhino. I imagine that you already know that there are trial downloads at McNeel...
    That's unfortunate, I'm using your scripts almost daily and I'm really thankful for your efforts.
    I hope to hear from you soon.
    Juan

  • 38. ledisnomad (Feb 23, 2016 18.23):

    Hi, Juan.

    I currently don't have access to Rhino! :( But I am looking to get a copy and would be happy to make these adjustments if I do. Your comment #2 seems the most important: a way to cancel the renderings without having to press Esc endlessly.

    I'll see what I can do.

  • 37. palosanto (Feb 20, 2016 04.05):

    Hi ledisnomad,

    I left a couple of messages back in August. I wonder if you would have time to address the comments.
    Thanks,
    Juan

  • 36. palosanto (Aug 12, 2015 23.22):

    I tested the new delete pairs script. Works fine thanks.
    Couple of comments:
    1.- While we wait for someone to help out with a .NET script for managing the saved pairs, a cosmetic suggestion to make ShowSavedViewVRaySunPair more elegant:
    It should display "No view-sun pairs saved' if there is none saved. Right now you get a 'and' and also a prompt to render but there's nothing to render.
    I would remove the commas and "and" and simply list the views one per row rather than one after another on the same line. It would read much clearer.
    2.- Is there a way to stop the batch render script once it starts running other that keep pressing escape. Many times I run it and I need to abort it because I just noticed something in the model or for whatever reason. So I keep pressing escape and hope to stop it. Eventually it stops but it leaves a trail of unfinished image files of course that I have to go and clean up.
    3.- On the image subject, the command SaveRenderWindowAs writes a file for each VFB channel. Is there a command to save only the rgb channel?

  • 35. palosanto (Aug 12, 2015 22.45):

    Hi ledisnomad.
    You are right about the do-it-all. Calling the scripts from a toolbar works fine and that's what I have now.
    I look forward to see your updated scripts when they are uploaded.
    I'll check often
    Take care - Juan

  • 34. ledisnomad (Aug 12, 2015 22.43):

    Juan,

    Updated! Feel free to continue to give me feedback and/or ideas. If I have time, I'm happy to help.

  • 33. palosanto (Aug 12, 2015 22.39):

    Hi ledisnomad.
    You are right about the do-it-all. Calling the scripts from a toolbar works fine and that's what I have now.
    I look forward to see your updated scripts when they are uploaded.
    I'll check often
    Take care - Juan

  • 32. ledisnomad (Aug 12, 2015 20.05):

    Hi palosanto,

    So glad you're getting your hands dirty with scripting. That's the best way to learn.

    I've updated the scripts and will upload them:
    SaveViewVRaySunPair
    RenderViewVRaySunPair
    ShowSavedViewVRaySunPair
    DeleteViewVRaySunPair (new)
    RestoreViewVRaySunPair (in progress)

    As for a "do-it-all" script, I'm not sold for a couple reasons. First, a simple toolbar would be an easy solution to collect them all in one place. Second, if I did it all together, I'd like to do it as a plugin with a GUI. I've never done that and I can't seem to find any information about using Python to create a plugin. I think I'd have to redo it in a .NET language. Possible, but more than I want to bite off.

    It would be cool to have a window like the Named Views that contained a summary of View-Sun pairs and had buttons to add, delete, update, etc. all the pairs. If anybody is listening out there and knows how to do this and wants to help, please speak up! We'd love your help!!!

  • 31. palosanto (Aug 09, 2015 20.20):

    Hi again,
    I trust you had a nice vacation. So here I am bugging you. Se my last message with my crude attempts to adapt the code.
    I also added a way to restore the sun position when I'm on a certain view. Very useful. However, there's no error check so if there is no sun position for the view it crashes. It needs some if statement so that if there's no sun for that view, display a message "No sun paired" and quit.
    Here is what I have:

    import rhinoscriptsyntax as rs
    import scriptcontext as sc
    import Rhino as rc
    import System.DateTime

    ## GetSun.py ##

    #Get current view
    current_view = rs.CurrentView()
    #Find VRay sun in document
    lights = rs.LightObjects()
    for i in range(0, len(lights), 1):
        if (rs.LightName(lights[i])=="sun"): sun = lights[i]
    #Restore sun direction
    dir = rs.GetDocumentData(current_view, "direction")
    v = dir.split(",")
    rs.LightDirection(sun, v)

    So now I can go to a certain view, restore the sun and render only that view.
    What do you think ?

    Also,ideally it would be nice to have a more generic 'do-it-all' script where one can call from one place any of the functions that we already have so far if we include my doodling:
    - Save view-sun
    - Restore view-sun (then I can always hit render)
    - List pairs
    - Delete one pair
    - Delete all pairs
    - Render all

  • 30. palosanto (Jul 27, 2015 22.21):

    Sound great. Thanks.
    In the meantime I managed to do some progress (despite my poor prog skills ...)
    I can now delete one view-sun pair or all view-sun pairs.
    Here is what I did (probably not too elegant but it works ...

    To delete only one pair, being in the view I want to clear:

    import rhinoscriptsyntax as rs
    import scriptcontext as sc
    import Rhino as rc
    import System.DateTime

    #Get current view
    current_view = rs.CurrentView()

    rs.SetDocumentData(current_view, "direction", "")
    print "View '" + current_view + "' cleared."

    And for all pairs:

    import rhinoscriptsyntax as rs
    import scriptcontext as sc
    import Rhino as rc

    named_views = rs.NamedViews()

    view_sun_pairs = []

    for i in range(0, len(named_views), 1):
        current_view = named_views[i]
        dir = rs.GetDocumentData(current_view, "direction")
       
        if dir:
             rs.SetDocumentData(current_view, "direction", "")

    I was also trying to add to the render script, an 'if' statemnt that would check if there are any view-sun pairs saved at all, and if there arent any, simply quit with an echo saying "No view-sun pairs found" or something like that but I couldn't figure it out ...
    Let me know waht you think.
    Thanks
    Juan

  • 29. ledisnomad (Jul 27, 2015 05.11):

    I'm on vacation this week, but I'd be happy to revisit the script when I get back. Sorry I didn't get to it before. If you don't hear from me early next week, send me another message

  • 28. palosanto (Jul 25, 2015 22.15):

    Hi ledisnomad,
    I hate to bug you again.
    I wonder if I could beg you to fix the script to be able to delete previously saved views with sun.
    Like I said before, I have no way of getting rid of the saved views so for example
    once I have already rendered the views, the metadata remains in the model so if I want to render a different view, it wants to render again everything.
    Can you please at least let me know how to clear the metadata ...
    I would really appreciate it
    Thanks
    Juan

  • 27. palosanto (May 30, 2015 19.36):

    Hi ledisnomad,
    I get the fact that simply re-saving the view will update it.
    The trouble is that sometimes I need to repeat only some of the views, or perhaps I saved a view that wasn't needed, but of course the script wants to render everything again so it would be nice to be able to remove some of the views from the list.
    Other than that it is really helpful so far !.
    See what you can come up with when you have time.
    Cheers - Juan

  • 26. ledisnomad (May 30, 2015 14.15):

    Hi palosanto,

    Glad to hear you've been using the scripts.

    You should be able to modify a view-sun pair using the Save script. If you change the sun and save with the same named view, it should overwrite the previous one.

    I never added a way to delete pairs. That shouldn't be difficult. The data is stored as user data in the Rhino file. The only way I know of to modify it is through a script. I'll take another look at the scripts next week and see what I can do.

  • 25. palosanto (May 30, 2015 09.16):

    Hi there,
    It's been a while and I've been using your scripts which helped me a lot.
    I have a question: Is there a way to modify or delete the list of views with sun that the script has saved ? Where is the associated data stored ?
    Thanks in advance
    Juan

  • 24. palosanto (Apr 23, 2015 21.03):

    Perfect.
    Take care.

  • 23. ledisnomad (Apr 23, 2015 21.00):

    Glad it's working!

    I'll check out the typo in the render script.

    Yes, it was intentional to comment out the lines in the listing script that activate the render now feature. Since one has to change the path, I want the script to run without error. Then users can edit it if they want.

    Happy batch rendering!

  • 22. palosanto (Apr 23, 2015 20.50):

    (Mmm I just wrote a message and seems to have disappeared ....)

    Anyways, the scripts work great now but there were a couple of glitches causing errors.
    1.- The render script had a ' in line 18 instead of a # so in was causing an error.
    2.- The view listing script wasn't asking me in the dialog box whether I wanted to render the views. There were some commented lines causing this. Not sure if that was intentional.
    Anyways, they all work perfect now.
    Once again, thank you for your efforts and patience.
    I'll keep checking regularly in case you further develop the scripts.
    Cheers

  • 21. ledisnomad (Apr 23, 2015 15.46):

    I'm about to upload new versions of the Render and Show scripts.

    I could modify the folder selection. It needs to at least prompt the user to hit enter to choose previous location or browse, otherwise there would be no way to modify the folder after the first time. I've added two options in the script: #1 always open browser, but it will save the previous location and you can just hit enter or #2 first time open browser, after that, have a command prompt with previous location as default or browse option. If you prefer option 2, comment out option 1 and remove comments (triple quotation marks """) for option 2. Option 2 is more error prone because at the prompt, the user could enter text that means nothing and I don't think it is worth doing such rigorous error checking.

    As for the View listing script, if you use forward slash (/) in the path instead of backslash (\), you won't have the problem. I added an example path and note to help clarify.

    This has been a good project (and good timing, since I've had a little extra time and I had just worked on a batch render script). Your comments have been great to help refine these scripts.

  • 20. palosanto (Apr 23, 2015 08.07):

    Hi,
    I've been testing the new scripts and the rendering one still prompts me for the output folder every time for some reason ...
    Another detail for the wish list (eventually) is to remember the file type chosen. But it's esay enough as is, so don't worry. Usually one renders always with the same format anyways so once is set it's ok.

    The View listing script is great but it had trouble resolving the path string of my original script location. The path had a "5.0" (...\Rhinoceros\5.0\...") in its string and the "\5.0\" became a "|.0\" so instead (...\Rhinoceros\5.0\...") it was resolving (...\Rhinoceros|.0\..."). I suspect that \5 is the escape code for the character "|" , is it not?
    Anyways something to keep in mind. I moved the scripts to a simpler path. Spaces are fine though.
    I think that these scripts have great potential !

  • 19. ledisnomad (Apr 22, 2015 21.04):

    OK, uploaded a new version of RenderViewVRaySunPair.py (version 1.2).

    It saves the previous file location and fixes a bug that caused an error when trying to render a named view that didn't have a saved sun.

    I also wrote and uploaded a script to show a message box with the name of the view-sun pairs.

    NOTE: I added and commented out two lines near the end of the message box, "Do you want to render these views now?" and have Yes and No buttons, where clicking the Yes button will run RenderViewVRaySunPair.py. The catch is that the path to the Render script is fixed in the script at C:\RhinoPython\RenderViewVRaySunPair.py". If you want to use this functionality, feel free to delete the # at the beginning of lines 27, 31, and 32 and edit the path on line 32 if necessary. Otherwise, the script as-is will at least display the named views with saved suns for reference.

    At this point, I think this collection of scripts could be packaged into a plugin or something a little more comprehensive. Anybody out there want to help me set that up? I've never bothered packaging anything together as a set.

  • 18. palosanto (Apr 22, 2015 20.07):

    Thanks for your great help !!

  • 17. ledisnomad (Apr 22, 2015 19.58):

    Glad it works! As for your suggested improvements, #1 turns out to be easy, so I'll upload a new version with that change for sure. I'll look into the second option. I'm sure it's possible, but it might be a separate script. I'll look into #2.

    As for the button, this is the way you write it:

    -_RunPythonScript (C:\RhinoPython\RenderViewVRaySunPair.py)

    Note the space between RunPythonScript and the parenthesis and of course you can change the path to the script to wherever you've saved it.

  • 16. palosanto (Apr 22, 2015 18.57):

    Hi,
    I meant to write earlier, sorry. What happened is that I got a bit confused with the different versions because there was a 1.2 and I assumed that this was the latest. Then I saw "(vray sun)" in the name but since it was version 1 I hadn't considered ... duh ! Then I got distracted with work.
    Anyways, finally I got it running and it seem to do the trick. Thank you !
    A couple of improvements for the future:
    1. Save latest output folder as default when prompted.
    2. Have the ability to list the saved views that have been sun associated. So if I have, say, 10 views saved in Rhino but only 4 with sun have been saved with the script, I would know what to expect when running the batch render or decide if I need to save other views to be rendered with associated sun.

    Finally, although I'm familiar with creating buttons and small macros, I can't seem to be able to make one for these python scripts. Can you help?
    Thanks again

  • 15. ledisnomad (Apr 22, 2015 17.28):

    Does it do what you hoped?

  • 14. palosanto (Apr 16, 2015 21.12):

    That sound awesome.

    I'll give it a try this evening after work and report back. Once again, thank you !

  • 13. ledisnomad (Apr 16, 2015 21.04):

    It was a glitch. Must have hit "add message" twice by mistake.

    Anyway, I was able to update the two scripts using the directional light created by the VRay sun command. I've uploaded them as a new project since they are not really new versions of the previous.

    The only property of the sun that I am saving with the view is direction (as set with the "Modify Sun" button in the VRay sun's Properties or by simply rotating the VRay sun). I cannot find any way to access its other properties. Python has methods to modify the following properties of lights: enable/disable, diffuse color, direction, location, name. It can do a few things specific to plane and spot lights that are not relevant here.

    I fixed the folder issue and I gave user input for the save file type, which defaults to PNG. You can easily change the default by editing the script at line 23. I added a comment on line 22 to explain.

  • 12. palosanto (Apr 16, 2015 20.00):

    You sent me the same message ?

  • 11. ledisnomad (Apr 16, 2015 19.59):

    Yes, I did choose the Rhino Document Sun because that is what I usually use when I render. (I'm an architect, so location, date, and time are usually quite important to me.) Let me look into using the VRay sun.

    The visible gadget seems like a user preference, not a limitation, but I can appreciate that. However, with regards to the intensity, do you change it from view to view? If not, then I don't see this as a problem, as you can set the Rhino Document Sun intensity in the VRay GI environment settings. I bring all this up because I'm not immediately finding a way to access the VRay sun object. Like I said, I'll look into it.

    As for the folder name re: spaces and the file format, good points. I did not intend these scripts to be general purpose, so I didn't treat all the possible user inputs I could have. In fact, I rarely treat my scripts as general purpose since I create them for specific uses and then can modify them for the next use if necessary. If I have time, I'll address these points.

  • 10. palosanto (Apr 16, 2015 19.23):

    Hi again,
    Couldn't you treat the vray sun as any other infinite light? Even without having vray installed, you still can call the sunlight command and it will place an infinite light. That's what vray does. The difference is that when you click on the light icon in properties, it takes you back to the sun panel instead of the regular infinite light panel.
    Then renaming this infinite light sun1 (default is sun) to differentiate it from the default rhino sun, perhaps would do the trick if you are able to save/restore the direction.
    The direction values are listed in the object properties details as (xxx,xxx,xxx). Can you access this with Phyton?
    I realize that, not being a programmer, I'm not aware of what is and what is not feasable ... I really appreciate your time.

  • 9. ledisnomad (Apr 16, 2015 19.04):

    Yes, I did choose the Rhino Document Sun because that is what I usually use when I render. (I'm an architect, so location, date, and time are usually quite important to me.) Let me look into using the VRay sun.

    The visible gadget seems like a user preference, not a limitation, but I can appreciate that. However, with regards to the intensity, do you change it from view to view? If not, then I don't see this as a problem, as you can set the Rhino Document Sun intensity in the VRay GI environment settings. I bring all this up because I'm not immediately finding a way to access the VRay sun object. Like I said, I'll look into it.

    As for the folder name re: spaces and the file format, good points. I did not intend these scripts to be general purpose, so I didn't treat all the possible user inputs I could have. In fact, I rarely treat my scripts as general purpose since I create them for specific uses and then can modify them for the next use if necessary. If I have time, I'll address these points.

  • 8. palosanto (Apr 15, 2015 21.20):

    Hi lenisnomad,
    Thanks for the scripts. Here is what I found, and bare with me because you probably are already aware of what I'm saying:
    The scripts work but only when saving with the time and day option of the native sun. As you know the native Rhino sun is limited because I cannot control the intensity and there is no visible gadget symbol in the vewport.

    Vray uses the Rhino command '_sunlight' that creates in fact a directional light but using a sun panel almost identical to the one of the command "-sun" but with the header "Sun angle calculator" and no daylight toggle (ignored in vray anyway) and also let's you enter a location for the arrow symbol in the viewport (default 0,0) which, although it makes no difference being a directional light, is useful to select it or get it out of the way in a busy model.

    That is the light that needs to be used by the script in terms of orientation.

    When you create a light with the _sunlight command, it will appear in the lights panel like any other light. To add to the confusion, the default name is also 'sun', (the same name as the default invisible, useless to me, Rhino sun). This light could be renamed first (by the user) to 'sunlight' or 'vraysun' or something to the effect of distinguish it from the Rhino default 'sun' which is off by default and we don't want anyways).

    The script needs to save the orientation of this user's sun light (created with the sunlight' command) and most importantly, I need to be able to handle the orientation with manual control. Again I have no use for time-date option.

    Unfortunately the 'sunlight' command control panel, although visually updates the sun position when you change time and date, it doesn't do the opposite, i.e., update the time and date when I vary manually the position.

    However, both, the 'sun' command and the 'sunlight' command have the option to save/restore sun parameters to a .rsun xml file.
    If I save first the sun orientation for each view (or let the script do the saving) perhaps you could use the xml to retrieve the values?
    The .rsun xml file seems to save more or less parameters depending whether its saved using the sun or the sunlight commands. See attached xmls generated from both panels. We probably need only the short version. You can open them in a plain text editor:

    dl.dropboxusercontent.com/u/80779383/sun_values_with_su[...]

    dl.dropboxusercontent.com/u/80779383/sun_values_with_su[...]


    On another note, I looked at the script and noticed a few things probably easy to change:
    A minor thing is that the folder name has no provision as is for names with spaces for example "New folder" so the script fails.
    Also the file type is set to jpg, but I can change this since I use mostly png, or perhaps have a file type selection option after choosing the folder for the output images.

    Sorry about the long post but I hope that you can have a better feel for what I need.

    Thanks again

  • 7. ledisnomad (Apr 15, 2015 17.36):

    OK, palosanto, I have two scripts for you. I uploaded them to the PY collection here on RhinoScript.org. You can create a toolbar with lines like these to have buttons:

    -_RunPythonScript (C:\RhinoPython\RenderViewSunPair.py)
    -_RunPythonScript (C:\RhinoPython\SaveViewSunPair.py)

    Note the space after RunPythonScript and the "(".

    Or I've created the toolbar for myself and can share it via email or some other way if you give me a place to drop it.

  • 6. palosanto (Apr 14, 2015 23.07):

    Please take your time. No rush.
    Thanks !

  • 5. ledisnomad (Apr 14, 2015 23.00):

    I'd be happy to help. It isn't trivial, so let me work on it and I'll get back to you, hopefully tomorrow.

  • 4. palosanto (Apr 14, 2015 20.30):

    Thanks for taking the time to write the script. Unfortunately, I have no scripting skills. I don't care about the layer states, it just happened to be in the vray tools script so don't worry about that.
    All I really need is to be able to save / restore the sun position with the named view. I don't really need the sun study either, like you said which of course involves a sort of animation process of multiple frames.
    If you could modify your script to accomplish only that I would be very grateful.
    Cheers

  • 3. ledisnomad (Apr 14, 2015 20.23):

    import rhinoscriptsyntax as rs
    import scriptcontext as sc
    import Rhino as rc
    import System.DateTime

    def layersOff(t):
        for i in range(0,len(t),1):
            print t[i]
            rs.LayerVisible(t[i],False)
        return True

    #Frame Save location
    folder = rs.BrowseForFolder(message="Browse for folder", title="Save Frames")
    if folder is None: quit()

    print "Rendering..."

    prevLayer = "Shades0500"

    for h in range(18, 21, 1):
       
        if (h < 10):
            hour = "0" + str(h)
        else:
            hour = str(h)
       
        for m in range(0, 60, 1):
           
            if (m < 10):
                minute = "0" + str(m)
            else:
                minute = str(m)
           
            time = hour + minute
           
            if (m%15 == 0):
                #Turn on correct shades layer
                layer = "Shades" + time
                rs.LayerVisible(prevLayer,False)
                rs.LayerVisible(layer,True)
                prevLayer = layer
               
                print layer
           
            #Dcoument sun settings
            sun = sc.doc.Lights.Sun
            lat = sun.Latitude
            long = sun.Longitude
            currTime = System.DateTime(2015, 6, 21, int(h), int(m), 0)
            sun.SetPosition(currTime, lat, long)
           
            #File name
            filename = str(folder) + "/" + time + ".jpg"
           
            print "...rendering " + time
           
            #Render and save
            rs.Command("!_Render", echo=False)
            rs.Command("-_SaveRenderWindowAs " + filename, echo=False)

    print "Finished."
  • 2. ledisnomad (Apr 14, 2015 20.22):

    hi palosanto,

    I just wrote a simple Python script to render a daylighting animation. It doesn't do what you want, yet, but I think it would be possible to modify it. Layer States could be tricky, though, since it seems the Layer State manager is not a part of Rhinocommon as such. Changing the Rhino Document Sun, though, is no problem.

    Note that my script is currently very specify to a sun study: it steps through from 5am to 9pm in 1 minute increments, changing a specific set of layers every 15 minutes.

  • 1. palosanto (Apr 02, 2015 18.14):

    Hi,
    Is there a way to have a batch script to render saved views and the sun position(by azimut/altitude, not related to time of day/year)

    I render exteriors and it is critical for me to be able to associate the vray sun orientation when changing saved views if I leave a set of views to render overnight with the a batch script.
    Chaos Group has a set of vray utilities help.chaosgroup.com/vray/misc/tools/ where one of them is supposed to do exactly that, be able to save views with associated data such a layer status AND the direction of a direct light which it's what I'm looking for. Unfortunately it doesn't work with Rhino 5 and Vray 2.0 as it was written for Rhino 4 and Vray 1.05 and when restoring the view, the sun is always reset to 0,90.
    I also found this simple Phyton script as starting point for batch rendering:
    www.grasshopper3d.com/forum/topics/batch-rendering-in-p[...]

    However, the thread must be dead because I got no replies.

    Your help would be very much appreciated.

    Thanks

Recommend

Why are these buttons gray?