Esempio n. 1
0
    def RunScript(self, Listener_Location, Direction, Height):

        __author__ = "theomarchal"
        self.Params.Input[
            0].Description = "Location of the listener foots (as a point - Default is set to 0,0,0)"
        self.Params.Input[
            1].Description = "Direction of the listener (in degrees from 0 to 360)"
        self.Params.Input[
            2].Description = "How tall is the listener (default = 1.80)"
        self.Params.Output[
            0].Description = "Listener Geometry, size and direction"
        self.Params.Output[
            1].Description = "Listener Object (plug it into EsquisSons)"
        self.Name = "Listener Point"
        self.NickName = "Listener"
        self.Message = "EsquisSons V3"
        self.Category = "EsquisSons"
        self.SubCategory = "1/ Scene"

        import rhinoscriptsyntax as rs

        LL = Listener_Location
        LD = Direction
        LH = Height

        if LL is None:
            LL = rs.AddPoint(0, 0, 0)
        if LD is None:
            LD = 0
        if LH is None:
            LH = 1.8

        LV = rs.VectorRotate([0, (LH), 0], LD, [0, 0, 1])
        matrix = rs.XformTranslation((0, 0, LH))
        LHp = rs.PointTransform(LL, matrix)
        LV2 = rs.VectorScale((rs.VectorRotate(LV, 90, [0, 0, 1])), 0.5)
        LV3 = rs.VectorScale((rs.VectorRotate(LV, -90, [0, 0, 1])), 0.5)
        T1 = rs.PointTransform(LL, (rs.XformTranslation(LV)))
        Tl = rs.PointTransform(LL, (rs.XformTranslation(LV2)))
        Tr = rs.PointTransform(LL, (rs.XformTranslation(LV3)))
        ps = [T1, Tl, Tr]
        Geo = [
            rs.AddSphere(LHp, (LH / 10)),
            rs.AddLine(LL, LHp),
            rs.AddSrfPt(ps)
        ]
        Tl = rs.PointTransform(Tl, matrix)
        Tr = rs.PointTransform(Tr, matrix)
        LP = [LHp, Tl, Tr, LH]
        Listener = [LP]
        return (Geo, Listener)
Esempio n. 2
0
def drawBox( side, location, angle_degrees1, angle_degrees2):
    """画一个2D方块
    参数:
      side(double): 方块的长度, double 
      locaiton(tuple(double, double,double)): 方块中心的位置
      angle_degrees1(double): xy平面旋转角度degree1
      angle_degrees2(double): 到达位置后继续朝z轴方向旋转角度degree2
    Returns:
      guid
    """
    corners = []
    corners.append((-side/2,-side/2,0))
    corners.append(( side/2,-side/2,0))
    corners.append((side/2,side/2,0))
    corners.append((-side/2,side/2,0)) 
    corners.append((-side/2,-side/2,side))
    corners.append((side/2,-side/2,side))
    corners.append((side/2,side/2,side))
    corners.append((-side/2,side/2,side))
    obj = rs.AddBox(corners)

    xform = rs.XformRotation2(angle_degrees1, (0,0,1), (0,0,0))
    obj = rs.TransformObject( obj, xform, False )
    vectorR1 = rs.VectorRotate( (1,0,0), angle_degrees1, (0,0,0))
    vectorR2 = rs.VectorCrossProduct(vectorR1, (0,0,1))
    xform = rs.XformRotation2(angle_degrees1, vectorR2, (0,0,0))
    obj = rs.TransformObject( obj, xform, False )
    xform = rs.XformTranslation( location)
    obj = rs.TransformObject( obj, xform, False )

    return obj 
Esempio n. 3
0
def drawRect( side, location, angle_degrees ):
    """画一个2D方块
    参数:
      side(double): 方块的长度, double 
      locaiton(tuple(double, double,double)): 方块中心的位置
      angle_degrees(double): 旋转角度degree
    Returns:
      guid
    """

    p0 = (-side/2,-side/2,0)
    p1 = (side/2,-side/2,0)
    p2 = (side/2,side/2,0)
    p3 = (-side/2,side/2,0)

    obj = rs.AddPolyline([p0,p1,p2,p3,p0])

   
    xform = rs.XformRotation2(angle_degrees, (0,0,1), (0,0,0))
    obj = rs.TransformObject( obj, xform, False )

    xform = rs.XformTranslation( location)
    obj = rs.TransformObject( obj, xform, False )

    return obj
def InsulationPanel(left_edge, right_edge):

    points = []
    #insulation_left = ver_line_split_even[i]
    point_1 = rs.CurveStartPoint(left_edge)
    point_2 = rs.CurveEndPoint(left_edge)
    #insulation_right = ver_line_split_even[i + next_even_Cource]
    point_3 = rs.CurveEndPoint(right_edge)
    point_4 = rs.CurveStartPoint(right_edge)

    trans = rs.XformTranslation((0, 0, ipThick))
    point_5 = rs.PointTransform(point_1, trans)
    point_6 = rs.PointTransform(point_2, trans)
    point_7 = rs.PointTransform(point_3, trans)
    point_8 = rs.PointTransform(point_4, trans)

    points.append(point_1)
    points.append(point_2)
    points.append(point_3)
    points.append(point_4)
    points.append(point_5)
    points.append(point_6)
    points.append(point_7)
    points.append(point_8)

    insulation = rs.AddBox(points)

    return insulation
def drawEvaluateValue(list_evaluate):
    frame = 5000
    original_point = 5000
    step_x_axis = 100

    plane = rs.WorldXYPlane()
    xform = rs.XformTranslation([0, 5000, 0])
    plane1 = rs.PlaneTransform(plane, xform)
    rs.AddRectangle(plane1, frame, frame)

    evaluate_sum = []
    for i in range(len(list_evaluate)):
        evaluate_sum.append(sum(list_evaluate[i]))

    max_value = max(evaluate_sum)
    min_value = min(evaluate_sum)

    # if 1000 > max_value > 100:
    #
    # if 10000 > max_value >= 1000:

    point_list = []
    for i in range(len(evaluate_sum)):
        value = evaluate_sum[i]
        # print("evaluate_sum", evaluate_sum[i])
        new_value = remap(value, max_value, 0, 5000, 0)
        # print("new_value", new_value)
        pt = rs.AddPoint(i * step_x_axis, original_point + new_value, 0)
        point_list.append(pt)

    rs.AddPolyline(point_list)
def WindowFrame():

    surf_int_edge_all = rs.DuplicateSurfaceBorder(surf[1], type=2)
    print len(surf_int_edge_all)
    window_frame_all = []

    for item in range(0, len(surf_int_edge_all), 1):
        surf_int_edge = surf_int_edge_all[item]

        surf_int_edge = rs.ExplodeCurves(surf_int_edge, True)

        trans1 = rs.XformTranslation((0, 0, 2 * ipThick))
        trans2 = rs.XformTranslation((0, 0, -2 * ipThick))

        point_1 = rs.CurveStartPoint(surf_int_edge[0])
        point_2 = rs.CurveStartPoint(surf_int_edge[1])
        point_3 = rs.CurveStartPoint(surf_int_edge[2])
        point_4 = rs.CurveStartPoint(surf_int_edge[3])

        point_5 = rs.PointTransform(point_1, trans1)
        point_6 = rs.PointTransform(point_2, trans1)
        point_7 = rs.PointTransform(point_3, trans1)
        point_8 = rs.PointTransform(point_4, trans1)

        point_1 = rs.PointTransform(point_1, trans2)
        point_2 = rs.PointTransform(point_2, trans2)
        point_3 = rs.PointTransform(point_3, trans2)
        point_4 = rs.PointTransform(point_4, trans2)

        frame_points = []
        frame_points.append(point_1)
        frame_points.append(point_2)
        frame_points.append(point_3)
        frame_points.append(point_4)
        frame_points.append(point_5)
        frame_points.append(point_6)
        frame_points.append(point_7)
        frame_points.append(point_8)

        window_frame = rs.AddBox(frame_points)
        window_frame_all.append(window_frame)

    return window_frame_all
Esempio n. 7
0
def Transform(dir,ninety,pt):
    
    v1 = [dir[0],dir[1],dir[2]]
    v2 = [ninety[0],ninety[1],ninety[2]]
    v3 = [pt[0],pt[1],pt[2]]
    
    xfrm1 = rs.XformRotation4([-1,0,0],[0,-1,0],[0,0,1], v1, v2, [0,0,1])
    xfrm2 = rs.XformTranslation(v3)
    xfrm = rs.XformMultiply(xfrm2,xfrm1)
    
    return xfrm
Esempio n. 8
0
def F(l):
    global state
    pntA = getPos(state)
    vec = getX(state)
    vec = rs.VectorUnitize(vec)
    vec = rs.VectorScale(vec, l)

    transMat = rs.XformTranslation(vec)
    state = state * transMat
    pntB = getPos(state)
    rs.AddLine(pntA, pntB)
def AddEndsToOffset(offset0, offset1, conn, dist):
    OC1SP = rs.CurveStartPoint(offset0)
    OC2SP = rs.CurveStartPoint(offset1)
    OC1EP = rs.CurveEndPoint(offset0)
    OC2EP = rs.CurveEndPoint(offset1)
    line0 = Rhino.Geometry.Line(OC1SP, OC2SP)
    line1 = Rhino.Geometry.Line(OC1EP, OC2EP)

    result = [offset0, offset1]
    if conn == 0:
        result.append(sc.doc.Objects.AddLine(line0))
        result.append(sc.doc.Objects.AddLine(line1))
    else:
        #add arc from crv end pts and tan direction - save arcs for next section
        dom = rs.CurveDomain(offset0)
        t_vec = rs.CurveTangent(offset0, dom[0])
        t_vec.Reverse()
        arc0 = Rhino.Geometry.Arc(OC1SP, t_vec, OC2SP)
        t_vec = rs.CurveTangent(offset0, dom[1])
        arc1 = Rhino.Geometry.Arc(OC1EP, t_vec, OC2EP)

        if conn == 1:
            result.append(sc.doc.Objects.AddArc(arc0))
            result.append(sc.doc.Objects.AddArc(arc1))
        else:
            #translate lines to arc midpoints, then extend offset curves to ends
            xform = rs.XformTranslation(arc0.MidPoint -
                                        ((line0.From + line0.To) / 2))
            line0.Transform(xform)
            xform = rs.XformTranslation(arc1.MidPoint -
                                        ((line1.From + line1.To) / 2))
            line1.Transform(xform)
            result.append(sc.doc.Objects.AddLine(line0))
            result.append(sc.doc.Objects.AddLine(line1))
            rs.ExtendCurvePoint(offset0, 0, line0.From)
            rs.ExtendCurvePoint(offset1, 0, line0.To)
            rs.ExtendCurvePoint(offset0, 1, line1.From)
            rs.ExtendCurvePoint(offset1, 1, line1.To)

    if len(result) > 2: rs.JoinCurves(result, True)
Esempio n. 10
0
def vrep_pose_from_plane(plane):
    """Creates a vrep-compatible transformation matrix from a Rhino/Grasshopper
    plane.

    This function might need rework as the source of the 90-deg Y rotation
    need is not entirely clear to me (related to the RFL model mismatch).
    """
    translation_matrix = rs.XformTranslation(((plane[0][0]), (plane[0][1]), plane[0][2]))
    plane_start = rs.PlaneFromFrame(rs.AddPoint(0, 0, 0), rs.AddPoint(1, 0, 0), rs.AddPoint(0, 1, 0))
    plane_end = rs.PlaneFromFrame(rs.AddPoint(0, 0, 0), rs.AddPoint(plane[1][0], (plane[1][1]), plane[1][2]), rs.AddPoint(plane[2][0], plane[2][1], plane[2][2]))
    rotation_matrix = rs.XformRotation1(plane_start, plane_end)
    matrix = rs.XformMultiply(translation_matrix, rotation_matrix)
    return [matrix.M00, matrix.M01, matrix.M02, matrix.M03,
            matrix.M10, matrix.M11, matrix.M12, matrix.M13,
            matrix.M20, matrix.M21, matrix.M22, matrix.M23]
Esempio n. 11
0
def MoveX(startPoint, endPoint, pIn):
    matrix = rs.XformTranslation(rs.VectorSubtract(endPoint, startPoint))
    return rs.PointTransform(pIn, matrix)
Esempio n. 12
0
import time
import rhinoscriptsyntax as rs
import scriptcontext as sc
import compas_rhino

guids = compas_rhino.get_objects()
compas_rhino.delete_objects(guids, True)

result = rs.AddBox([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 1],
                    [1, 0, 1], [1, 1, 1], [0, 1, 1]])

obj = sc.doc.Objects.Find(result)
xform = rs.XformTranslation([0.5, 0, 0])
rs.Redraw()

for i in range(10):
    time.sleep(0.5)
    rs.TransformObject(obj, xform)
    rs.Redraw()
Esempio n. 13
0
#coding=utf-8
import rhinoscriptsyntax as rs

firstpoint = rs.GetPoint("Selet one point")  #在rhinoceros中失区点
rangel = 4  #定义x方向上复制点的数量
multiplev = 12  #定义点间距的倍数
mpoints = []  #定义第一排x方向列表

#循环x方向上复制点数量的参数,形成第一排
for i in range(rangel):
    matrix1 = rs.XformTranslation((i * multiplev, 0, 0))  #建立x方向上的矩阵
    mpoint1 = rs.PointTransform(firstpoint, matrix1)  #根据变换矩阵移动点
    mpoints.append(mpoint1)  #将移动的点依次放置于事项定义的空列表
    rs.AddPoint(mpoint1)  #在rhino空间中增加每次移动的点

rangeh = 4  #定义Y方向上复制点的次数
dpoints = {}  #定义空的字典,放置所有移动的点,每一横排的点放置于一个单独的列表中,作为值
mpointh = []  #放置所有点的空列表
deletep = []  #放置每一次内部循环即横排点的空列表,用于字典

#循环Y方向上的复制点的次数
for i in range(rangeh):
    matrixh = rs.XformTranslation((0, i * multiplev, 0))  #建立Y方向上的变换矩阵
    for m in range(len(mpoints)):
        pointh = rs.PointTransform(mpoints[m], matrixh)  #按照变换矩阵逐个移动每一个点
        rs.AddPoint(pointh)  #在rhino空间中增加每次移动点
        mpointh.append(pointh)  #将点加入列表
        deletep.append(pointh)
    dpoints[i] = deletep  #加入字典
    deletep = []
print(dpoints)
Esempio n. 14
0
 def _shift_points(self, points, vec):
     x_form = rs.XformTranslation(vec)
     return rs.PointArrayTransform(points, x_form)
                if pCounter == _panelIndex:

                    panel = panelData[i][0]
                    break

        if panel:

            for ang in angle:
                widthOffset = panel.GetPanelProperty("PanelWidth") / 2
                if ang == None: ang = 0
                arrBoxPoints = [[offsetX-widthOffset, offsetY, offsetZ],[offsetX + widthOffset, offsetY, offsetZ],\
                    [offsetX-widthOffset, offsetY, offsetZ+panel.GetPanelProperty("PanelHeight")],\
                    [offsetX + widthOffset, offsetY, offsetZ+panel.GetPanelProperty("PanelHeight")]]

                xform = rs.XformTranslation((0, -LocCircle.Radius, 0))
                arrBoxPoints = rs.PointArrayTransform(arrBoxPoints, xform)
                xform = Rhino.Geometry.Transform.Rotation(
                    math.radians(ang), Rhino.Geometry.Vector3d.ZAxis, Loc)
                for point in arrBoxPoints:
                    point.Transform(xform)

                #create text info
                #rs.CurrentLayer("_P_0")
                #panelName = panel.GetName()
                #textTypes.append(rs.AddText(panelName, rs.PointSubtract(arrBoxPoints[0], [0,1,0]), fontHeight, font_style=fontStyle))
                #rs.RotateObject(textTypes[len(textTypes)-1], rs.TextObjectPoint(textTypes[len(textTypes)-1]), 270)

                #create and draw panel selected
                newPanel = SGLibPanel()
                newPanel.Copy(panel)
Esempio n. 16
0
#coding=utf-8
import rhinoscriptsyntax as rs

plane = rs.WorldXYPlane()  #建立XY工作平面
mplane = rs.MovePlane(plane, [6, 6.5, 0])  #移动平面
rectangle = rs.AddCircle(mplane, 5)  #建立圆形
dpointsc = rs.DivideCurve(rectangle, 20)  #等分矩形
dpoints = rs.AddPoints(dpointsc)  #增加等分点
for i in range(len(dpoints)):
    rs.AddText(str(i), dpoints[i], 1)  #添加字
print(dpoints)

#sphere = rs.AddSphere(dpoints[3],1)
#cube = rs.AddBox(rs.BoundingBox(sphere))

sdpoints = dpoints[:]  #切片提取点
for i in range(len(sdpoints)):
    sphere = rs.AddSphere(sdpoints[i], 0.5)
    cube = rs.AddBox(rs.BoundingBox(sphere))
    rs.DeleteObject(sphere)  #删除不再使用的球体
    xform = rs.XformTranslation([i, i * 1.3, i * 1.3])  #分步骤执行比gh同步更灵活
    trancube = rs.TransformObject(cube, xform)
Esempio n. 17
0
rs.CapPlanarHoles(surf)

#Draw spines
cone = rs.AddCone([0, 0, -sh], sh, sr)
basis = []
theta = ma.pi / 8
dphi = 2 * ma.pi / m
for k in range(0, m):
    phi = k * dphi
    x = ma.sin(theta) * ma.cos(phi)
    y = ma.sin(theta) * ma.sin(phi)
    z = ma.cos(theta)
    matrix = rs.XformRotation3([0, 0, 1], [x, y, z], [0, 0, 0])
    basis.append(rs.TransformObject(cone, matrix, True))
rs.DeleteObject(cone)

for crv in ridges:
    domain = rs.CurveDomain(crv)
    dt = (domain[1] - domain[0]) / 10
    for j in range(1, 10):
        t = domain[0] + j * dt
        point = rs.EvaluateCurve(crv, t)
        xaxis = rs.CurveTangent(crv, t)
        yaxis = rs.VectorCrossProduct(xaxis, point)
        zaxis = rs.VectorCrossProduct(xaxis, yaxis)
        matrix = rs.XformRotation3([0, 0, 1], zaxis, [0, 0, 0])
        copy = rs.TransformObjects(basis, matrix, True)
        matrix = rs.XformTranslation(point)
        rs.TransformObjects(copy, matrix)
    rs.DeleteObjects(basis)
Esempio n. 18
0
def profileXform(sec, plane, vec):
    xvec = rs.XformTranslation(vec)
    cob = rs.XformChangeBasis(plane, rs.WorldXYPlane())
    xform = rs.XformMultiply(cob, xvec)
    return rs.TransformObjects(sec, xform, False)
Esempio n. 19
0
plane = rs.WorldXYPlane()   #��ȡxy��ԭ��Ϊ���ĵIJο�ƽ��
rectangle = rs.AddRectangle(plane,40,40)

dpointsCoordinate = rs.DivideCurve(rectangle,10) #�ȷ�10����
dpoints = rs.AddPoints(dpointsCoordinate)   #���ӵȷֵ�
print(dpoints)

format = "point_%s" #��ʽ���ַ�����ģʽ
dpointe = []
i = 0
for i in  range(len(dpoints)):
    dpointe.append(format % str(i)) #��ʽ���ַ�������һ׷�ӵ��б�
print(dpointe)

dpointx = list(range(len(dpoints))) #�����ȷֵ�����
print(dpointx)

#��Ƭ����������
selepoints = dpoints[x:y]
cubes = []
print(selepoints)
for i in range(len(selepoints)):
    sphere = rs.AddSphere(selepoints[i],3)  #��ȡ[y](Բ�ģ��뾶)
    cube = rs.AddBox(rs.BoundingBox(sphere))    #�����壬plane��
#    id = rs.GetObject(sphere)
#    if id: rs.DeleteObject()
    xform = rs.XformTranslation([i,i*5,i*5])    #x������ƶ�����
    trancube = rs.TransformObject(cube,xform)   #�ƶ�����
    cubes.append(trancube)
print(cubes)
Esempio n. 20
0
def translate_plane(plane, vector):
    """Shifts the input plane by the given vector."""
    translation = rs.XformTranslation(vector)
    return rs.PlaneTransform(plane, translation)
Esempio n. 21
0
__author__ = "billpower"
__version__ = "2019.12.27"

import rhinoscriptsyntax as rs

#start建立基本结构线
basicpoint = rs.GetPoint("pick one point")  #1.拾取一个点
matrix = rs.XformTranslation((80, 0, 0))  #建立用于移动的矩阵
mbpoint = rs.PointTransform(basicpoint, matrix)  #根据建立的矩阵移动点

basicline = rs.AddLine(basicpoint, mbpoint)  #2.建立一条直线

offsetdistance = 10
offsetlineA = rs.OffsetCurve(basicline, [0, 0, 0], offsetdistance,
                             [0, 0, 1])  #3.偏移复制直线
offsetlineB = rs.OffsetCurve(basicline, [0, 0, 0], -offsetdistance, [0, 0, 1])

#调整结构线,使用提取点移动
extendvalue = 2  #中间直线延长的距离
extendline = rs.ExtendCurveLength(basicline, 0, 2, extendvalue)  #4.延长中间直线

startpoint = rs.CurveStartPoint(extendline)  #5.拾取两侧端点
endpoint = rs.CurveEndPoint(extendline)
midpoint = rs.CurveMidPoint(extendline)

heightA = 10
heightB = 18
matrixstartend = rs.XformTranslation((0, 0, heightA))  #建立端点移动矩阵
matrixmid = rs.XformTranslation((0, 0, heightB))  #建立中间点移动矩阵

mstartpoint = rs.PointTransform(startpoint, matrixstartend)  #根据矩阵移动开始点
#Define empty Square list and parameters
rectangleList = []
amountSquares = 5
initialSquareSize = 1
squaresOffset = 2

#Generate square of grid

#iterate trough X axis
for x in range(gridAmountX):
    #iterate trough Y axis
    for y in range(gridAmountY):
        tempRectangleList = []
        #iterate for rectangle from each point
        for size in range(initialSquareSize,amountSquares*squaresOffset+initialSquareSize, squaresOffset):
            #Starting Point
            point = rs.CreatePoint(x*gridSizeX, y*gridSizeY, 0)
            #Just to viz
            pointList.append(point)
            #Correct the origin point for each rectangle (It's not domained, it starts from the 0,0)
            translation = rs.XformTranslation([-size/2, -size/2, 0])
            correctedPoint = rs.TransformObject(point, translation, True)
            currentPlane = rs.CreatePlane(correctedPoint, (1,0,0), (0,1,0))
            #Create all te rectangles from each point
            tempRectangleList.append(rs.AddRectangle(currentPlane, size, size))
        #Appends each sets of rectangle to the tree
        rectangleList.append(tempRectangleList)

#Converts the list of list to a GH Tree
offsetRectangle = th.list_to_tree(rectangleList)
Esempio n. 23
0
def main():

    # get our curves
    profile, cross = get_two_curves()
    if profile is None or cross is None:
        return

    ##################################################
    # get bounding box for cross section
    
    cross_bbox = rs.BoundingBox([cross])

    

    cmin, cmax = box_to_points(cross_bbox)

    cz_range = cmax[2] - cmin[2]
    cz = 0.5 * (cmax[2] + cmin[2])

    c_ctr, _ = rs.CurveAreaCentroid(cross)

    # make sure it's planar in XY
    if cz_range > 1e-9:
        print 'cross section curve should be planar in XY plane'
        return

    ##################################################
    # get bounding box for profile
    
    profile_bbox = rs.BoundingBox([profile])

    # make sure it's planar in in YZ
    pmin, pmax = box_to_points(profile_bbox)
    
    px_range = pmax[0] - pmin[0]
    
    if px_range > 1e-9:
        print 'profile curve should be planar in YZ plane'
        return

    ##################################################
    # get the point closest to the center for the
    # cross-section curve
    
    r, pc = get_inscribed_radius(cross, c_ctr)

    ##################################################
    # get the range of z-values for the profile curve

    _, _, z0 = pmin
    _, _, z1 = pmax

    ##################################################
    # build list of rings and list of points

    points = []
    ring_pipes = []

    # for each level
    for i in range(num_levels):

        # get the Z value of the ith plane
        u = float(i) / (num_levels-1)
        z = z0 + u*(z1 - z0)

        # build the i'th plane
        plane = rs.PlaneFromNormal([0, 0, z], [0, 0, 1], [1, 0, 0])

        # find out where the plane intersects the profile curve
        intersect = rs.PlaneCurveIntersection(plane, profile)

        # there should be exactly one intersection of type 1 (point)
        if intersect is None or len(intersect) > 1 or intersect[0][0] != 1:
            print 'bad intersection'
            return

        # get the intersection point
        pi = intersect[0][1]

        # get the desired XY radius at this z value
        ri = abs(pi[1])

        # we need to set up some transformations:

        # translate cross section curve down to z=0
        T1 = rs.XformTranslation(mz.vec_mul(list(c_ctr), -1.0))

        # scale it along XY by the ratio of radii
        S1 = rs.XformScale([ri/r, ri/r, 1.0])

        # scale a piped cross section along Z by a vertical scale factor
        S2 = rs.XformScale([1.0, 1.0, ring_vscale])

        # translate piped cross section up to our desired z value
        T2 = rs.XformTranslation([0, 0, z])

        # scale and translate cross section curve
        ci = rs.TransformObject(cross, rs.XformMultiply(S1, T1), copy=True)

        # pipe it
        ring = rs.AddPipe(ci, [0, 1], [ring_rad, ring_rad])

        # scale vertically and transform up
        ring = rs.TransformObject(ring, rs.XformMultiply(T2, S2))

        # delete the copy of the cross section curve
        rs.DeleteObject(ci)

        # add to list of ring pipes
        ring_pipes.append(ring)

        # create a rotation by the i'th angle
        angle_i_deg = i*360.0/num_sides
        Ri = rs.XformRotation2(angle_i_deg, [0, 0, 1], [0, 0, 0])

        # transform the closest point by rotation and scale
        pci = rs.PointTransform(pc,
                                rs.XformMultiply(rs.XformMultiply(Ri, T2), S1))

        # add to list of points
        points.append(pci)

    # we have built up a list of points for a single spiral of struts to connect,
    # now we need to pipe them all together and do the ArrayPolar thing around
    # the z axis

    # first build a single spiral of struts
    strut_pipes = []

    for i0 in range(num_levels-1):
        i1 = i0+1
        p0 = points[i0]
        p1 = points[i1]
        l01 = rs.AddLine(p0, p1)
        pipe = rs.AddPipe(l01, [0, 1], [strut_rad, strut_rad], cap=2)
        rs.DeleteObject(l01)
        strut_pipes.append(pipe)

    # then array polar around Z axis
    all_strut_pipes = []
    all_strut_pipes += strut_pipes

    for j in range(1, num_sides):
        angle_j_deg = j*360.0/num_sides
        Rj = rs.XformRotation2(angle_j_deg, [0, 0, 1], [0, 0, 0])
        all_strut_pipes += rs.TransformObjects(strut_pipes, Rj, copy=True)

    # now just select all the objects we created
    rs.SelectObjects(ring_pipes + all_strut_pipes)

    # done!
    print 'yay'
Esempio n. 24
0
import rhinoscriptsyntax as rs
from Rhino.Geometry import Point3d, Vector3d

#lines = rs.GetObjects("Select lines", filter=4)
lines = rs.AllObjects()

for i in range(len(lines)):
    p = Point3d(i, 0, 0)
    v = p - rs.CurveStartPoint(lines[i])
    rs.TransformObject(lines[i], rs.XformTranslation(v))
    a = rs.Angle(rs.CurveStartPoint(lines[i]), rs.CurveEndPoint(lines[i]))[0]
    rs.TransformObject(lines[i], rs.XformRotation2(90 - a, Vector3d.ZAxis, p))

start = 1
while start < len(lines):
    current = start
    while current > 0 and rs.CurveLength(lines[current - 1]) > rs.CurveLength(
            lines[current]):
        rs.TransformObject(lines[current], rs.XformTranslation((-1, 0, 0)))
        rs.TransformObject(lines[current - 1], rs.XformTranslation((1, 0, 0)))
        lines[current], lines[current - 1] = lines[current - 1], lines[current]
        current -= 1
        rs.Sleep(500)
    start += 1