Esempio n. 1
0
def RunCommand():
    crvA = rs.GetCurveObject("first curve")[0]
    crvA = rs.coercecurve(crvA)
    crvB = rs.GetCurveObject("second curve")[0]
    crvB = rs.coercecurve(crvB)
    if crvA == None or crvB == None:
        return Rhino.Commands.Result.Failure

    maxa, maxb, maxd, mina, minb, mind = rs.CurveDeviation(crvA, crvB)

    if mind <= Rhino.RhinoMath.ZeroTolerance:
        mind = 0.0
    maxDistPtA = crvA.PointAt(maxa)
    maxDistPtB = crvB.PointAt(maxb)
    minDistPtA = crvA.PointAt(mina)
    minDistPtB = crvB.PointAt(minb)

    print "Minimum deviation = {0}   pointA({1}, {2}, {3}), pointB({4}, {5}, {6})".format(
        mind, minDistPtA.X, minDistPtA.Y, minDistPtA.Z, minDistPtB.X,
        minDistPtB.Y, minDistPtB.Z)
    print "Maximum deviation = {0}   pointA({1}, {2}, {3}), pointB({4}, {5}, {6})".format(
        maxd, maxDistPtA.X, maxDistPtA.Y, maxDistPtA.Z, maxDistPtB.X,
        maxDistPtB.Y, maxDistPtB.Z)
Esempio n. 2
0
    def SetPlanarCurve(self, type="Any", guid=None):
        if (type == "Any"): prompt = "Select a planar pitch curve"
        elif (type == "Circle"): prompt = "Select the pitch circle"

        newCurve = rs.GetCurveObject(prompt, True,
                                     True) if guid is None else [guid]
        if (newCurve is None):
            Rhino.RhinoApp.WriteLine("Exit: No curve was selected")
            return False
        isPlanar = rs.IsCurvePlanar(newCurve[0])
        if (isPlanar == False):
            newCurve = None
            Rhino.RhinoApp.WriteLine("Exit: Selected curve was not planar")
            return False

        self.curve = newCurve  #Accept the curve into the object because the curve exists and it is planar
        self.isClosed = rs.IsCurveClosed(self.curve[0])
        self.normal = rs.CurveNormal(
            self.curve[0])  #For non planar curves the script already exited.

        self.isCircle = rs.IsCircle(self.curve[0])
        if (type == "Circle" and self.isCircle != True):
            Rhino.RhinoApp.WriteLine("Exit: Selected curve was not a circle")
            return False

        self.crvLen = rs.CurveLength(self.curve[0])
        if (self.isCircle == True):
            Rhino.RhinoApp.WriteLine("Selected: Circle")
            self.origin = rs.CircleCenterPoint(self.curve[0])
            self.plane = rs.PlaneFromNormal(
                self.origin, self.normal,
                rs.CurveStartPoint(self.curve[0]) -
                self.origin)  #PlaneFromNormal(origin, normal, xaxis=None)
            self.SetPD()  #Propagate the value updates
            self.SetBC()  #Propagate the value updates
            return
        if (self.isClosed == True):
            Rhino.RhinoApp.WriteLine(
                "Selected: Closed non-circular planar curve")
            return
        else:
            Rhino.RhinoApp.WriteLine("Selected: Open planar curve")
def addArcLeader():
    """
    Automatically calculates and annotates the length of a curve object,
    used primarily for arc length
    
    Input parameters: None    
    
    Returns: Guid if successful
             None if failure    
    """

    try:
        #assign empty variables
        points = []
        leader = None

        #get curve
        crv = rs.GetCurveObject("Select curve object")
        crvLen = rs.CurveLength(crv[0])  #get curve's length

        #get points
        pts = rs.GetPoints("AddPoints, press enter when done")
        points = rs.AddPoints(pts)

        #make leader
        leader = rs.AddLeader(points,
                              text="ArcLength: " + str(round(crvLen, 3)))
        return leader

    except Exception:
        pass

    finally:
        if points:
            rs.DeleteObjects(
                points)  #points will be deleted even upon exception
        return leader
Esempio n. 4
0
            else:
                # print "Cool"
                centroid = rs.CurveAreaCentroid(pl)
                centpt = rs.AddPoint(centroid[0])
                curves = rs.ExplodeCurves(pl)
                for crv in curves:
                    # print crv
                    pt1 = rs.CurveStartPoint(crv)
                    pt2 = rs.CurveEndPoint(crv)
                    pts = []
                    pts.append(pt1)
                    pts.append(pt2)
                    pts.append(centpt)
                    pts.append(pt1)
                    newpl = rs.AddPolyline(pts)
                    pls.append(newpl)
                    rs.DeleteObject(crv)
                cleanup = []
                cleanup.append(centpt)
                # cleanup.append(curves)
                rs.DeleteObjects(cleanup)
        count = count - 1
        return crackpolygon(pls, count)


count = rs.GetInteger("How many iterations would you like to do?", 3)
pl = rs.GetCurveObject("pick a closed curve to crack")
plguid = pl[0]
polygons = []
polygons.append(plguid)
crackpolygon(polygons, count)
Esempio n. 5
0
"""
Author: Angel Linares Garcia.
Date: 150821
Description: This scripts takes one
selected curve and creates N offsets
at D distance.
"""
##############################

import rhinoscriptsyntax as rs

strCrv0 = rs.GetCurveObject("Select curve", True)
intTimes = rs.GetInteger("Number of repetitions")
dblDist = rs.GetReal("Distance between curves")
pt0 = rs.GetPoint("Selec offset side")
rs.EnableRedraw(False)

for i in range(intTimes):

    newCurve = rs.OffsetCurve(strCrv0[0], pt0, dblDist * (i + 1))
    strCrv = newCurve

rs.EnableRedraw(True)
Esempio n. 6
0
import rhinoscriptsyntax as rs

degrees = 30
numCurves = 12

ln = rs.GetCurveObject("Pick a line")

#print ln

for i in range(0, numCurves):

    # pt = rs.CurveEndPoint(ln[0])
    pt = (0, 0, 0)
    nl = rs.RotateObject(ln[0], pt, degrees * i, (0, 0, 1), True)
    #nl2 = rs.MoveObject(nl, [i,0,0])
Esempio n. 7
0
import rhinoscriptsyntax as rs
import math
import random
import Rhino.Geometry as rg

result = rs.GetCurveObject()
curveid = result[0]
rail = rs.GetCurveObject()


def TransformProfile(object, pt1, pt2):
    normal = rs.VectorSubtract(pt1, pt2)
    normal = rs.VectorUnitize(normal)

    plane = rs.PlaneFromNormal(pt1, normal)

    transformation = rs.XformRotation1((rs.WorldXYPlane), normal)
    profiletras = rs.TransformObject(object, transformation, True)


#pt1=rs.CurveStartPoint
#pt2=rs.CurveEndPoint

pt1 = rs.GetPoint()
pt2 = rs.GetPoint()
rs.MoveObject(curveid, rs.VectorCreate(pt1, pt2))
print rs.VectorCreate(pt1, pt2)
Esempio n. 8
0
def main():
    #select a brep and 2 guide curves
    filter = ObjectType.Mesh | ObjectType.Brep
    result, obj = RhinoGet.GetOneObject('选择多重曲面或者网格', False, filter)
    brep = obj.Brep() or obj.Mesh()
    id1 = rs.GetCurveObject('第一条引导曲线')[0]
    curve1 = rs.coercecurve(id1)
    id2 = rs.GetCurveObject('第二条引导曲线')[0]
    while id2 == id1:
        id2 = rs.GetCurveObject('选择一条不同的曲线!')[0]
    curve2 = rs.coercecurve(id2)
    step1 = rs.GetInteger('沿第一条曲线的切割间距', number = 5)
    step2 = rs.GetInteger('沿第二条曲线的切割间距', number = 5)
    global solid
    solid = rs.GetBoolean('是否切穿实体?',('选择','否','是'),False)[0]
    offset_dist = rs.GetReal('生成条带的偏移宽度?(正值向外,负值向内,决定标注字体大小)', number = 2)
    thickness = rs.GetReal('材料的厚度', number = 0.3)

    #make ribs
    breps1, outline1 = make_ribs(brep, curve1, step1, offset_dist, thickness)
    breps2, outline2 = make_ribs(brep, curve2, step2, offset_dist, thickness)
    offset_dist = abs(offset_dist)
    #cutline stroage
    
    for s in breps1:
        cutlines[str(s)] = []
    for s in breps2:
        cutlines[str(s)] = []
    #find intersect and make notch line
    brep_surf = breps1 + breps2
    out_lines = outline1 + outline2
    intsect(brep_surf, thickness)
    #arrange to xy plane
    y1 = 0
    y2 = 0
    x_max = 0
    for i, b in enumerate(brep_surf):
        outline = out_lines[i]
        cut = cutlines[str(b)]
        for c in cut:
            count = 0
            for c2 in outline[:-1]:
                event = Intersect.Intersection.CurveCurve(c, c2, 0.2, tol)
                if event:
                    count += 1
            if count > 1:
                outline = outline[0:-1]
        #0: orient to worldXY plane
        surf = b.Surfaces[0]
        from_pl = surf.TryGetPlane()[1]
        to_pl = Plane.WorldXY
        xform = Transform.PlaneToPlane(from_pl, to_pl)
        group1 = Group(str(b))
        group1.Add(cut)
        group1.Add(outline)
        group = Group('new' + str(b))
        group.Add(group1.objects)
        b_in_breps1 = 0
        if b in breps1:
            text = 'x%d'%i
            b_in_breps1 = 1
        else:
            text = 'y%d'%(i-len(breps1))
        original_box = group1.bbox(plane = from_pl)
        group1.Add([TextDot(text,from_pl.Origin)])
        group1.Display()
        #arrange 1 : get boundingbox
        group.Transform(xform)
        bbox = group.bbox()
        bbox.Inflate(offset_dist, offset_dist, 0)
        xlen = (bbox.Max-bbox.Min).X
        ylen = (bbox.Max-bbox.Min).Y
        #arrange 2 : rotate according to x,y size
        if ylen > xlen:
            xlen, ylen = ylen, xlen
            rot = Transform.Rotation(math.pi/2, Vector3d.ZAxis,bbox.Center)
            group.Transform(rot)
        x_max = xlen if xlen > x_max else x_max
        #arrange 3 : align bbox cornor to worldXY origin
        cornor_plane = Plane(bbox.Min, Vector3d.ZAxis)
        align_xform = Transform.PlaneToPlane(cornor_plane, to_pl)
        group.Transform(align_xform)
        #arrange 4 : translate each group to proper position
        center = bbox.Center
        if b_in_breps1:
            move = Vector3d(0,y1,0)
            y1 += ylen 
        else:
            move = Vector3d(x_max ,y2,0)
            y2 += ylen 
        group.Transform(Transform.Translation(move))
        group.label(text,offset_dist)
        group.Display()
    render(brep_surf)
    doc.Objects.Hide(obj,True)
    doc.Views.Redraw()