def Orthographic_Cplane():
    cpln_current = rs.ViewCPlane()
    Bool_Osnap = rs.Osnap()
    point = cpln_current.Origin
    if Bool_Osnap:
        rs.Osnap(False)
    
    rs.Command("_Circle 0,0,0 ")
    
    #
    rs.EnableRedraw(False)
    #
    Circle = rs.LastCreatedObjects()
    if Bool_Osnap:
        rs.Osnap(True)
        
        
    if Circle is None:
            #
        rs.EnableRedraw(True)
    #
        return
            
    if not rs.IsObject(Circle):
        rs.EnableRedraw(True)
        return
    
        
    rs.Command("_Point 0,0,1 ")
    pt_pos = rs.LastCreatedObjects()
    rs.Command("_Point 0,0,-1 ") 
    pt_neg = rs.LastCreatedObjects()
    
    pt_cam = rs.ViewCamera()
    
    dist_pos = rs.Distance(pt_cam,pt_pos)
    dist_neg = rs.Distance(pt_cam,pt_neg)
    
    print pt_cam
    
    Disk = rs.AddPlanarSrf(Circle)
    rs.UnselectAllObjects()
    rs.SelectObjects(Disk)
    
    if dist_pos>dist_neg:
        rs.Command("OrientCameraToSrf _f 0,0,0 _pause")
    else:
        rs.Command("OrientCameraToSrf 0,0,0 _pause")
        
        
    rs.DeleteObjects((pt_pos,pt_neg,Circle,Disk))
    
    rs.ViewProjection(None,1)
예제 #2
0
def view(camera=False, target=False, lens=False):
    if camera and target and lens:
        if not rh.IsViewMaximized("Perspective"):
            rh.MaximizeRestoreView("Perspective")
        rh.ViewProjection("Perspective", 2)
        rh.ViewCameraLens("Perspective", lens)
        rh.ViewCameraTarget("Perspective", Pt(camera), Pt(target))
        rh.ViewDisplayMode("Perspective", "Shaded")
        vs.Redraw()
        return (camera, target, lens)
    else:
        rh.CurrentView("Perspective")
        camera, target, lens = rh.ViewCamera(), rh.ViewTarget(
        ), rh.ViewCameraLens()
        return (fromPt(camera), fromPt(target), lens)
예제 #3
0
def blkFace(obj):

    cameraPos = rs.ViewCamera()

    cameraPos.Z = 0

    xform = rs.BlockInstanceXform(obj)
    plane = rs.PlaneTransform(rs.WorldXYPlane(), xform)

    viewdir = rs.VectorUnitize(cameraPos - plane.Origin)

    angle = rs.VectorAngle(viewdir, plane.YAxis)

    newXform = rs.XformRotation3(plane.YAxis, viewdir, plane.Origin)

    rs.TransformObject(obj, newXform)
예제 #4
0
def FaceCamera():
    try:
        frames = rs.GetObjects("Select Picture Frames",
                               filter=8,
                               preselect=True)

        # rotate surfaces around z axis towards camera point
        if frames:
            rs.EnableRedraw(False)

            cam = rs.ViewCamera()
            camz = (cam.X, cam.Y, 0)
            angle = 1

            for i in frames:
                angle = 1
                while angle >= 1:

                    # get mid point of surface and move to z 0
                    pointmid = rs.SurfaceAreaCentroid(i)
                    pointmidz = (pointmid[0].X, pointmid[0].Y, 0)
                    # Get center UV of surface
                    domainU = rs.SurfaceDomain(i, 0)
                    domainV = rs.SurfaceDomain(i, 1)
                    u = domainU[1] / 2.0
                    v = domainV[1] / 2.0
                    # Get normal vector of surface and cam vector
                    vec1 = rs.SurfaceNormal(i, (u, v))
                    vec1 = vec1.X, vec1.Y, 0
                    vec2 = rs.VectorCreate(camz, pointmidz)
                    # find angle difference between the two vectors
                    angle = rs.VectorAngle(vec1, vec2)
                    angle = round(angle)
                    # Rotate Object
                    rs.RotateObject(i, pointmidz, angle)
                continue

            rs.EnableRedraw(True)

    except:
        print("Failed to execute")
        rs.EnableRedraw(True)
        return
예제 #5
0
def blkFace(obj):

    cameraPos = rs.ViewCamera()

    cameraPos.Z = 0

    plane = rs.WorldXYPlane()

    if rs.IsBlockInstance(obj):
        plane = blkPlane(obj)
    elif rs.IsSurface(obj):
        plane = srfPlane(obj)

    targetpos = plane.Origin
    targetpos.Z = 0

    viewdir = rs.VectorUnitize(cameraPos - targetpos)

    angle = rs.VectorAngle(viewdir, plane.YAxis)

    newXform = rs.XformRotation3(plane.YAxis, viewdir, plane.Origin)

    rs.TransformObject(obj, newXform)
예제 #6
0
def ExportNamedViews():
    '''
    Extract view coordinates and write to JSON

    Example:
        * Open original .3dm file
        * RunPythonScript `ExportNamedViews()`
        * Create a New .3dm file
        * RunPythonScript `ImportNamedViews()`
    '''
    log = open('./views.json', 'a')
    fname = rs.DocumentPath() + rs.DocumentName()
    data = {}
    data[fname] = {}

    for view in rs.NamedViews():
        rs.RestoreNamedView(view)
        data[fname][view] = (list(rs.ViewCamera()), list(rs.ViewTarget()))

    log.write(json.dumps(data, indent=2) + '\n')
    log.close()

    return data
예제 #7
0
# input is guid of referenced block

import rhinoscriptsyntax as rs
import ghpythonlib.treehelpers as th
import scriptcontext as sc
import Rhino as rc

sc.doc = rc.RhinoDoc.ActiveDoc

cameraPos = rs.ViewCamera()

cameraPos.Z = 0

xform = rs.BlockInstanceXform(x)
plane = rs.PlaneTransform(rs.WorldXYPlane(), xform)

viewdir = rs.VectorUnitize(cameraPos - plane.Origin)

angle = rs.VectorAngle(viewdir, plane.YAxis)

newplane = rs.RotatePlane(plane, angle, plane.ZAxis)

a = xform

b = plane

c = cameraPos

d = viewdir

e = plane.YAxis
예제 #8
0
def distFromCamera(target):
    camPos = rs.ViewCamera(rs.CurrentView())
    dist = rs.Distance(camPos, target)
    print "Distance from camera is " + str(dist)