def bisecNormalAtEnd(crv, compare): print('at end') p0 = rs.CurveEndPoint(crv) n1s = curvePlnrNormalAtEnds(crv) n1 = n1s[1] n2 = None # # rs.AddPoint(p0) # print('p0:',p0) # print('pS:',rs.CurveStartPoint(compare)) # print('pE:',rs.CurveEndPoint(compare)) n2s = curvePlnrNormalAtEnds(compare) if p0 == rs.CurveStartPoint(compare): n2 = n2s[0] print('found startpoint match') elif p0 == rs.CurveEndPoint(compare): n2 = n2s[1] print('found endpoint match') else: return None #rs.AddLine(p0,p0+n2) #rs.AddLine(p0,p0+n1) n = (n1 + n2) / 2 #rs.AddLine(p0,p0+n) return n
def bisecNormalAtStart(crv, compare): tolerance = 0.001 print('at start') p0 = rs.CurveStartPoint(crv) n1s = curvePlnrNormalAtEnds(crv) n1 = n1s[0] n2 = None #rs.AddPoint(p0) print('p0:', p0) print('pS:', rs.CurveStartPoint(compare)) print('pE:', rs.CurveEndPoint(compare)) compStart = rs.CurveStartPoint(compare) compEnd = rs.CurveEndPoint(compare) #rs.AddLine(compStart,compStart+Point3d(0,1,0)) #rs.AddLine(compEnd,compEnd+Point3d(0,1,0)) n2s = curvePlnrNormalAtEnds(compare) if rs.Distance(p0, compStart) < tolerance: n2 = n2s[0] print('found startpoint match') elif rs.Distance(p0, compEnd) < tolerance: n2 = n2s[1] print('found endpoint match') else: print('match not found') return None # rs.AddLine(p0,p0+n2) # rs.AddLine(p0,p0+n1) n = (n1 + n2) / 2 #rs.AddLine(p0,p0+n) return n
def SortCurves(curves, torrent=0.001): """将多条曲线组成的闭合环线,按照首尾相连的顺序重新排列 """ newCurves = [] newCurves.append(curves[0]) crvs = curves[:] del crvs[0] startP0 = rs.CurveStartPoint(newCurves[-1]) for i in range(len(curves) - 1): endP0 = rs.CurveEndPoint(newCurves[-1]) # if (rs.Distance(startP0,endP0)<torrent): # break flag = False for crv in crvs: sp = rs.CurveStartPoint(crv) ep = rs.CurveEndPoint(crv) if (rs.Distance(sp, endP0) < torrent): flag = True crvs.remove(crv) break if (rs.Distance(ep, endP0) < torrent): crvObj = rs.coercerhinoobject(crv).Geometry crvs.remove(crv) crv = ghc.FlipCurve(crvObj)[0] print('flip') flag = True break if not flag: print('erro:出现孤立的线') return None newCurves.append(crv) return newCurves
def mergeCoincidentLines(segments): """ removes coincident, consecutive segments input: List of GUIDs returns: List of GUIDs """ newSegments = [] i = 0 while i < len(segments): if (i < len(segments) - 1): #if coincident, delete both, add new. a = rs.VectorCreate(rs.CurveStartPoint(segments[i]), rs.CurveEndPoint(segments[i])) b = rs.VectorCreate(rs.CurveStartPoint(segments[i + 1]), rs.CurveEndPoint(segments[i + 1])) a = rs.VectorUnitize(a) b = rs.VectorUnitize(b) aAng = rs.VectorAngle(a, b) if (aAng < .00001): newLine = rs.AddLine(rs.CurveStartPoint(segments[i]), rs.CurveEndPoint(segments[i + 1])) rs.DeleteObject(segments[i]) rs.DeleteObject(segments[i + 1]) newSegments.append(newLine) i = i + 2 else: newSegments.append( segments[i]) #if not coincident, add to array i = i + 1 else: newSegments.append(segments[i]) #add last seg to array i = i + 1 return newSegments
def isShareEdge(srf1, srf2): border1 = rs.DuplicateSurfaceBorder(srf1) border2 = rs.DuplicateSurfaceBorder(srf2) edges1 = rs.ExplodeCurves(border1, True) edges2 = rs.ExplodeCurves(border2, True) shareMid = [] threshold = 0.001 flag = False for e1 in edges1: for e2 in edges2: mid1 = rs.CurveMidPoint(e1) mid2 = rs.CurveMidPoint(e2) if rs.Distance(mid1, mid2) < threshold: s1 = rs.CurveStartPoint(e1) s2 = rs.CurveStartPoint(e2) e1 = rs.CurveEndPoint(e1) e2 = rs.CurveEndPoint(e2) if rs.Distance(s1, s1) < threshold: flag = True break if rs.Distance(s1, e1) < threshold: flag = True break rs.DeleteObjects(edges1) rs.DeleteObjects(edges2) return flag
def get_pocket_entry(self, z_level, translation, pocket_list): revised_list = [] last_obj = None for obj in pocket_list: if obj != "sec_plane": revised_list.append(rs.CopyObject(obj, translation)) else: if last_obj != obj: revised_list.append(obj) last_obj = obj pocket_list = revised_list for i in range(0, len(pocket_list)): crv = pocket_list[i] if crv == "sec_plane": #Cambio intermedio pep = rs.CurveEndPoint(pocket_list[i - 1]) try: nsp = rs.CurveStartPoint(pocket_list[i + 1]) except: npt = rs.CurveStartPoint(self.cut_curve) nsp = (npt[0], npt[1], z_level) points = [ rs.CurveEndPoint(pocket_list[i - 1]), (pep[0], pep[1], self.general_input["sec_plane"]), (nsp[0], nsp[1], self.general_input["sec_plane"]), nsp ] travel_line = rs.AddPolyline(points) rs.ObjectColor(travel_line, color_palette["cut"]) pocket_list[i] = travel_line return pocket_list
def finish_pocket_curves(self, crv_list): block_curves = [] for i in range(0, len(crv_list)): if i == 0: pep = rs.CurveEndPoint(self.cut_curve) csp = rs.CurveStartPoint(crv_list[i]) join_line = rs.AddLine(pep, csp) rs.ObjectColor(join_line, color_palette["cut"]) block_curves.append(join_line) crv = crv_list[i] if crv == "sec_plane": block_curves.append(crv) else: try: if i < len(crv_list) and crv_list[i + 1] != "sec_plane": nsp = rs.CurveStartPoint(crv_list[i + 1]) cep = rs.CurveEndPoint(crv_list[i]) join_line = rs.AddLine(cep, nsp) rs.ObjectColor(join_line, color_palette["cut"]) block_curves.append(crv_list[i]) block_curves.append(join_line) else: block_curves.append(crv) except: pass return block_curves
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 createPipe(self, first, mid, last, text): first_fillet = rs.AddFilletCurve(first, mid, 0.25) fillet_points = rs.CurveFilletPoints(first, mid, 0.25) first_circle = rs.AddCircle(fillet_points[2], 0.125) first_cp = rs.CurveClosestPoint(first, fillet_points[0]) first_domain = rs.CurveDomain(first) nfirst = rs.TrimCurve(first, (first_domain[0], first_cp), False) second_cp = rs.CurveClosestPoint(mid, fillet_points[1]) second_domain = rs.CurveDomain(mid) nmid = rs.TrimCurve(mid, (second_cp, second_domain[1]), False) second_fillet = rs.AddFilletCurve(mid, last, 0.25) fillet_points = rs.CurveFilletPoints(mid, last, 0.25) second_circle = rs.AddCircle(fillet_points[2], 0.125) first_cp = rs.CurveClosestPoint(mid, fillet_points[0]) first_domain = rs.CurveDomain(mid) nmid = rs.TrimCurve(nmid, (first_domain[0], first_cp), False) second_cp = rs.CurveClosestPoint(last, fillet_points[1]) second_domain = rs.CurveDomain(last) nlast = rs.TrimCurve(last, (second_cp, second_domain[1]), False) curve = rs.JoinCurves( [nfirst, first_fillet, nmid, second_fillet, nlast]) print curve pipe = rs.AddPipe(curve, 0, 0.09375, 0, 1) points = [ rs.CurveStartPoint(first), rs.CurveEndPoint(first), rs.CurveStartPoint(last), rs.CurveEndPoint(last) ] self.copyAndMover(first, mid, last, points, text)
def Sierpinsky_triangle(triangle): if rs.CurveLength(triangle[0]) < smallestCurve: return else: #make left triangle line1 = rs.AddLine(rs.CurveStartPoint(triangle[0]), rs.CurveMidPoint(triangle[0])) line2 = rs.AddLine(rs.CurveMidPoint(triangle[0]), rs.CurveMidPoint(triangle[2])) line3 = rs.AddLine(rs.CurveMidPoint(triangle[2]), rs.CurveStartPoint(triangle[0])) #make right triangle line4 = rs.AddLine(rs.CurveMidPoint(triangle[0]), rs.CurveEndPoint(triangle[0])) line5 = rs.AddLine(rs.CurveEndPoint(triangle[0]), rs.CurveMidPoint(triangle[1])) line6 = rs.AddLine(rs.CurveMidPoint(triangle[1]), rs.CurveMidPoint(triangle[0])) #make top triangle line7 = rs.AddLine(rs.CurveMidPoint(triangle[2]), rs.CurveMidPoint(triangle[1])) line8 = rs.AddLine(rs.CurveMidPoint(triangle[1]), rs.CurveEndPoint(triangle[1])) line9 = rs.AddLine(rs.CurveStartPoint(triangle[2]), rs.CurveMidPoint(triangle[2])) #recurse Sierpinsky_triangle([line1, line2, line3]) Sierpinsky_triangle([line4, line5, line6]) Sierpinsky_triangle([line7, line8, line9])
def get_ref_pts(ref_obj, srf_num, indexes): obj_copy = rs.CopyObject(ref_obj) all_srf = rs.ExplodePolysurfaces(obj_copy) ref_srf = rs.DuplicateSurfaceBorder(all_srf[srf_num]) ref_lines = rs.ExplodeCurves(ref_srf) ref_points = [ rs.CurveEndPoint(ref_lines[indexes[0]]), rs.CurveEndPoint(ref_lines[indexes[1]]), rs.CurveEndPoint(ref_lines[indexes[2]]) ] return ref_points
def close_curve(): curve_a = curves[0] curve_b = curves[1] points_a = [rs.CurveStartPoint(curve_a), rs.CurveEndPoint(curve_a)] points_b = [rs.CurveStartPoint(curve_b), rs.CurveEndPoint(curve_b)] for test_point in points_a: closest_point = rs.PointArrayClosestPoint(points_b, test_point) curves.append(rs.AddLine(test_point, points_b[closest_point])) points_b.pop(closest_point) rs.JoinCurves(curves, True) print "Curves closed"
def get_line_coordinates(guids): if isinstance(guids, System.Guid): sp = map(float, rs.CurveStartPoint(guids)) ep = map(float, rs.CurveEndPoint(guids)) return sp, ep lines = [] for guid in guids: sp = map(float, rs.CurveStartPoint(guid)) ep = map(float, rs.CurveEndPoint(guid)) lines.append((sp, ep)) return lines
def offset(): curves = [curve] offset_curve = rs.OffsetCurve(curve, dir, dist) curves.append(offset_curve) curves.append( rs.AddLine(rs.CurveEndPoint(offset_curve), rs.CurveEndPoint(curve))) curves.append( rs.AddLine(rs.CurveStartPoint(offset_curve), rs.CurveStartPoint(curve))) rs.JoinCurves(curves, True) print "Offset created."
def addExtlHandrail(self): hdrlPtList = [] hdrlEndPt = rs.AddPoint(rs.CurveEndPoint(self.guideCrv)) hdrlStPt = rs.AddPoint(rs.CurveStartPoint(self.guideCrv)) hdrlVec = rs.VectorCreate(hdrlStPt, hdrlEndPt) projHdrlVec = rs.VectorUnitize([hdrlVec.X, hdrlVec.Y, 0]) #Top Extension topExtEndPt = rs.CopyObject(hdrlEndPt) rs.MoveObject(topExtEndPt, rs.VectorScale(projHdrlVec, -.305)) hdrlPtList.append(topExtEndPt) #Btm Extension (tread length method) btmExtEndPt = rs.CopyObject(hdrlStPt) btmPtExtTemp = rs.CopyObject(hdrlStPt) btmVertPtExtTemp = rs.CopyObject(hdrlStPt) rs.MoveObject(btmPtExtTemp, hdrlVec) angledLineTemp = rs.AddLine(hdrlStPt, btmPtExtTemp) rs.MoveObject(btmVertPtExtTemp, [0, 0, -1]) vertLineTemp = rs.AddLine(btmVertPtExtTemp, hdrlStPt) rs.MoveObject(vertLineTemp, rs.VectorScale(projHdrlVec, self.treadLength)) btmExtPt = rs.LineLineIntersection(angledLineTemp, vertLineTemp)[0] hdrlPtList.append(hdrlEndPt) hdrlPtList.append(btmExtPt) #Make and move hdrlCrv = rs.AddPolyline(hdrlPtList) rs.MoveObject(hdrlCrv, [0, 0, self.hdrlHeight]) #move away from wall widthVec = rs.VectorUnitize( rs.VectorCreate(rs.CurveEndPoint(self.stairWidthEdge), rs.CurveStartPoint(self.stairWidthEdge))) rs.MoveObject(hdrlCrv, rs.VectorScale(widthVec, self.hdrlDistFromWall)) #cleanup rs.DeleteObject(topExtEndPt) rs.DeleteObject(hdrlEndPt) rs.DeleteObject(hdrlStPt) rs.DeleteObject(btmPtExtTemp) rs.DeleteObject(btmVertPtExtTemp) rs.DeleteObject(angledLineTemp) rs.DeleteObject(vertLineTemp) rs.DeleteObject(btmExtEndPt) return hdrlCrv
def DrawDoubleLines(cls, layer, offsetType): # startPoint gp = Rhino.Input.Custom.GetPoint() gp.SetCommandPrompt("Pick first point") gp.Get() if gp.CommandResult() != Rhino.Commands.Result.Success: return gp.CommandResult() point1 = gp.Point() gp.Dispose() # secondPoint line00 = None line01 = None oldLayer = rs.CurrentLayer(layer) while True: gp = Rhino.Input.Custom.GetPoint() gp.SetCommandPrompt("Pick second point") gp.DrawLineFromPoint(point1, True) gp.EnableDrawLineFromPoint(True) gp.Get() if gp.CommandResult() != Rhino.Commands.Result.Success: rs.CurrentLayer(oldLayer) return gp.CommandResult() point2 = gp.Point() if point2: doubleLine = cls.MakeDoubleLine(config.DOUBLELINEWIDTH, point1, point2, offsetType) if (line00 != None) and (line01 != None): line10, line11 = doubleLine.draw() p0 = rs.LineLineIntersection(line00, line10) p1 = rs.LineLineIntersection(line01, line11) rs.AddLine(rs.CurveStartPoint(line00), p0[0]) rs.AddLine(rs.CurveStartPoint(line01), p1[0]) rs.DeleteObject(line00) rs.DeleteObject(line01) line00 = rs.AddLine(p0[1], rs.CurveEndPoint(line10)) line01 = rs.AddLine(p1[1], rs.CurveEndPoint(line11)) rs.DeleteObject(line10) rs.DeleteObject(line11) else: line00, line01 = doubleLine.draw() point1 = point2 else: sc.errorhandler() break gp.Dispose() rs.CurrentLayer(oldLayer)
def depressCrvs(crvs, paths, startPt, radius, sd): newCrvs = [] for i in range(len(crvs)): divPts = rs.DivideCurve(crvs[i], 100) if i < len(crvs) - 1: cntPt01 = centerCrv(crvs[i]) cntPt02 = centerCrv(crvs[i + 1]) horVec = rs.VectorCreate(cntPt01, cntPt02) for j in range(len(divPts)): path = rs.PointClosestObject(divPts[j], paths)[0] param = rs.CurveClosestPoint(path, divPts[j]) close = rs.EvaluateCurve(path, param) dist = rs.Distance(close, divPts[j]) tan = rs.CurveTangent(crvs[i], param) vec = [0, 0, -1] #rs.VectorCrossProduct(horVec,tan) testVec = rs.VectorCreate(cntPt01, divPts[j]) if rs.VectorDotProduct(vec, testVec) < 0: rs.VectorReverse(vec) vec = rs.VectorUnitize(vec) border = 1 entry = 1 if j > len(divPts) / 2: border = rs.Distance(rs.CurveEndPoint(crvs[i]), divPts[j]) else: border = rs.Distance(rs.CurveStartPoint(crvs[i]), divPts[j]) if border < sd * 3: border = border / (sd * 3) entryDist = rs.Distance(startPt, divPts[j]) if entryDist < sd * 10: entry = entryDist / (sd * 10) if dist < sd * 2: val = radius * (bellCrv(dist, sd)) divPts[j] = rs.PointAdd(divPts[j], vec * val * border * entry) newCrvs.append(rs.AddCurve(divPts)) return divPts
def getAllEndPoints(crvs): arrPoints = [] i = 0 for crv in crvs: arrPoints.append(rs.CurveEndPoint(crv)) arrPoints.append(rs.CurveStartPoint(crv)) return arrPoints
def isVertical(crv,tolerance=0.0001): start=rs.CurveStartPoint(c) end=rs.CurveEndPoint(c) # if abs(start[2]-end[2])<tolerance: hor_crvs.append(c) if abs(start[1]-end[1])<tolerance and abs(start[0]-end[0])<tolerance: return True return False
def crackpolygon(pls, count): temppls = pls pls = [] if count == 0: return 1 else: for pl in temppls: if rs.CloseCurve(pl) == False: print "Not a closed curve" 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)
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 export_curdatapoints(): object_id = rs.GetObject("Select curve", rs.filter.curve) if( object_id==None ): return #Get the filename to create filter = "Text File (*.shf)|*.shf|All Files (*.*)|*.*||" filename = rs.SaveFileName("Save point coordinates as", filter) if( filename==None ): return if rs.IsCurveClosed(object_id): start_point = rs.GetPoint("Base point of center line") end_point = rs.GetPoint("Endpoint of center line", start_point) points = rs.CurveContourPoints(object_id, start_point, end_point) else: points = rs.CurveContourPoints(object_id,rs.CurveStartPoint(object_id),rs.CurveEndPoint(object_id)) if not points: return file = open( filename, "w" ) for pt in points: print(str(pt.X)+","+str(pt.Y)+","+str(pt.Z)) file.write( str(pt.X) ) file.write( ", " ) file.write( str(pt.Y) ) file.write( ", " ) file.write( str(pt.Z) ) file.write( "\n" ) file.close()
def add_sharp_edges(polys, points, sharp_edges): fixed_nodes = [] if sharp_edges: for edge in sharp_edges: pt1, pt2 = rs.CurveStartPoint(edge), rs.CurveEndPoint(edge) index1 = str(rs.PointArrayClosestPoint(points, pt1)) index2 = str(rs.PointArrayClosestPoint(points, pt2)) flag1 = False flag2 = False for key in polys: indices = polys[key]['indices'] for i, index in enumerate(indices): if index == index1: if flag1: #rs.AddTextDot(index,points[int(index)]) points.append(points[int(index)]) indices[i] = str(len(points) - 1) flag1 = True if index == index2: if flag2: #rs.AddTextDot(index,points[int(index)]) points.append(points[int(index)]) indices[i] = str(len(points) - 1) flag2 = True polys[key]['indices'] = indices return polys, points
def connectEndpoints(crvs): points = getAllEndPoints(crvs) for crv in crvs: point = rs.CurveEndPoint(crv) connectClosestPoint(point, points) point = rs.CurveStartPoint(crv) connectClosestPoint(point, points)
def writeArc(curve): normal = rs.CurveTangent(curve, 0) # get curvepoints startpt = rs.CurveStartPoint(curve) endpt = rs.CurveEndPoint(curve) midpt = rs.ArcCenterPoint(curve) # calc G2/G3 parameters x = endpt.X y = endpt.Y i = -startpt.X + midpt.X j = -startpt.Y + midpt.Y # make a distinction between positive and negative direction if ((normal[1] > 0) and (startpt.X > midpt.X)) or ( (normal[1] < 0) and (startpt.X < midpt.X) or (normal[1] == 0 and (normal[0] == 1 or normal[0] == -1) and startpt.X == midpt.X)): file.write("G03 X%0.4f" % x + " Y%0.4f" % y + " I%0.4f" % i + " J%0.4f" % j + "\n") else: file.write("G02 X%0.4f" % x + " Y%0.4f" % y + " I%0.4f" % i + " J%0.4f" % j + "\n")
def divideSrfToPattern(srf, facadeType): top, bot, verts = getSrfTopBotVertCrvs(srf) if bot is None: print('bot is None exit') return None if not rs.IsCurve(bot): print('bot is not Curve exit') return None if len(verts) < 1: print('len(verts)<1') return None if not rs.IsCurve(verts[0]): print('verts[0] is not a curve') return None p0 = rs.CurveStartPoint(verts[0]) p1 = rs.CurveEndPoint(verts[0]) if p1[2] > p0[2]: vect = p1 - p0 else: vect = p0 - p1 print(vect) rs.EnableRedraw(False) m = meshExtrudeCrvToPattern(bot, facadeType, vect) rs.DeleteObjects([top, bot]) rs.DeleteObjects(verts) rs.EnableRedraw(True) return m
def SillHeight(): # Find mid point of sill line midpointSill = rs.CurveMidPoint(window_sillLine[1]) #midpointSill = rs.AddPoint(midpointSill) # Find closest point in curve parameterSill = rs.CurveClosestPoint(window_sillLine[1], midpointSill) # Find curve Tangent sill_Tangent = rs.CurveTangent(window_sillLine[1], parameterSill) # find normal plane sill_plane = rs.PlaneFromNormal(midpointSill, sill_Tangent) # find start and end points of ground line points_gl = [] start_gl = rs.CurveStartPoint(groundLine[1]) end_gl = rs.CurveEndPoint(groundLine[1]) points_gl.append(start_gl) points_gl.append(end_gl) #find point on ground line pointGroundLine = rs.LinePlaneIntersection(points_gl, sill_plane) #pointGroundLine = rs.AddPoint(pointGroundLine) sill_Height = rs.Distance(midpointSill, pointGroundLine) return sill_Height
def depressCrvs(srf, crvs, paths, startPt, radius, sd): newCrvs = [] for i in range(len(crvs)): divPts = rs.DivideCurve(crvs[i], 400) for j in range(len(divPts)): path = rs.PointClosestObject(divPts[j], paths)[0] param = rs.CurveClosestPoint(path, divPts[j]) close = rs.EvaluateCurve(path, param) srfParam = rs.SurfaceClosestPoint(srf, close) vec = rs.SurfaceNormal(srf, srfParam) dist = rs.Distance(close, divPts[j]) vec = rs.VectorUnitize(vec) border = 1 entry = 1 if j > len(divPts) / 2: border = rs.Distance(rs.CurveEndPoint(crvs[i]), divPts[j]) else: border = rs.Distance(rs.CurveStartPoint(crvs[i]), divPts[j]) if border < sd * 3: border = border / (sd * 3) else: border = 1 entryDist = rs.Distance(startPt, divPts[j]) if entryDist < sd * 10: entry = entryDist / (sd * 10) else: entry = 1 if dist < sd * 2: val = radius * (bellCrv(dist, sd)) divPts[j] = rs.PointAdd(divPts[j], vec * val * border * entry) newCrvs.append(rs.AddCurve(divPts)) return divPts
def main(): print 'test' objs = rs.GetObjects() vec_x = [10,0,0] # restore viewport Cplane p1 = rs.WorldXYPlane() rs.ViewCPlane(None, p1) for obj in objs: if rs.IsBlockInstance(obj) and rs.BlockInstanceName(strObject): xform1 = rs.BlockInstanceXform(obj) crv = rs.AddCurve([ [0,0,0], [0,300,0] ]) xfrom1_inv = rs.TransformObject( crv, (xform1) ) rs.SelectObject(crv) vec1 = rs.CurveEndPoint(crv) - rs.CurveStartPoint(crv) print vec1, math.degrees(calcAngle(vec1, vec_x)) if __name__ == "__main__": main();
def createAirplane(): #CREATE FUSELAGE rectangleFuselage = rs.AddRectangle(rs.WorldXYPlane(), Fw, Fh) endPointsF = rs.PolylineVertices(rectangleFuselage) fPtsB = offsetPoints(Fpb, endPointsF[0], endPointsF[1]) fPtsR = offsetPoints(Fpr, endPointsF[1], endPointsF[2]) fPtsT = offsetPoints(Fpt, endPointsF[2], endPointsF[3]) fPtsL = offsetPoints(Fpl, endPointsF[3], endPointsF[0]) fPtsL.append(fPtsB[0]) fCurveOpen = rs.AddCurve(fPtsB + fPtsR + fPtsT + fPtsL, 2) #CREATE WING SLOT wingSlotStart = rs.VectorAdd(endPointsF[0], (Fwx, Fwy, 0)) wingSlotEnd = rs.VectorAdd(wingSlotStart, (Fw - Fwx + maxPointOffset * 2, 0, 0)) wingSlot = rs.AddLine(wingSlotStart, wingSlotEnd) wingSlotOffset = rs.OffsetCurve(wingSlot, (0, 1, 0), 1 / 32) rs.AddLine(rs.CurveStartPoint(wingSlot), rs.CurveStartPoint(wingSlotOffset)) #CREATE WING wPlaneOffY = Wh + 1 wPlaneOffX = Fw / 2 wingPlane = rs.MovePlane(rs.WorldXYPlane(), (wPlaneOffX, -wPlaneOffY, 0)) rectangleWing = rs.AddRectangle(wingPlane, Ww, Wh) endPointsW = rs.PolylineVertices(rectangleWing) wPtsB = offsetPoints(Wpb, endPointsW[0], endPointsW[1]) wPtsR = offsetPoints(Wps, endPointsW[1], endPointsW[2]) wPtsT = offsetPoints(Wpt, endPointsW[2], endPointsW[3]) wPtsT.append(endPointsW[3]) wPtsB.insert(0, endPointsW[0]) wingCurve = rs.AddCurve(wPtsB + wPtsR + wPtsT) #wingLine = rs.AddLine(endPointsW[3],endPointsW[0]) rs.MirrorObject(wingCurve, endPointsW[3], endPointsW[0], True) #CREATE WING GROOVE wingGrooveStart = rs.VectorAdd(endPointsW[3], (-1 / 64, maxPointOffset, 0)) wingGrooveEnd = rs.VectorAdd(wingGrooveStart, (0, -(maxPointOffset + Wh * Wsd), 0)) wingGroove = rs.AddLine(wingGrooveStart, wingGrooveEnd) wingGrooveOffset = rs.OffsetCurve(wingGroove, (1, 0, 0), -1 / 32) rs.AddLine(rs.CurveEndPoint(wingGroove), rs.CurveEndPoint(wingGrooveOffset)) #DELETE RECTANGLES rs.DeleteObject(rectangleFuselage) rs.DeleteObject(rectangleWing)