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 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 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 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 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 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 isCurveNew(self, offsets, curve): if offsets: for offset in offsets: if rs.Distance(rs.CurveStartPoint(offset), rs.CurveStartPoint(curve)) == 0: return False return True
def CheckRunLengths(runs): lengthComment = '' for i, run in enumerate(runs): dist = rs.Distance(rs.CurveStartPoint(run[0]), rs.CurveStartPoint(run[1])) if dist > 360: lengthComment += 'Run {} requires a landing\n'.format(i + 1) templine = rs.AddLine(rs.CurveStartPoint(run[0]), rs.CurveStartPoint(run[1])) mdPt = rs.CurveMidPoint(templine) vec = rs.VectorCreate(mdPt, rs.CurveStartPoint(run[0])) landingCenter = rs.CopyObject(run[0], vec) vec = rs.VectorScale(rs.VectorUnitize(vec), 30) upperLine = rs.CopyObject(landingCenter, vec) vec = rs.VectorReverse(vec) lowerLine = rs.MoveObject(landingCenter, vec) rs.DeleteObject(templine) run.insert(1, lowerLine) run.insert(2, upperLine) flatList = [] for item in runs: for each in item: flatList.append(each) pairs = [] for i in range(0, len(flatList), 2): pairs.append([flatList[i], flatList[i + 1]]) return pairs, lengthComment
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 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 Cremona2(no, nomes, Linhas, countPF, dicPF): ptos1 = [] dicUp = {} for i in range(countPF): if i == 0: Spt = dicPF[nomes[i]].PointAt(0) Ept = dicPF[nomes[i]].PointAt(1) else: if i == 1: cond1 = rs.PointCompare(dicPF[nomes[i - 1]].PointAt(0), dicPF[nomes[i]].PointAt(1), Tol) cond2 = rs.PointCompare(dicPF[nomes[i - 1]].PointAt(0), dicPF[nomes[i]].PointAt(0), Tol) if cond1 or cond2: pAux3 = Spt Spt = Ept Ept = pAux3 if rs.PointCompare(Ept, dicPF[nomes[i]].PointAt(1), Tol): ptAux1 = dicPF[nomes[i]].PointAt(1) ptAux2 = dicPF[nomes[i]].PointAt(0) else: ptAux1 = dicPF[nomes[i]].PointAt(0) ptAux2 = dicPF[nomes[i]].PointAt(1) Ept += (ptAux2 - ptAux1) vAux1 = Line(rs.CurveStartPoint(Linhas[-2]), Ept) vAux2 = Line(rs.CurveStartPoint(Linhas[-1]), Spt) F1 = gh.Move(rs.coerceline(Linhas[-2]), vAux1)[0] F2 = gh.Move(rs.coerceline(Linhas[-1]), vAux2)[0] inter = gh.LineXLine(F1, F2)[2] F1 = rs.AddLine(Ept, inter) F2 = rs.AddLine(inter, Spt) dicUp[nomes[-2]] = rs.coerceline(F1) dicUp[nomes[-1]] = rs.coerceline(F2) #-cargas e nomenclatura #teste de tração e compressão sin1 = TraComp(no, F1, rs.coerceline(Linhas[-2]), nomes[-2]) sin2 = TraComp(no, F2, rs.coerceline(Linhas[-1]), nomes[-1]) #valores das cargas carga1 = rs.CurveLength(F1) * sin1 / Escala carga2 = rs.CurveLength(F2) * sin2 / Escala #teste de tensão admissivel cor1 = teste_elemento(nomes[-2], carga1, Linhas[-2]) cor2 = teste_elemento(nomes[-1], carga2, Linhas[-1]) #nomenclatura do FG txt1 = nomes[-2] + ' = ' + str('%.2f' % carga1) txt2 = nomes[-1] + ' = ' + str('%.2f' % carga2) pt1 = rs.coerceline(Linhas[-2]).PointAt(.5) pt2 = rs.coerceline(Linhas[-1]).PointAt(.5) ptos1 += [pt1, txt1, cor1] ptos1 += [pt2, txt2, cor2] #nimenclatura do PF pt1 = rs.coerceline(F1).PointAt(.5) pt2 = rs.coerceline(F2).PointAt(.5) txt1 = nomes[-2] txt2 = nomes[-1] ptos1 += [pt1, txt1, cor1] ptos1 += [pt2, txt2, cor2] return dicUp, ptos1
def testAlign(crv1,crv2): start=rs.CurveStartPoint(crv2) crv1Start=rs.CurveStartPoint(crv1) pts=rs.PolylineVertices(crv1) index=rs.PointArrayClosestPoint(pts,start) crv1Pt=pts[index] if index!=0: return False else: return True
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 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 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 travel(self, startPoint, endPoint, surfaceToProject): travelLine = rs.AddLine(startPoint, endPoint) projectedTravelLine = rs.ProjectCurveToSurface(travelLine, surfaceToProject, (0, 0, 1)) rs.MoveObject(projectedTravelLine, (0, 0, self.gcoder.getLayerHeight())) try: convertedTravelPolyline = rs.ConvertCurveToPolyline( projectedTravelLine) except: print('In Trave, convertCurveToPolyline failed') print(projectedTravelLine) return False travelVertices = rs.CurveEditPoints(convertedTravelPolyline) rs.DeleteObject(convertedTravelPolyline) self.gcoder.addGcode("G92 E0\n") self.gcoder.initEValue() tmpText = "G1 E{0} F{1}\n".format(self.gcoder.getRetractionDistance(), 1800) self.gcoder.addGcode(tmpText) travelLineStartPoint = rs.CurveStartPoint(travelLine) projectedTravelLineStart = rs.CurveStartPoint(projectedTravelLine) projectedTravelLineEnd = rs.CurveEndPoint(projectedTravelLine) if rs.Distance(travelLineStartPoint, projectedTravelLineStart) > rs.Distance( travelLineStartPoint, projectedTravelLineEnd): travelVertices = list(travelVertices) travelVertices.reverse() rs.DeleteObject(travelLine) rs.DeleteObject(projectedTravelLine) for travelVer in travelVertices: tmpText = "G1 X{0} Y{1} Z{2} F{3}\n".format( travelVer[0], travelVer[1], travelVer[2], 3600) self.gcoder.addGcode(tmpText) tmpText = "G1 X{0} Y{1} Z{2} F{3}\n".format(endPoint[0], endPoint[1], endPoint[2], 3600) tmpText += "G1 E0.0 F1800\n" tmpText += "G92 E0\n" self.gcoder.addGcode(tmpText)
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 checkCurveIntegrity(objs): layers = [] selection = [] delete_objs = [] for i, obj in enumerate(objs): if rs.IsCurve(obj): layer_name = rs.ObjectLayer(obj) # check for disconnected endpoints if (re.search('contour', layer_name, re.IGNORECASE) or re.search('Pocket', layer_name, re.IGNORECASE)) and not rs.IsCurveClosed(obj): selection.append(obj) appendLayer(layers, obj) delete_objs.append(rs.AddPoint(rs.CurveStartPoint(obj))) delete_objs.append(rs.AddPoint(rs.CurveEndPoint(obj))) rs.Command("'_printDisplay _state _on _Enter") for i in range(0, 3): temp_circle = rs.AddCircle(rs.WorldXYPlane(), 80.0 * i + 1) rs.MoveObject(temp_circle, rs.CurveStartPoint(obj)) rs.ObjectPrintWidth(temp_circle, 2.0) delete_objs.append(temp_circle) if len(selection) > 0: rs.SelectObjects(selection) rs.ZoomSelected() redraw() # when an object is found on > 0 layers, prompt for proceed if len(layers) > 0: msg = "See selection: curves and contours should always be closed:\n" for layer in layers: msg = msg + "- " + layer + " \n" msg = msg + '\n Do you want to proceed?' rs.DeleteObjects(delete_objs) if rs.MessageBox(msg, 1) != 1: # do not proceed with export return False # else return True
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 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 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 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 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 MakeSimpleSec(dir, nam, num, line, mode, ext): s = time.time() rs.Command("_CPlane " + "_W " + "_T ") rs.Command("_CPlane " + "_I " + ConvertPt(rs.CurveStartPoint(line)) + " " + "_V " + ConvertPt(rs.CurveEndPoint(line)) + " ") rs.Command("_Clippingplane " + "_C " + "0,0,0" + " " + str(1000) + " " + str(1000) + " ") rs.Command("_Plan") rs.Command("_SelAll") rs.Command("_Zoom " + "_S ") rs.Command("_SelNone") if mode == "fast": rs.Command("_SelVisible " + "_Enter") elif mode == "slow": rs.Command("_SelAll") sc.doc = Rhino.RhinoDoc.ActiveDoc select = len(rs.SelectedObjects()) sc.doc = ghdoc print("selected " + str(select) + " objects") if select == 0: print("canceled") else: rs.Command("-_Make2d " + "_D " + "_C " + "_M=はい " + "_Enter") rs.Command("_CPlane " + "_W " + "_T ") if ext == "dwg": rs.Command("-_Export " + dir + nam + "_section_" + str(num) + ".dwg" + " " + "_Enter") else: rs.Command("-_Export " + dir + nam + "_section_" + str(num) + "." + str(ext)) print("exported section") rs.Command("_SelCrv") rs.Command("_SelClippingPlane") rs.Command("_Delete") print("time = " + str(time.time() - s))
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 getAllEndPoints(crvs): arrPoints = [] i = 0 for crv in crvs: arrPoints.append(rs.CurveEndPoint(crv)) arrPoints.append(rs.CurveStartPoint(crv)) return arrPoints
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 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 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()