def getExtendedCrv(self, crvList, dist=50, layer_height=2.5, vecMul=.66):
     segmentCount = int(math.floor(dist / layer_height)) - 1
     tmpList = []
     fullHeight = []
     for i in range(len(crvList)):
         extendedCrv = rs.ExtendCurveLength(crvList[i], 2, 0, dist)
         fullHeight.append(extendedCrv)
         domStart, domEnd = rs.CurveDomain(extendedCrv)
         trimmedCrv = rs.TrimCurve(extendedCrv, (domStart, 0))
         tmpList.append(trimmedCrv)
     tmp = []
     ###Smooth Curves###
     for i in range(len(tmpList)):
         bottomPt = rs.CurveEndPoint(tmpList[i])
         zVec = rs.VectorAdd((0, 0, 0), (0, 0, dist))
         topPt = rs.CopyObject(bottomPt, zVec)
         line = rs.AddLine(bottomPt, topPt)
         crvPts = rs.DivideCurve(tmpList[i], segmentCount)
         LinePts = rs.DivideCurve(line, segmentCount)
         for i in range(segmentCount):
             tmpVec = rs.VectorCreate(LinePts[segmentCount - i - 1],
                                      crvPts[i])
             tmpVec = rs.VectorScale(tmpVec, vecMul)
             rs.MoveObject(crvPts[i], tmpVec)
         tmp.append(rs.AddInterpCurve(crvPts))
         result = []
         for crv in tmp:
             crvLen = rs.CurveLength(crv)
             if crvLen < dist:
                 tmpExt = dist - crvLen
                 result.append(rs.ExtendCurveLength(crv, 2, 0, tmpExt))
             else:
                 result.append(rs.CopyObject(crv))
     return result
def HorizontalLines():
    #Course = rs.OffsetCurve(,bbox[3],sill_remain)

    Surf_Height = rs.Distance(bbox[0], bbox[3])

    #number of horizontal cources
    hori_no = Surf_Height / ipHeight

    #convert to intiger
    hori_no = int(hori_no)

    Course_All = []

    Course = rs.AddLine(bbox[0], bbox[1])

    Course_start = rs.ExtendCurveLength(Course, 0, 0, ipThick)
    Course_end = rs.ExtendCurveLength(Course, 0, 1, ipThick)

    Course = rs.JoinCurves((Course_start, Course, Course_end), True)
    Course1 = Course

    Course_All.append(Course)
    for index in range(0, hori_no, 1):
        Course = rs.OffsetCurve(Course, bbox[3], ipHeight)
        Course_All.append(Course)

    Course = rs.OffsetCurve(Course1, bbox[3], Surf_Height)
    Course_All.append(Course)

    rs.ObjectColor(Course_All, [255, 0, 0])

    return Course_All
Exemplo n.º 3
0
def extrude_solid(pt, cp, b):
    # int_solid: (listof pt) pt curve -> (listof solid)
    lo_solid = []
    ptlst = rs.CurvePoints(b)
    srf = rs.AddPlanarSrf(rs.AddCurve(ptlst, 1))
    # make curve and extrude
    line = rs.AddCurve([cp, pt], 1)
    max = get_max_side(b)
    curve = rs.ExtendCurveLength(line, 0, 1, max * 40)
    #extrude surface
    brep = rs.coercebrep(srf, True)
    curve = rs.coercecurve(curve, -1, True)
    newbrep = brep.Faces[0].CreateExtrusion(curve, True)
    if newbrep:
        rc = sc.doc.Objects.AddBrep(newbrep)
        sc.doc.Views.Redraw()
        return rc
Exemplo n.º 4
0
def unfilletCurve(curve):
    rs.EnableRedraw(False)

    curLay = rs.CurrentLayer()
    childrenLay = rs.LayerChildren(curLay)
    cutCrvs = []
    contours = []
    finalLines = []
    finalLineSegs = []
    tempCrv = curve
    if tempCrv is not None:
        cutCrvs.append(tempCrv)

    for crv in cutCrvs:
        contours.append(ghcomp.Explode(crv, True)[0])

    for contour in contours:
        for i in range(0, len(contour)):
            if rs.IsLine(contour[i]):
                finalLines.append(sc.doc.Objects.AddCurve(contour[i]))
    finalPts = []
    for line in finalLines:
        rs.ExtendCurveLength(line, 0, 2, 300)
    for i in range(0, len(finalLines) - 1):
        tempPt = rs.CurveCurveIntersection(finalLines[i], finalLines[i + 1])
        finalPts.append(rs.AddPoint(rs.coerce3dpoint(tempPt[0][1])))
    tempPt = rs.CurveCurveIntersection(finalLines[-1], finalLines[0])
    finalPts.append(rs.AddPoint(rs.coerce3dpoint(tempPt[0][1])))
    for i in range(0, len(finalPts) - 1):
        finalLineSegs.append(rs.AddLine(finalPts[i], finalPts[i + 1]))
    finalLineSegs.append(rs.AddLine(finalPts[-1], finalPts[0]))
    lastCrv = rs.JoinCurves(finalLineSegs, True)
    sc.doc.Views.Redraw()

    rs.DeleteObjects(finalPts)
    rs.DeleteObjects(finalLines)
    rs.DeleteObject(tempCrv)
    rs.DeleteObjects(cutCrvs)
    rs.EnableRedraw(True)

    rs.SelectObject(lastCrv)
Exemplo n.º 5
0
def outline_region():
	
	
	go = Rhino.Input.Custom.GetObject()
	go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
	
	default_length = sc.sticky["length"] if sc.sticky.has_key("length") else 100
	default_delete = sc.sticky["delete"] if sc.sticky.has_key("delete") else True
	
	opt_delete = Rhino.Input.Custom.OptionToggle(default_delete,"No","Yes")
	go.SetCommandPrompt("Select Curves")
	go.AddOptionToggle("DeleteInput", opt_delete)

	go.GroupSelect = True
	go.SubObjectSelect = False
	go.AcceptEnterWhenDone(True)
	go.AcceptNothing(True)
	go.EnableClearObjectsOnEntry(False)
	go.GroupSelect = True
	go.SubObjectSelect = False
	go.DeselectAllBeforePostSelect = False
	
	res = None
	bHavePreselectedObjects = False
	while True:
		res = go.GetMultiple(1,0)
		if res == Rhino.Input.GetResult.Option:
			#print res
			go.EnablePreSelect(False, True)
			continue
		#If not correct
		elif res != Rhino.Input.GetResult.Object:
			print "No curves selected!"
			return Rhino.Commands.Result.Cancel
		if go.ObjectsWerePreselected:
			bHavePreselectedObjects = True
			go.EnablePreSelect(False, True)
			continue
		break
	
	input_curves = []
	for i in xrange(go.ObjectCount):
		b_obj = go.Object(i).Object()
		input_curves.append(b_obj.Id)
	
	#Get length
	extension_length = rs.GetInteger(message="Enter Extension Length",number=default_length)
	if not extension_length:
		rs.EnableRedraw(True)
		print "No Extension Length entered."
		return False

	arr_preview_geom = get_preview_geometry(input_curves)
	for indCrv in arr_preview_geom:
		rs.ExtendCurveLength(indCrv,0,2,extension_length)
	
	rs.EnableRedraw(False)
	#Get curveboolean and display it
	region_was_created = True
	rs.UnselectAllObjects()
	rs.SelectObjects(arr_preview_geom)
	
	rs.Command("_-CurveBoolean _AllRegions _Enter")
	
	pcurve_outline = rs.LastCreatedObjects()
	
	if isinstance(pcurve_outline,list):
		preview_srf = rs.AddPlanarSrf(pcurve_outline)
		rs.LockObjects(arr_preview_geom)
		rs.LockObjects(preview_srf)
	else:
		region_was_created = False
		rs.LockObjects(arr_preview_geom)
		preview_srf = []

	rs.EnableRedraw(True)
	rs.Redraw()

	#Set up input object
	go = Rhino.Input.Custom.GetOption()
	optint = Rhino.Input.Custom.OptionDouble(extension_length)

	prompt = "Press Enter to accept"
	warning = "Insufficient overlap length. "
	s = prompt if region_was_created else warning+prompt
	go.SetCommandPrompt(s)
	go.AddOptionDouble("ExtensionLength", optint)
	go.AddOptionToggle("DeleteInput", opt_delete)
	go.AcceptEnterWhenDone(True)
	go.AcceptNothing(True)

	#control flow: can distinguish between inserting an option, cancelling, and pressing enter
	res = None
	while True:
		res = go.Get()
		rs.EnableRedraw(False)
		region_was_created = True
		
		#If new option entered, redraw a possible result
		if res == Rhino.Input.GetResult.Option:
			#Delete old preview
			rs.UnlockObjects(preview_srf+arr_preview_geom)
			rs.DeleteObjects(preview_srf+arr_preview_geom)
			if isinstance(pcurve_outline,list):
				rs.DeleteObjects(pcurve_outline)
			rs.SelectObjects(input_curves)
			
			#Draw new preview
			arr_preview_geom = get_preview_geometry(input_curves)
			if not extension_length: return False
			
			for indCrv in arr_preview_geom:
				rs.ExtendCurveLength(indCrv,0,2,optint.CurrentValue)
			
			rs.UnselectAllObjects()
			rs.SelectObjects(arr_preview_geom)
			rs.Command("_-CurveBoolean _AllRegions _Enter")
			pcurve_outline = rs.LastCreatedObjects()
			
			if isinstance(pcurve_outline,list):
				preview_srf = rs.AddPlanarSrf(pcurve_outline)
				rs.LockObjects(arr_preview_geom)
				rs.LockObjects(preview_srf)
			else:
				rs.LockObjects(arr_preview_geom)
				preview_srf = []
				region_was_created = False
			rs.EnableRedraw(True)
			
			s = prompt if region_was_created else warning+prompt
			go.SetCommandPrompt(s)
			
			continue

		#If accepted, leave loop
		elif res == Rhino.Input.GetResult.Nothing:
			break
		
		#If cancelled, delete working geometry
		elif res != Rhino.Input.GetResult.Option:
			rs.UnlockObjects(preview_srf)
			rs.UnlockObjects(arr_preview_geom)
			rs.DeleteObjects(preview_srf)
			rs.DeleteObjects(arr_preview_geom)
			rs.DeleteObjects(pcurve_outline)
			rs.EnableRedraw(True)
			return Rhino.Commands.Result.Cancel
	

	#Clean up if successful
	if opt_delete.CurrentValue == True: rs.DeleteObjects(input_curves)
	rs.UnlockObjects(preview_srf)
	rs.UnlockObjects(arr_preview_geom)
	rs.DeleteObjects(preview_srf)
	rs.DeleteObjects(arr_preview_geom)
	if isinstance(pcurve_outline,list):
		rs.SelectObjects(pcurve_outline)
	
	sc.sticky["length"] = optint.CurrentValue
	sc.sticky["delete"] = opt_delete.CurrentValue
	
	rs.EnableRedraw(True)
Exemplo n.º 6
0
#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)  #根据矩阵移动开始点
mendpoint = rs.PointTransform(endpoint, matrixstartend)  #移动结束点
mmidpoint = rs.PointTransform(midpoint, matrixmid)  #移动中心点

#整理变量到列表
def Main():

    rectangle = rs.GetObject(
        "Select rectangle to create mortise and tenon from", rs.filter.curve,
        True, True)

    if rs.IsCurveClosed(rectangle):
        x = 0
    else:
        print "Failed....Curve must be closed and rectangular"
        return

    if rs.IsCurvePlanar(rectangle):
        x = 0
    else:
        print "Failed....Curve must be planar"
        return

    lines = rs.ExplodeCurves(rectangle)
    count = 0

    for line in lines:
        count = count + 1

    if count != 4:
        print "Failed....To many line segments, redraw rectangle"
        return

    if rs.IsLine(lines[0]):
        x = 0
    else:
        print "Failed....Curve must be rectangular"
        return

    if rs.IsLine(lines[1]):
        x = 0
    else:
        print "Failed....Curve must be rectangular"
        return

    if rs.IsLine(lines[2]):
        x = 0
    else:
        print "Failed....Curve must be rectangular"
        return

    if rs.IsLine(lines[3]):
        x = 0
    else:
        print "Failed....Curve must be rectangular"
        return

    face = rs.GetObject("Select tenon surface", rs.filter.surface, False, True,
                        None, True)

    length = rs.GetReal("Enter tenon length", number=None)
    if length and length != 0:
        x = 0
    else:
        print "Failed....No length was entered"
        return

    depth = rs.GetReal("Enter mortise depth", number=length + 0.05)
    if depth and depth != 0:
        x = 0
    else:
        print "Failed....No depth was entered"
        return

    fit = rs.GetReal("Enter mortise fit", number=0.01)

    line1 = rs.AddLine(rs.CurveStartPoint(lines[0]),
                       rs.CurveEndPoint(lines[0]))
    line2 = rs.AddLine(rs.CurveStartPoint(lines[1]),
                       rs.CurveEndPoint(lines[1]))
    line3 = rs.AddLine(rs.CurveStartPoint(lines[2]),
                       rs.CurveEndPoint(lines[2]))
    line4 = rs.AddLine(rs.CurveStartPoint(lines[3]),
                       rs.CurveEndPoint(lines[3]))

    rs.DeleteObjects(lines)
    lines = line1, line2, line3, line4

    if rs.CurveLength(lines[0]) > rs.CurveLength(lines[1]):
        smallside = rs.CurveLength(lines[1])
        longside1 = lines[0]
        longside2 = lines[2]
    else:
        smallside = rs.CurveLength(lines[0])
        longside1 = lines[1]
        longside2 = lines[3]

    filletRadius = smallside / 2

    fillet1 = rs.CurveFilletPoints(lines[0], lines[1])
    fillet2 = rs.CurveFilletPoints(lines[1], lines[2])
    fillet3 = rs.CurveFilletPoints(lines[2], lines[3])
    fillet4 = rs.CurveFilletPoints(lines[3], lines[0])

    arc1 = rs.AddFilletCurve(lines[0], lines[1], radius=filletRadius)
    arc2 = rs.AddFilletCurve(lines[1], lines[2], radius=filletRadius)
    arc3 = rs.AddFilletCurve(lines[2], lines[3], radius=filletRadius)
    arc4 = rs.AddFilletCurve(lines[3], lines[0], radius=filletRadius)
    arcs = arc1, arc2, arc3, arc4

    arcs = rs.JoinCurves(arcs)

    arcEnd1 = rs.CurveEndPoint(arcs[0])
    arcStart1 = rs.CurveStartPoint(arcs[0])
    arcEnd2 = rs.CurveEndPoint(arcs[1])
    arcStart2 = rs.CurveStartPoint(arcs[1])

    if rs.Distance(arcEnd1, arcEnd2) > rs.Distance(arcEnd1, arcStart2):
        temp = arcEnd2
        arcEnd2 = arcStart2
        arcStart2 = temp

    line1 = rs.AddLine(arcEnd1, arcEnd2)
    line2 = rs.AddLine(arcStart1, arcStart2)

    curves = line1, arcs[0], arcs[1], line2
    tenonOut = rs.JoinCurves(curves)
    tenonSurf = rs.AddPlanarSrf(tenonOut)
    point = rs.SurfacePoints(face)

    param = rs.SurfaceClosestPoint(face, point[0])
    normal = rs.SurfaceNormal(face, param)
    normal = normal * length
    vect = rs.AddLine(arcEnd1, arcEnd1 + normal)

    tenon = rs.ExtrudeSurface(tenonSurf, vect, cap=True)

    rs.DeleteObjects(curves)
    arcs = arc1, arc2, arc3, arc4
    rs.DeleteObjects(arcs)
    rs.DeleteObject(rectangle)

    rs.ExtendCurveLength(longside1, 0, 0, fit)
    rs.ExtendCurveLength(longside1, 0, 1, fit)
    rs.ExtendCurveLength(longside2, 0, 0, fit)
    rs.ExtendCurveLength(longside2, 0, 1, fit)

    if rs.Distance(rs.CurveEndPoint(longside1),
                   rs.CurveEndPoint(longside2)) < rs.Distance(
                       rs.CurveStartPoint(longside1),
                       rs.CurveEndPoint(longside2)):
        line1Start = rs.CurveEndPoint(longside1)
        line1End = rs.CurveEndPoint(longside2)
        line2Start = rs.CurveStartPoint(longside1)
        line2End = rs.CurveStartPoint(longside2)
    else:
        line1Start = rs.CurveStartPoint(longside1)
        line1End = rs.CurveEndPoint(longside2)
        line2Start = rs.CurveEndPoint(longside1)
        line2End = rs.CurveStartPoint(longside2)

    shortside1 = rs.AddLine(line1Start, line1End)
    shortside2 = rs.AddLine(line2Start, line2End)

    arc1 = rs.AddFilletCurve(longside1, shortside1, radius=filletRadius)
    arc2 = rs.AddFilletCurve(shortside1, longside2, radius=filletRadius)
    arc3 = rs.AddFilletCurve(longside2, shortside2, radius=filletRadius)
    arc4 = rs.AddFilletCurve(shortside2, longside1, radius=filletRadius)
    arcs = arc1, arc2, arc3, arc4

    arcs = rs.JoinCurves(arcs)

    arcEnd1 = rs.CurveEndPoint(arcs[0])
    arcStart1 = rs.CurveStartPoint(arcs[0])
    arcEnd2 = rs.CurveEndPoint(arcs[1])
    arcStart2 = rs.CurveStartPoint(arcs[1])

    if rs.Distance(arcEnd1, arcEnd2) > rs.Distance(arcEnd1, arcStart2):
        temp = arcEnd2
        arcEnd2 = arcStart2
        arcStart2 = temp

    line1 = rs.AddLine(arcEnd1, arcEnd2)
    line2 = rs.AddLine(arcStart1, arcStart2)

    curves = line1, arcs[0], arcs[1], line2
    mortiseOut = rs.JoinCurves(curves)
    mortiseSurf = rs.AddPlanarSrf(mortiseOut)

    param = rs.SurfaceClosestPoint(face, point[0])
    normal = rs.SurfaceNormal(face, param)
    normal = normal * depth
    vect = rs.AddLine(arcEnd1, arcEnd1 + normal)

    mortise = rs.ExtrudeSurface(mortiseSurf, vect, cap=True)

    rs.DeleteObject(shortside1)
    rs.DeleteObject(shortside2)
    rs.DeleteObject(mortiseOut)
    rs.DeleteObject(mortiseSurf)
    rs.DeleteObjects(curves)
    rs.DeleteObjects(lines)
    arcs = arc1, arc2, arc3, arc4
    rs.DeleteObjects(arcs)
    rs.DeleteObject(rectangle)
    rs.DeleteObject(tenonOut)
    rs.DeleteObject(tenonSurf)

    return
Exemplo n.º 8
0
def drilling(curve_list, surface1, used_line2, unused_line, closest_p):
    split_num = 4
    point_list = []

    if not curve_list:
        # print("tan2: There is not curve")
        return

    if len(curve_list) != 1:
        cur_length = []
        length = 0

        # Message: unable to convert 0530c598-26e0-4ff5-a15a-389bd334aeff into Curve geometry
        for i in range(0, len(curve_list)):
            if rs.IsCurve(curve_list[i]):
                length = rs.CurveLength(curve_list[i])

        cur_length.append(length)

        curve_index = cur_length.index(max(cur_length))
        curve = curve_list[curve_index]

    else:
        curve = curve_list

    domain = rs.CurveDomain(curve)
    t = (domain[1] - domain[0]) / split_num

    for i in range(0, 4):
        dt = t * i
        point = rs.EvaluateCurve(curve, dt)
        point_list.append(point)

    # 直線の交点を求める
    line1 = rs.AddLine(point_list[0], point_list[2])
    line2 = rs.AddLine(point_list[1], point_list[3])

    vec1 = rs.VectorCreate(point_list[2], point_list[0])
    vec2 = rs.VectorCreate(point_list[3], point_list[1])

    cross = rs.VectorCrossProduct(vec1, vec2)
    normal = rs.VectorUnitize(cross)

    curveOnsurface1 = rs.ProjectCurveToSurface(line1, surface1, normal)
    curveOnsurface2 = rs.ProjectCurveToSurface(line2, surface1, normal)

    if len(curveOnsurface1) == 0:  # ttm add プロジェクションされていない可能性があるため
        new_vec1 = rs.VectorReverse(normal)
        curveOnsurface1 = rs.ProjectCurveToSurface(line1, surface1, new_vec1)

    if len(curveOnsurface2) == 0:  # ttm add プロジェクションされていない可能性があるため
        new_vec2 = rs.VectorReverse(normal)
        curveOnsurface2 = rs.ProjectCurveToSurface(line2, surface1, new_vec2)

    if len(curveOnsurface1) == 2 and len(curveOnsurface2) == 2:

        intersection1 = rs.CurveCurveIntersection(curveOnsurface1[0],
                                                  curveOnsurface2[0])
        intersection2 = rs.CurveCurveIntersection(curveOnsurface1[1],
                                                  curveOnsurface2[1])

        # 条件分岐
        if intersection1 is None:
            intersection1 = rs.CurveCurveIntersection(curveOnsurface1[0],
                                                      line2)

            if intersection1 is None:
                intersection1 = rs.CurveCurveIntersection(
                    curveOnsurface2[0], line1)

            if intersection1 is None:
                intersection1 = rs.CurveCurveIntersection(
                    curveOnsurface1[1], line2)

            if intersection1 is None:
                intersection1 = rs.CurveCurveIntersection(
                    curveOnsurface2[1], line1)

            if intersection1 is None:
                intersection1 = rs.CurveCurveIntersection(
                    curveOnsurface1[0], curveOnsurface2[1])
                intersection2 = rs.CurveCurveIntersection(
                    curveOnsurface1[1], curveOnsurface2[0])

    else:
        # normal_reverce = rs.VectorReverse(normal)
        # curveOnsurface1 = rs.ProjectCurveToSurface(line1, surface1, normal)
        # curveOnsurface2 = rs.ProjectCurveToSurface(line2, surface1, normal)

        intersection1 = rs.CurveCurveIntersection(
            curveOnsurface1[0], curveOnsurface2[0])  #index out of range: 0
        intersection2 = None

    # console
    # print("intersection1: %s" % (intersection1))
    # print("intersection2: %s" % (intersection2))

    if intersection1 is None and intersection2 is None:
        center_point = rs.CurveMidPoint(curveOnsurface1[0])

    elif intersection2 is None:
        center_point = intersection1[0][1]

    else:
        center_point1 = intersection1[0][1]
        center_point2 = intersection2[0][1]

        dis1 = rs.Distance(center_point1, closest_p)
        dis2 = rs.Distance(center_point2, closest_p)

        if dis1 > dis2:
            center_point = center_point2
        else:
            center_point = center_point1

    parameter1 = rs.CurveClosestPoint(unused_line, center_point)
    parameter2 = rs.CurveClosestPoint(used_line2, center_point)

    point1 = rs.EvaluateCurve(unused_line, parameter1)  # base point
    point2 = rs.EvaluateCurve(used_line2, parameter2)  # base point

    # ドリル穴のベクトルを生成
    drill_line = rs.AddLine(point1, point2)
    rs.CurveArrows(drill_line, 2)
    rs.ExtendCurveLength(drill_line, 0, 2, 100)

    drill_vec = rs.VectorCreate(point2, point1)

    # 外積計算より回転軸を生成
    start_point = rs.CurveStartPoint(unused_line)
    end_point = rs.CurveEndPoint(unused_line)

    distance1 = rs.Distance(start_point, center_point)
    distance2 = rs.Distance(end_point, center_point)

    if distance1 > distance2:
        select_point = end_point
    else:
        select_point = start_point

    # 回転平面を定義する
    origin_point = center_point
    x_point = point1
    y_point = select_point

    new_plane = rs.PlaneFromPoints(origin_point, x_point, y_point)
    rs.ViewCPlane(None, new_plane)

    rotate_p = origin_point

    vec1 = rs.VectorCreate(x_point, rotate_p)
    vec2 = rs.VectorCreate(y_point, rotate_p)

    cross = rs.VectorCrossProduct(vec1, vec2)
    cross_unit = rs.VectorUnitize(cross)
    rotate_vec = rs.VectorScale(
        cross_unit, 100)  # Message: Could not convert None to a Vector3d

    # 描画
    # new_rotate_axis = AddVector(center_point, rotate_vector)
    # rotate_axis = AddVector(rotate_p, rotate_vec)
    # rs.AddPoint(point1)
    # rs.AddPoint(point2)
    # rs.AddPoint(center_point)

    # object削除
    rs.DeleteObject(line1)
    rs.DeleteObject(line2)
    for i in range(0, len(curveOnsurface1)):
        rs.DeleteObject(curveOnsurface1[i])
    for i in range(0, len(curveOnsurface2)):
        rs.DeleteObject(curveOnsurface2[i])

    # 平面をもとのxy平面に戻す
    origin_point = (0, 0, 0)
    x_point = (100, 0, 0)
    y_point = (0, 100, 0)
    new_plane = rs.PlaneFromPoints(origin_point, x_point, y_point)
    rs.ViewCPlane(None, new_plane)

    # 戻り値(ドリルライン、ドリルベクトル、回転軸、回転軸点)
    return drill_line, drill_vec, rotate_vec, center_point
Exemplo n.º 9
0
def main():

    rectangle = rs.GetObject("Select rectangle to create mortise and tenon from", rs.filter.curve, True, True)

    errorCheck = curveErrorCheck(rectangle)
    if errorCheck == True:
        return

    lines = rs.ExplodeCurves(rectangle)

    errorCheck = lineErrorCheck(lines)
    if errorCheck == True:
        return

    face = rs.GetObject("Select tenon surface", rs.filter.surface, False, True, None, True)

    length = rs.GetReal("Enter tenon length", number=None)
    if length and length != 0:
        x = 0
    else:
        print "Failed....No length was entered"
        return

    depth = rs.GetReal("Enter mortise depth", number=length+0.05)
    if depth and depth != 0:
        x = 0
    else:
        print "Failed....No depth was entered"
        return

    fit = rs.GetReal("Enter mortise fit", number=0.01)

    line1 = rs.AddLine(rs.CurveStartPoint(lines[0]),rs.CurveEndPoint(lines[0]))
    line2 = rs.AddLine(rs.CurveStartPoint(lines[1]),rs.CurveEndPoint(lines[1]))
    line3 = rs.AddLine(rs.CurveStartPoint(lines[2]),rs.CurveEndPoint(lines[2]))
    line4 = rs.AddLine(rs.CurveStartPoint(lines[3]),rs.CurveEndPoint(lines[3]))

    rs.DeleteObjects(lines)
    lines = line1, line2, line3, line4

    if rs.CurveLength(lines[0]) > rs.CurveLength(lines[1]):
        smallside = rs.CurveLength(lines[1])
        longside1 = lines[0]
        longside2 = lines[2]
    else:
        smallside = rs.CurveLength(lines[0])
        longside1 = lines[1]
        longside2 = lines[3]


    filletRadius = smallside/2

    fillet1 = rs.CurveFilletPoints (lines[0], lines[1])
    fillet2 = rs.CurveFilletPoints (lines[1], lines[2])
    fillet3 = rs.CurveFilletPoints (lines[2], lines[3])
    fillet4 = rs.CurveFilletPoints (lines[3], lines[0])

    arc1 = rs.AddFilletCurve(lines[0],lines[1], radius = filletRadius)
    arc2 = rs.AddFilletCurve(lines[1],lines[2], radius = filletRadius)
    arc3 = rs.AddFilletCurve(lines[2],lines[3], radius = filletRadius)
    arc4 = rs.AddFilletCurve(lines[3],lines[0], radius = filletRadius)
    arcs = arc1, arc2, arc3, arc4

    arcs = rs.JoinCurves(arcs)

    arcEnd1 = rs.CurveEndPoint(arcs[0])
    arcStart1 = rs.CurveStartPoint(arcs[0])
    arcEnd2 = rs.CurveEndPoint(arcs[1])
    arcStart2 = rs.CurveStartPoint(arcs[1])

    if rs.Distance(arcEnd1, arcEnd2) > rs.Distance(arcEnd1,arcStart2):
        temp = arcEnd2
        arcEnd2 = arcStart2
        arcStart2 = temp

    line1 = rs.AddLine(arcEnd1, arcEnd2)
    line2 = rs.AddLine(arcStart1, arcStart2)

    curves = line1, arcs[0], arcs[1], line2
    tenonOut = rs.JoinCurves(curves)
    tenonSurf = rs.AddPlanarSrf(tenonOut)
    point = rs.SurfacePoints(face)

    param = rs.SurfaceClosestPoint(face, point[0])
    normal = rs.SurfaceNormal(face, param)
    normal = normal * length
    vect = rs.AddLine( arcEnd1, arcEnd1 + normal )

    tenon = rs.ExtrudeSurface(tenonSurf, vect, cap=True)

    rs.DeleteObjects(curves)
    arcs = arc1, arc2, arc3, arc4
    rs.DeleteObjects(arcs)
    rs.DeleteObject(rectangle)


    rs.ExtendCurveLength(longside1, 0, 0, fit)
    rs.ExtendCurveLength(longside1, 0, 1, fit)
    rs.ExtendCurveLength(longside2, 0, 0, fit)
    rs.ExtendCurveLength(longside2, 0, 1, fit)

    if rs.Distance(rs.CurveEndPoint(longside1), rs.CurveEndPoint(longside2)) < rs.Distance(rs.CurveStartPoint(longside1), rs.CurveEndPoint(longside2)):
        line1Start = rs.CurveEndPoint(longside1)
        line1End = rs.CurveEndPoint(longside2)
        line2Start = rs.CurveStartPoint(longside1)
        line2End = rs.CurveStartPoint(longside2)
    else:
        line1Start = rs.CurveStartPoint(longside1)
        line1End = rs.CurveEndPoint(longside2)
        line2Start = rs.CurveEndPoint(longside1)
        line2End = rs.CurveStartPoint(longside2)

    shortside1 = rs.AddLine(line1Start, line1End)
    shortside2 = rs.AddLine(line2Start, line2End)

    arc1 = rs.AddFilletCurve(longside1, shortside1, radius = filletRadius)
    arc2 = rs.AddFilletCurve(shortside1, longside2, radius = filletRadius)
    arc3 = rs.AddFilletCurve(longside2, shortside2, radius = filletRadius)
    arc4 = rs.AddFilletCurve(shortside2, longside1, radius = filletRadius)
    arcs = arc1, arc2, arc3, arc4

    arcs = rs.JoinCurves(arcs)

    arcEnd1 = rs.CurveEndPoint(arcs[0])
    arcStart1 = rs.CurveStartPoint(arcs[0])
    arcEnd2 = rs.CurveEndPoint(arcs[1])
    arcStart2 = rs.CurveStartPoint(arcs[1])

    if rs.Distance(arcEnd1, arcEnd2) > rs.Distance(arcEnd1,arcStart2):
        temp = arcEnd2
        arcEnd2 = arcStart2
        arcStart2 = temp

    line1 = rs.AddLine(arcEnd1, arcEnd2)
    line2 = rs.AddLine(arcStart1, arcStart2)

    curves = line1, arcs[0], arcs[1], line2
    mortiseOut = rs.JoinCurves(curves)
    mortiseSurf = rs.AddPlanarSrf(mortiseOut)

    param = rs.SurfaceClosestPoint(face, point[0])
    normal = rs.SurfaceNormal(face, param)
    normal = normal * depth
    vect = rs.AddLine( arcEnd1, arcEnd1 + normal )

    mortise = rs.ExtrudeSurface(mortiseSurf, vect, cap=True)

    rs.DeleteObject(shortside1)
    rs.DeleteObject(shortside2)
    rs.DeleteObject(mortiseOut)
    rs.DeleteObject(mortiseSurf)
    rs.DeleteObjects(curves)
    rs.DeleteObjects(lines)
    arcs = arc1, arc2, arc3, arc4
    rs.DeleteObjects(arcs)
    rs.DeleteObject(rectangle)
    rs.DeleteObject(tenonOut)
    rs.DeleteObject(tenonSurf)

    mortiseSide = rs.GetObject("Select part to mortise", rs.filter.polysurface, False, False)
    tenonSide = rs.GetObject("Select part to tenon", rs.filter.polysurface, False, False)
    tenonUnion = tenonSide, tenon
    rs.BooleanDifference(mortiseSide, mortise, delete_input = True)
    rs.BooleanUnion(tenonUnion, delete_input = True)

    return
Exemplo n.º 10
0
def create_bone(point, curve, length, width, radius, extend):

    if not extend: extend = 0.001
    curve_surface = rs.AddPlanarSrf(curve)
    if not curve_surface:
        exp_curves = rs.ExplodeCurves(curve)
        curve_surface = rs.AddEdgeSrf(exp_curves)
        rs.DeleteObjects(exp_curves)
        print("Surface problem")


#         circle = rs.AddCircle(rs.CurveAreaCentroid(curve)[0],10000)
#         planar_surface = rs.AddPlanarSrf(circle)
#         projected_curve = rs.ProjectCurveToSurface(curve,planar_surface,(0,0,-1))
#         if not projected_curve: rs.ProjectCurveToSurface(curve,planar_surface,(0,0,1))
#         if not projected_curve: print "noooooo"
#         curve_surface = rs.AddPlanarSrf(projected_curve)
#         rs.DeleteObjects([circle,planar_surface,curve])
#         curve = rs.JoinCurves(rs.DuplicateEdgeCurves(curve_surface, select=False))
#         if not curve_surface: print "WARNING"

    main_point_param = rs.CurveClosestPoint(curve, point)
    curve_normal = rs.CurveNormal(curve)
    curve_plane = rs.CurvePlane(curve)
    tangent = rs.CurveTangent(curve, main_point_param)
    center_curve = rs.AddLine((0, 0, 0), rs.VectorScale(tangent, length))
    rs.RotateObject(center_curve, (0, 0, 0), 90, curve_normal)
    rs.MoveObject(center_curve, rs.VectorCreate(point, (0, 0, 0)))
    if not rs.IsPointOnSurface(curve_surface, rs.CurveEndPoint(center_curve)):
        rs.RotateObject(center_curve, point, 180, curve_normal)
    normal = rs.VectorScale(tangent, 10000)
    normal_inverted = rs.VectorReverse(normal)
    side_curve = rs.OffsetCurveOnSurface(center_curve, curve_surface,
                                         width / 2)
    if not side_curve:
        side_curve = rs.OffsetCurveOnSurface(center_curve, curve_surface,
                                             -width / 2)
    side_curves = [
        side_curve,
        rs.RotateObject(
            side_curve, rs.CurveMidPoint(center_curve), 180,
            rs.VectorCreate(rs.CurveStartPoint(center_curve),
                            rs.CurveEndPoint(center_curve)), True)
    ]
    #side_curves = [side_curve,rs.MirrorObject(side_curve,rs.CurveStartPoint(center_curve),rs.CurveEndPoint(center_curve), True)]
    #side_curves = [rs.OffsetCurveOnSurface(center_curve,curve_surface, width/2),rs.OffsetCurveOnSurface(center_curve,curve_surface, -width/2)]
    for side_curve in side_curves:
        rs.ExtendCurveLength(side_curve, 0, 0, 2)
        rs.ObjectColor(side_curve, (255, 0, 0))
    perimeter_curve = rs.AddCurve([
        rs.CurveStartPoint(side_curves[0]),
        rs.CurveEndPoint(side_curves[0]),
        rs.CurveEndPoint(side_curves[1]),
        rs.CurveStartPoint(side_curves[1]),
        rs.CurveStartPoint(side_curves[0])
    ], 1)
    inside_curve = rs.OffsetCurve(perimeter_curve,
                                  rs.CurveAreaCentroid(perimeter_curve)[0],
                                  radius * .7)
    external_curve = rs.OffsetCurve(perimeter_curve,
                                    rs.CurveAreaCentroid(perimeter_curve)[0],
                                    -extend)

    e_points = [
        rs.CurvePoints(external_curve)[0],
        rs.CurvePoints(external_curve)[3]
    ]
    e_perimeter_curve = rs.AddCurve([
        rs.CurveEndPoint(side_curves[1]),
        rs.CurveEndPoint(side_curves[0]), e_points[0], e_points[1],
        rs.CurveEndPoint(side_curves[1])
    ], 1)

    center_plane_a = rs.PlaneFromPoints(
        rs.CurvePoints(inside_curve)[2],
        rs.CurvePoints(inside_curve)[1],
        rs.CurvePoints(inside_curve)[3])
    center_plane_b = rs.PlaneFromPoints(
        rs.CurvePoints(inside_curve)[1],
        rs.CurvePoints(inside_curve)[0],
        rs.CurvePoints(inside_curve)[2])

    circles = [
        rs.AddCircle(center_plane_a, radius + RADIUS_TOLERANCE),
        rs.AddCircle(center_plane_b, radius + RADIUS_TOLERANCE)
    ]

    bone_curve = rs.CurveBooleanUnion(
        [e_perimeter_curve] +
        circles) if extend else rs.CurveBooleanUnion([perimeter_curve] +
                                                     circles)
    rs.DeleteObjects([
        inside_curve, center_curve, perimeter_curve, curve_surface,
        e_perimeter_curve, external_curve
    ] + side_curves + circles)
    return bone_curve
Exemplo n.º 11
0
def get_outer_box(bb_dims, tol, T_IBOX, T_OBOX, TOL_INSIDE, ORIGIN_OB):
    """input:
		bbdims float(w,l,h). l is longest dimension.
		tol float: percentage "give" to have
		T_IBOX: thickness in mm
		T_OBOX: thickness in mm
		TOL_INSIDE: additional absolute tolerance added to the inner dimension of the box
		ORIGIN_OB: origin point for placing the curves
		return: 
		br: list of four points representing the bounding rectangle of the output.
		"""

    W = (1 + tol) * bb_dims[0] + T_IBOX * 2 + T_OBOX * 2 + TOL_INSIDE * 2
    L = (1 + tol) * bb_dims[1] + T_IBOX * 2 + T_OBOX * 2 + TOL_INSIDE * 2
    H = (1 + tol) * bb_dims[2] + T_IBOX * 2 + T_OBOX * 1 + TOL_INSIDE * 1

    dy = ORIGIN_OB[1]  #amount to move everything up by

    n_joins_W = get_num_joins(W, J_LEN)
    n_joins_L = get_num_joins(L, J_LEN)
    n_joins_H = get_num_joins(H, J_LEN)

    #get bounding rectangles for each geometry. placeholder; this won't all be necessary
    bottom = rs.AddRectangle(ORIGIN_OB, L, W)
    top = rs.AddRectangle([0, W + LCUT_GAP + dy, 0], L, W)
    short_a = rs.AddRectangle([L + LCUT_GAP, dy, 0], W, H)
    short_b = rs.AddRectangle([L + LCUT_GAP, H + LCUT_GAP + dy, 0], W, H)
    long_a = rs.AddRectangle([L + W + LCUT_GAP * 2, dy, 0], L, H)
    long_b = rs.AddRectangle([L + W + LCUT_GAP * 2, H + LCUT_GAP + dy, 0], L,
                             H)

    tickmarks = add_tickmarks(top, TICK_DIST,
                              T_OBOX + T_IBOX + TOL_LID_ABSOLUTE)
    grip_data = make_slots(bb_dims[0], bb_dims[1])

    desired_grip_gap = 130
    if bb_dims[1] > desired_grip_gap * 1.4:
        slots = add_slots(top, grip_data, desired_grip_gap)
    else:
        slots = add_slots(top, grip_data, bb_dims[1] / 20)

    rs.ObjectLayer(slots, LCUT_NAMES[1])

    #turn sides into finger joins
    sides_b = rs.ExplodeCurves(bottom)
    jb_0 = make_join(sides_b[0], n_joins_L, 0, T_OBOX, True, True)
    jb_2 = make_join(sides_b[2], n_joins_L, 0, -T_OBOX, True, True)
    jb_1 = make_join(sides_b[1], n_joins_W, -T_OBOX, 0, True, True)
    jb_3 = make_join(sides_b[3], n_joins_W, T_OBOX, 0, True, True)

    sides_s = rs.ExplodeCurves(short_a)
    js_0 = make_join(sides_s[0], n_joins_W, 0, T_OBOX, False, False)
    js_2 = rs.CopyObject(sides_s[2])
    js_1 = make_join(sides_s[1], n_joins_H, -T_OBOX, 0, False, False)
    js_3 = make_join(sides_s[3], n_joins_H, T_OBOX, 0, False, False)

    sides_l = rs.ExplodeCurves(long_a)
    jl_0 = make_join(sides_l[0], n_joins_L, 0, T_OBOX, False, True)
    jl_2 = rs.ExtendCurveLength(rs.CopyObject(sides_l[2]), 0, 2, -T_OBOX)
    jl_1 = make_join(sides_l[1], n_joins_H, -T_OBOX, 0, True, False)
    jl_3 = make_join(sides_l[3], n_joins_H, T_OBOX, 0, True, False)

    sb, ss, sl = rs.JoinCurves([jb_0, jb_1, jb_2, jb_3], True), rs.JoinCurves(
        [js_0, js_1, js_2, js_3],
        True), rs.JoinCurves([jl_0, jl_1, jl_2, jl_3], True)

    final_crvs = sb + ss + sl + [top]
    rs.ObjectLayer(sb + ss + sl + [top], LCUT_NAMES[1])
    final_crvs.extend(rs.CopyObjects(ss, [0, H + LCUT_GAP, 0]))
    final_crvs.extend(rs.CopyObjects(sl, [0, H + LCUT_GAP, 0]))

    centerpt, _ = rs.CurveAreaCentroid(short_a)
    add_logo(centerpt, W, H)

    all_geo = [bottom, top, short_a, short_b, long_a, long_b]
    br = rs.BoundingBox(all_geo)[:4]

    rs.DeleteObjects(sides_b + sides_s + sides_l)
    rs.DeleteObjects([bottom, short_a, short_b, long_a, long_b])

    SELECT_GUIDS.extend(final_crvs)
    SELECT_GUIDS.extend(slots)
    SELECT_GUIDS.extend(tickmarks)
    return br