コード例 #1
0
ファイル: swapRes.py プロジェクト: syl1130/pythonscripts
def swapRes():
    """
    This script script swaps x and y resolution.
    Typically useful for standard formats (together with changeRes.py) to switch between portrait and landscape
    script by Gijs de Zwart
    www.studiogijs.nl
    """
    vray = rs.GetPlugInObject("V-Ray for Rhino")

    param = vray.Scene().Plugin("/SettingsOutput").Param("img_pixelAspect")
    param.Value = 5
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_aspect_ratio")
    param.Value = 5
    param = vray.Scene().Plugin("/SettingsOutput").Param("lock_resolution")
    param.Value = False

    param1 = vray.Scene().Plugin("/SettingsOutput").Param("img_width")
    width = param1.Value()

    param2 = vray.Scene().Plugin("/SettingsOutput").Param("img_height")
    height = param2.Value()
    param1.Value = height
    param2.Value = width
    vray.RefreshUI()
    print "x resolution is now %d and y %d" % (height, width)
コード例 #2
0
def changeRes():
    """
    With this script you can change the resolution through the command line.
    Typically use this in a toolbar, where you can pass the x and y relolution directly
    script by Gijs de Zwart
    www.studiogijs.nl
    """
    width = rs.GetInteger(number = 1024)
    height = rs.GetInteger(number=768)
    vray = rs.GetPlugInObject("V-Ray for Rhino")
    
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_pixelAspect")
    param.Value=5
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_aspect_ratio")
    param.Value=5
    
    
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_width")
    
    param.Value = width
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_height")
    param.Value = height
    
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_aspect_ratio_height")
    param.Value = System.Single(1)
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_aspect_ratio_width")
    param.Value = System.Single(width/height)
    param = vray.Scene().Plugin("/SettingsOutput").Param("lock_resolution")
    param.Value = True
    vray.RefreshUI()
コード例 #3
0
ファイル: layers.py プロジェクト: tmwarchitecture/PCPA_TOOLS
 def loadMatFromPath(path):
     if os.path.isfile(path):
         rdk = rs.GetPlugInObject("Renderer Development Kit")
         result = rdk.ContentLoadFromFile(path)
         return result
     else:
         print "Cannot find the material file"
         return None
コード例 #4
0
 def getMaterialNames():
     rdk = rs.GetPlugInObject("Renderer Development Kit")
     rdkALL = rdk.FactoryList()
     arrMatIDList = rdk.ContentList("material") 
     arrMatNames = []
     for i in range(len(arrMatIDList)):
         arrMatNames.append(rdk.ContentInstanceName(arrMatIDList[i]))
     return arrMatNames
コード例 #5
0
def ChangeLayerState(LayerState):
    """
    Receives a LayerState and changes
    the model to that specific LayerState
    """
    plugin = rs.GetPlugInObject("Rhino Bonus Tools")
    if plugin is not None:
        plugin.RestoreLayerState(LayerState, 0)
        return 1
    else:
        return 0
コード例 #6
0
def guessHorizontalShift():
    """
    This script will correct the horizontal distortion and set it in the V-Ray Camera.
    It levels the camera for this correction to work well and resets
    lens shift (vertical shift) to 0
    Works with V-Ray 5.1
        
    version 0.4
        
    www.studiogijs.nl
    """
    viewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport
    if viewport.IsParallelProjection:
        print "Stupid, you should select a perspective view"
        return
    view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport
    #set camera location to target height
    pt = view.CameraLocation
    pt[2] = view.CameraTarget.Z
    dir = rs.VectorSubtract(view.CameraTarget, pt)
    view.SetCameraLocation(pt, False)
    view.SetCameraDirection(dir, False)

    #calculate camera direction angle relative to WorldXY plane
    cam = view.CameraZ
    vec = Rhino.Geometry.Vector3d(1, 0, 0)
    plane = Rhino.Geometry.Plane.WorldXY
    angle = Rhino.Geometry.Vector3d.VectorAngle(cam, vec, plane)

    #calculate the correction factor
    for i in range(3):
        if angle > math.pi / 2:
            angle -= math.pi / 2
        else:
            break

    if 0 <= angle < math.pi / 4:
        factor = math.tan(angle)

    if math.pi / 4 <= angle < math.pi / 2:
        factor = -math.tan(math.pi / 2 - angle)

    rv = rs.GetPlugInObject("V-Ray for Rhino").Scene().Plugin(
        "/CameraPhysical")
    rv.Param("horizontal_shift").Value = factor
    print "Horizontal shift factor set to %r." % factor
    rv.Param("lens_shift").Value = 0
    rs.Redraw()
コード例 #7
0
ファイル: changeRes.py プロジェクト: syl1130/pythonscripts
def changeRes():
    """
    This script scales the resolution by user specified factor.
    Typically use this in a toolbar, where you can pass the scale factor directly
    script by Gijs de Zwart
    www.studiogijs.nl
    """
    i = rs.GetReal(number=2, minimum=0.1)
    vray = rs.GetPlugInObject("V-Ray for Rhino")
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_width")
    param.Value = int(param.Value() * i)
    width = param.Value()
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_height")
    param.Value = int(param.Value() * i)
    height = param.Value()
    param = vray.Scene().Plugin("/SettingsOutput").Param("img_aspect_ratio")
    param.Value = 5
    print "image resolution set to %d by %d" % (width, height)
    def __init__(self):
        self.vray = rs.GetPlugInObject("V-Ray for Rhino")

        # Get the maximum priority.
        try:
            self.maximumPriority = int(
                CallDeadlineCommand(["-getmaximumpriority"]))
        except:
            self.maximumPriority = 100

        # Get the pools.
        self.pools = CallDeadlineCommand(["-pools"]).splitlines()

        self.secondaryPools = [""]
        for pool in self.pools:
            self.secondaryPools.append(pool)

        # Get the groups.
        self.groups = CallDeadlineCommand(["-groups"]).splitlines()

        # Get the current user Deadline home directory, which we'll use to store temp files.
        self.deadlineHome = CallDeadlineCommand(
            ["-GetCurrentUserHomeDirectory"]).replace("\n",
                                                      "").replace("\r", "")
        self.deadlineTemp = self.deadlineHome + "/temp"
        self.deadlineStickySettings = os.path.join(
            self.deadlineHome, "settings/rhino_vray_submission.ini")

        self.tabIndex = 0
        # Initialize UI Controls
        self.InitJobDescriptionUI()
        self.InitJobOptionsUI()
        self.InitVRaySpawnerUI()
        self.InitButtonPanelUI()
        self.InitFormUI()

        self.ReadStickySettings()

        # Show the Form
        self.TopMost = True
        self.Show()
        self.Select()

        self.renderStarted = False
コード例 #9
0
def GetLayerStates():
    """
    The function returns the LayerStates 
    that can be found in the model
    """
    plugin = rs.GetPlugInObject("Rhino Bonus Tools")
    if plugin is not None:
        MyArray = plugin.LayerStateNames
        MyArrayB = []
        MyArray = str(MyArray[1])
        Trigger = True
        while (Trigger):
            poz = MyArray.rfind("'")
            MyArray = MyArray[:poz]
            poz = MyArray.rfind("'")
            dif = MyArray[poz:]
            dif = dif[1:]
            MyArrayB.append(dif)
            MyArray = MyArray[:poz]
            if len(MyArray) < 14:
                Trigger = False
        del MyArrayB[-1]  #clean up the list
        return MyArrayB
コード例 #10
0
def viewCapture(fileName, directory, viewNames, image_width, image_height,
                keepAspectRatio, saveAlpha):
    fullPathList = []
    if saveAlpha == None:
        saveAlpha = False

    for viewName in viewNames:

        if viewName in rs.ViewNames():
            rs.CurrentView(viewName, True)
        else:
            # change to RhinoDoc to get access to NamedViews
            sc.doc = rc.RhinoDoc.ActiveDoc
            namedViews = rs.NamedViews()
            if viewName in namedViews:
                viewName = rs.RestoreNamedView(viewName)
            else:
                viewName = None
            # change back to Grasshopper
            sc.doc = ghdoc
            viewName = rs.CurrentView(viewName, True)

        rs.CurrentView(viewName)
        sc.doc.Views.Find(viewName, False)
        viewtoCapture = sc.doc.Views.ActiveView

        try:
            dispMode = rc.Display.DisplayModeDescription.FindByName(
                dispModeStr)
            sc.doc.Views.ActiveView.ActiveViewport.DisplayMode = dispMode
        except:
            pass

        if image_height == None:
            image_h = viewtoCapture.ActiveViewport.Size.Height
        else:
            image_h = image_height

        if image_width == None:
            image_w = viewtoCapture.ActiveViewport.Size.Width
        else:
            image_w = image_width

        # aspectRatio
        if keepAspectRatio:
            if image_height == None and image_width != None:
                image_h = image_h * (image_w /
                                     viewtoCapture.ActiveViewport.Size.Width)
            elif image_height != None and image_width == None:
                image_w = image_w * (image_h /
                                     viewtoCapture.ActiveViewport.Size.Height)

        fullPath = os.path.join(directory, fileName + '_' + viewName + '.png')
        fullPathList.append(fullPath)

        # Set the image size
        rc.RhinoDoc.ActiveDoc.RenderSettings.UseViewportSize = False
        viewSize = System.Drawing.Size(int(image_w), int(image_h))
        rc.RhinoDoc.ActiveDoc.RenderSettings.ImageSize = viewSize

        try:
            VRayForRhinoNETInterface.VRayInterface.SetRenderOutputSize(
                int(image_w), int(image_h))
        except:
            pass

        print "Image dimensions set to (" + str(int(image_w)) + "x" + str(
            int(image_h)) + ")"

        # Render the image and save it.
        try:
            # V-Ray is the renderer.
            VRayForRhinoNETInterface.VRayInterface.HasRenderFinished()

            rs.Command("!_Render", echo=False)
            print "Rendering " + viewName + "..."

            while not VRayForRhinoNETInterface.VRayInterface.HasRenderFinished(
            ):
                if sc.escape_test(False):
                    print("Rendering cancelled")
                    rs.Command("_CloseRenderWindow", echo=False)
                    rs.GetPlugInObject("V-Ray for Rhino").SetBatchRenderOn(
                        True)
                    vray.CancelRender()
                    rs.GetPlugInObject("V-Ray for Rhino").SetBatchRenderOn(
                        False)
                    esc = True
                    break
                rs.Sleep(10)
            rs.Command("_-SaveRenderWindowAs \"" + directory + "\\" +
                       fileName + '_' + viewName + ".png\"")
            rs.Command(
                "_-CloseRenderWindow"
            )  #close the rendered window when in saving mode to avoid stacking a series of renderWindows when running on Rhino renderer.
            if saveAlpha == False:
                try:
                    alphaPath = os.path.join(
                        directory, fileName + '_' + viewName + '.Alpha.png')
                    os.remove(alphaPath)
                except:
                    pass
        except:
            if renderTime_ != None:
                # V-Ray is probably the renderer.
                start = time.clock()

                rs.Command("!_Render", echo=False)
                print "Rendering " + viewName + "..."

                while float(time.clock() - start) < renderTime_:
                    rs.Sleep(10)

                rs.Command("_-SaveRenderWindowAs \"" + directory + "\\" +
                           fileName + '_' + viewName + ".jpeg\"")
                rs.Command(
                    "_-CloseRenderWindow"
                )  #close the rendered window when in saving mode to avoid stacking a series of renderWindows when running on Rhino renderer.
                if saveAlpha == False:
                    try:
                        alphaPath = os.path.join(
                            directory,
                            fileName + '_' + viewName + '.Alpha.jpeg')
                        os.remove(alphaPath)
                    except:
                        pass
            else:
                # Hopefully Rhino is the renderer.
                print "Rendering " + viewName + "..."
                rs.Command("!_render")
                rs.Command("_-SaveRenderWindowAs \"" + directory + "\\" +
                           fileName + '_' + viewName + ".png\"")
                rs.Command(
                    "_-CloseRenderWindow"
                )  #close the rendered window when in saving mode to avoid stacking a series of renderWindows when running on Rhino renderer.

    return fullPathList
コード例 #11
0
def printHorizontalShift():
    rv = rs.GetPlugInObject("V-Ray for Rhino").Scene().Plugin(
        "/CameraPhysical")
    print rv.Param("horizontal_shift").Value()
コード例 #12
0
 def loadMatFromPath(path):
     if os.path.isfile(path):
         rdk = rs.GetPlugInObject("Renderer Development Kit")
         rc = rdk.ContentLoadFromFile(path)
         return rc
     else: return None
コード例 #13
0
import rhinoscriptsyntax as rs
import Rhino
import clr

path = "\"C:\Users\sleaman\Desktop\Rainier Batch Renders\\"
print(path)
plugin = rs.GetPlugInObject("Rhino Bonus Tools")
if plugin is not None:
    states = plugin.LayerStateNames()

for state in states:
    plugin.RestoreLayerState(state)
    rs.Command("!_Render", echo=False)
    rs.Command("-_SaveRenderWindowAs " + path + state + "\"")

print("Finished Renders")
コード例 #14
0
    of the layer state to the naming of the
    view
    """
    FileName = '"' + folder + '\\' + View + '_' + State + '"'
    FileName = str(FileName)
    rs.Command("!_-Render")
    rs.Command("_-SaveRenderWindowAs " + FileName)
    rs.Command("_-CloseRenderWindow")
    return 1


def ChangeView(View):
    rs.Command("_-NamedView _Restore " + View + " _Enter", 0)


if __name__ == "__main__":
    """
    Main Function
    """
    VRay = rs.GetPlugInObject("V-Ray for Rhino")
    VRay.SetBatchRenderOn(True)  #Set Batch Render on True
    arrStates = GetLayerStates()  #initialise layer states
    arrViewNames = GetViewNames()
    folder = ChooseFolderPath()
    for State in arrStates:
        ChangeLayerState(State)
        print(State)
        for View in arrViewNames:
            ChangeView(View)
            Render(folder, View, State)