def meshSwipPolyAlongPoly(profile, rail): profile = rs.CopyObject(profile) pts = rs.CurveEditPoints(rail) baseVect = Rhino.Geometry.Point3d(0, 1, 0) meshes = [] for i in range(0, len(pts) - 2): p0 = pts[i] p1 = pts[i + 1] p2 = pts[i + 2] v1 = rs.VectorUnitize(p1 - p0) v2 = rs.VectorUnitize(p2 - p1) rv1 = rs.VectorUnitize(p0 - p1) vect = p1 - p0 mid = rs.VectorUnitize((rv1 + v2) / 2) np = p1 + mid up = p1 + Rhino.Geometry.Point3d(0, 0, 1) pln = rs.PlaneFromPoints(p1, np, up) mesh, pjpts = meshExtrudePolyToByVectPlane(profile, vect, pln) meshes.append(mesh) rs.DeleteObject(profile) profile = rs.AddPolyline(pjpts) mesh = rs.JoinMeshes(meshes, True) rs.DeleteObject(profile) return mesh
def main(): max_flrs = 9999 # maximum number of folders to open max_fils = 9999 # maximum number of files to open in each folder folder_tic = time.clock() fdr_cnt = 0 for root, dirs, files in walklevel(src_path): print("{}\t {}".format(fdr_cnt, root)) #if (root == src_path): continue fil_cnt = 0 for full_filename in files: filename, file_extension = os.path.splitext(full_filename) if file_extension != ".3dm": continue file_tic = time.clock() filepath = os.path.join(root, full_filename) rs.DocumentModified(False) rs.Command('_-Open {} _Enter'.format('"' + filepath + '"')) pln = rs.PlaneFromPoints((100, 0, 0), (0, 100, 0), (100, 100, 0)) rs.AddRectangle(pln, 100, 100) set_active_view("Origin_SW_ISO") view = rs.CurrentView() set_disp_mode(disp_mode) rs.Redraw() """ rs.ViewProjection(view,2) rs.ViewCameraTarget(view,cam_pos,tar_pos) rs.ViewCameraLens(view,lens_len) rs.ZoomExtents(view) #rs.ViewCameraLens(view,25) """ capture_view_antialias( os.path.join(tar_path, "{}.png".format(filename)), image_size) t = round(time.clock() - file_tic) print(filename + "\ttime:\t" + str(t)) fil_cnt += 1 if fil_cnt > max_fils: break fdr_cnt += 1 if fdr_cnt > max_flrs: break t = round(time.clock() - folder_tic) print("TOTAL\ttime:\t" + str(t))
def planeexample(): origin = rs.GetPoint("Plane origin") if not origin: return ptX = rs.GetPoint("Plane X-axis", origin) if not ptX: return ptY = rs.GetPoint("Plane Y-axis", origin) if not ptY: return x = rs.Distance(origin, ptX) y = rs.Distance(origin, ptY) plane = rs.PlaneFromPoints(origin, ptX, ptY) rs.AddPlaneSurface(plane, 1.0, 1.0) rs.AddPlaneSurface(plane, x, y)
def copyAndMover(self, first, mid, last, points, text): plane = rs.PlaneFromPoints(points[0], points[1], points[2]) uv1 = rs.PlaneClosestPoint(plane, points[1], False) uv2 = rs.PlaneClosestPoint(plane, points[2], False) distHor = abs(uv1[0] - uv2[0]) distVert = abs(uv1[1] - uv2[1]) key = 'len{0}{1}'.format(distHor, distVert) key = re.sub(r'\.', '', key) if key in self.partsHash: self.partsHash[key].append(text) else: self.partsHash[key] = [] self.partsHash[key].append(text) ypos = len(self.partsHash.keys()) + len(self.partsHash.keys()) rs.AddText(key, [0, ypos, 0], 0.3) newPoints = [ rs.AddPoint(0, ypos, 0), rs.AddPoint(self.FLAT_LENGTH, ypos, 0), rs.AddPoint(self.FLAT_LENGTH + distHor, ypos + distVert, 0), rs.AddPoint((self.FLAT_LENGTH * 2) + distHor, ypos + distVert, 0) ] first = rs.OrientObject(first, points, newPoints, 1) mid = rs.OrientObject(mid, points, newPoints, 1) last = rs.OrientObject(last, points, newPoints, 1) first_fillet = rs.AddFilletCurve(first, mid, 0.09375) fillet_points = rs.CurveFilletPoints(first, mid, 0.09375) first_circle = rs.AddCircle(fillet_points[2], 0.09375) first_cp = rs.CurveClosestPoint(first, fillet_points[0]) first_domain = rs.CurveDomain(first) first = rs.TrimCurve(first, (first_domain[0], first_cp), True) second_cp = rs.CurveClosestPoint(mid, fillet_points[1]) second_domain = rs.CurveDomain(mid) mid = rs.TrimCurve(mid, (second_cp, second_domain[1]), True) second_fillet = rs.AddFilletCurve(mid, last, 0.09375) fillet_points = rs.CurveFilletPoints(mid, last, 0.09375) second_circle = rs.AddCircle(fillet_points[2], 0.09375) first_cp = rs.CurveClosestPoint(mid, fillet_points[0]) first_domain = rs.CurveDomain(mid) mid = rs.TrimCurve(mid, (first_domain[0], first_cp), True) second_cp = rs.CurveClosestPoint(last, fillet_points[1]) second_domain = rs.CurveDomain(last) last = rs.TrimCurve(last, (second_cp, second_domain[1]), True) curve = rs.JoinCurves( [first, first_fillet, mid, second_fillet, last]) rs.AddCircle([0, ypos - 0.125 - 0.09375, 0], 0.09375) rs.AddCircle([(self.FLAT_LENGTH * 2) + distHor, ypos + distVert + 0.125 + 0.09375, 0], 0.09375)
def get_brep_plan_cut(brep, cut_height, tolerance): """cut a brep at a certain height. returns list of geometry.polycurve tolerance should be the document tolerance. NOTE: attempts to join the curves.""" bb = rs.BoundingBox(brep) height = rs.Distance(bb[0], bb[4]) #get middle section and get polycurve midplane_pts = rs.MoveObjects(bb[0:4], [0, 0, cut_height]) plane = rs.PlaneFromPoints(bb[0], bb[1], bb[3]) rs.DeleteObjects(midplane_pts) bool_merged = Rhino.Geometry.Brep.MergeCoplanarFaces(brep, tolerance) g = Rhino.Geometry.Intersect.Intersection.BrepPlane(brep, plane, tolerance) g_polycurves = g[1] g_polycurves = Rhino.Geometry.Curve.JoinCurves(g_polycurves, tolerance) return g_polycurves
def CutSect(SurfaceId, SpanStation): # SpanStation is assumed to be along the y direction, in the range [0,1] (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) = ObjectsExtents(SurfaceId) YStation = Ymin + (Ymax - Ymin) * SpanStation OriginX = Xmin - 1 OriginZ = Zmin - 1 CutPlane = rs.PlaneFromPoints((OriginX, YStation, OriginZ), (Xmax + 1, YStation, OriginZ), (OriginX, YStation, Zmax + 1)) CutPlaneSrf = rs.AddPlaneSurface( CutPlane, max([(Xmax - Xmin), (Ymax - Ymin), (Zmax - Zmin)]) + 1, max([(Xmax - Xmin), (Ymax - Ymin), (Zmax - Zmin)]) + 1) I = rs.IntersectBreps(CutPlaneSrf, SurfaceId) Section = I[0] rs.DeleteObject(CutPlaneSrf) (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) = ObjectsExtents(Section) # Find the apparent chord of the section (that is, the line connecting the fore # most and aftmost points on the curve DivPoints = rs.DivideCurve(Section, 200) Xs = [] Ys = [] Zs = [] for DP in DivPoints: list.append(Xs, DP[0]) list.append(Ys, DP[1]) list.append(Zs, DP[2]) val, idx = min((val, idx) for (idx, val) in enumerate(Xs)) LeadingPoint = [Xs[idx], Ys[idx], Zs[idx]] val, idx = max((val, idx) for (idx, val) in enumerate(Xs)) TrailingPoint = [Xs[idx], Ys[idx], Zs[idx]] Chord = rs.AddLine(TrailingPoint, LeadingPoint) return Section, Chord
def initSlice(self, init_geo): result = [] plane = rs.PlaneFromPoints((-5000, -5000, 0), (0, -5000, 0), (-5000, 0, 0)) planeSrf = rs.AddPlaneSurface(plane, 10000, 10000) crv = rs.IntersectBreps(init_geo, planeSrf) result.append(crv) while True: vec = rs.CreateVector((0, 0, self.layer_height)) planeSrf = rs.MoveObject(planeSrf, vec) crv = rs.IntersectBreps(init_geo, planeSrf) if crv == None: break else: result.append(crv) result = rs.JoinCurves(result) for i in range(1, len(result)): if not rs.CurveDirectionsMatch(result[0], result[i]): rs.ReverseCurve(result[i]) return result
def add_cube_w_material(count): for i in xrange(count): for j in xrange(count): ### define pt, plane tmp_pt = rs.AddPoint(i * 2, j * 2, 0) tmp_pln = rs.PlaneFromPoints(tmp_pt, rs.PointAdd(tmp_pt, (1,0,0)), rs.PointAdd(tmp_pt, (0,1,0))) ### define extrude line line_ex = rs.AddLine((0,0,0), (0,0,1)) ### draw rect tmp_crv = rs.AddRectangle(tmp_pln, 1,1) tmp_surf = rs.AddPlanarSrf(tmp_crv) tmp_box = rs.ExtrudeSurface(tmp_surf, line_ex, True) ### set color rs.AddMaterialToObject(tmp_box) index = rs.ObjectMaterialIndex(tmp_box) rs.MaterialName(index, str(i) + "_" +str(j)) rs.MaterialColor(index, ((255 / count) * i, 255 - ((255 / count) * j), 255 - ((255 / count) * j))) # name = rs.MaterialName(index) # print name ### delete rs.DeleteObject(tmp_pt) rs.DeleteObject(tmp_crv) rs.DeleteObject(tmp_surf) rs.DeleteObject(line_ex)
def _BuildFuselageOML(NoseLengthRatio, TailLengthRatio, CylindricalMidSection, SimplificationReqd): MaxFittingAttempts = 6 FittingAttempts = -1 NetworkSrfSettings = [[35, 20, 15, 5, 20], [35, 30, 15, 5, 20], [35, 20, 15, 2, 20], [30, 30, 15, 2, 20], [30, 20, 15, 2, 20], [25, 20, 15, 2, 20], [20, 20, 15, 2, 20], [15, 20, 15, 2, 20]] StarboardCurve, PortCurve, FSVUCurve, FSVLCurve, FSVMeanCurve, NoseEndX, TailStartX, EndX = _FuselageLongitudinalGuideCurves( NoseLengthRatio, TailLengthRatio) while FittingAttempts <= MaxFittingAttempts: FittingAttempts = FittingAttempts + 1 # Construct array of cross section definition frames SX0 = 0 Step01 = NetworkSrfSettings[FittingAttempts][0] SX1 = 0.04 * NoseEndX Step12 = NetworkSrfSettings[FittingAttempts][1] SX2 = SX1 + 0.25 * NoseEndX Step23 = NetworkSrfSettings[FittingAttempts][2] SX3 = NoseEndX Step34 = NetworkSrfSettings[FittingAttempts][3] SX4 = TailStartX Step45 = NetworkSrfSettings[FittingAttempts][4] SX5 = EndX print "Attempting network surface fit with network density setup ", NetworkSrfSettings[ FittingAttempts][:] Stations01 = act.pwfrange(SX0, SX1, max([Step01, 2])) Stations12 = act.pwfrange(SX1, SX2, max([Step12, 2])) Stations23 = act.pwfrange(SX2, SX3, max([Step23, 2])) Stations34 = act.pwfrange(SX3, SX4, max([Step34, 2])) Stations45 = act.pwfrange(SX4, SX5, max([Step45, 2])) StationRange = Stations01[: -1] + Stations12[: -1] + Stations23[: -1] + Stations34[: -1] + Stations45 C = [] FirstTime = True for XStation in StationRange: P = rs.PlaneFromPoints((XStation, 0, 0), (XStation, 1, 0), (XStation, 0, 1)) IP1 = rs.PlaneCurveIntersection(P, StarboardCurve) IP2 = rs.PlaneCurveIntersection(P, FSVUCurve) IP3 = rs.PlaneCurveIntersection(P, PortCurve) IP4 = rs.PlaneCurveIntersection(P, FSVLCurve) IPcentre = rs.PlaneCurveIntersection(P, FSVMeanCurve) IPoint1 = rs.AddPoint(IP1[0][1]) IPoint2 = rs.AddPoint(IP2[0][1]) IPoint3 = rs.AddPoint(IP3[0][1]) IPoint4 = rs.AddPoint(IP4[0][1]) IPointCentre = rs.AddPoint(IPcentre[0][1]) PseudoDiameter = abs(IP4[0][1].Z - IP2[0][1].Z) if CylindricalMidSection and NoseEndX < XStation < TailStartX: # Ensure that the parallel section of the fuselage is cylindrical # if CylindricalMidSection is True print "Enforcing circularity in the central section..." if FirstTime: PseudoRadius = PseudoDiameter / 2 FirstTime = False Pc = rs.PointCoordinates(IPointCentre) P1 = P2 = P3 = Pc P1 = rs.PointAdd(P1, (0, PseudoRadius, 0)) P2 = rs.PointAdd(P2, (0, 0, PseudoRadius)) P3 = rs.PointAdd(P3, (0, -PseudoRadius, 0)) c = rs.AddCircle3Pt(P1, P2, P3) else: c = rs.AddInterpCurve( [IPoint1, IPoint2, IPoint3, IPoint4, IPoint1], knotstyle=3) # Once CSec is implemented in Rhino Python, this could be replaced rs.DeleteObjects( [IPoint1, IPoint2, IPoint3, IPoint4, IPointCentre]) list.append(C, c) # Fit fuselage external surface CurveNet = [] for c in C[1:]: list.append(CurveNet, c) list.append(CurveNet, FSVUCurve) list.append(CurveNet, PortCurve) list.append(CurveNet, FSVLCurve) list.append(CurveNet, StarboardCurve) FuselageOMLSurf = rs.AddNetworkSrf(CurveNet) rs.DeleteObjects(C) if not (FuselageOMLSurf == None): print "Network surface fit succesful on attempt ", FittingAttempts + 1 FittingAttempts = MaxFittingAttempts + 1 # Force an exit from 'while' # If all attempts at fitting a network surface failed, we attempt a Sweep2 if FuselageOMLSurf == None: print "Failed to fit network surface to the external shape of the fuselage" print "Attempting alternative fitting method, quality likely to be low..." try: FuselageOMLSurf = rs.AddSweep2([FSVUCurve, FSVLCurve], C[:]) except: FuselageOMLSurf = False SimplificationReqd = True # Enforce simplification if not (FuselageOMLSurf): print "Alternative fitting method failed too. Out of ideas." if FuselageOMLSurf and SimplificationReqd: rs.UnselectAllObjects() rs.SelectObject(FuselageOMLSurf) ToleranceStr = str(0.0005 * EndX) print "Smoothing..." rs.Command("FitSrf " + ToleranceStr) rs.UnselectAllObjects() # Compute the stern point coordinates of the fuselage Pu = rs.CurveEndPoint(FSVUCurve) Pl = rs.CurveEndPoint(FSVLCurve) SternPoint = [Pu.X, Pu.Y, 0.5 * (Pu.Z + Pl.Z)] rs.DeleteObjects( [FSVUCurve, FSVLCurve, PortCurve, StarboardCurve, FSVMeanCurve]) return FuselageOMLSurf, SternPoint
def SetPlaneOrigin(): plane_origin = rs.PlaneFromPoints((0, 0, 0), (100, 0, 0), (0, 100, 0)) rs.ViewCPlane(None, plane_origin)
def Run(self, PanelBay_List, currentBay, skinInstance): modDistTolerance = self.__m_modifierDistThreshold level = skinInstance.GetProperty("SKIN_CURRENT_CELL_ROW") inLevelIndex = skinInstance.GetProperty("SKIN_CURRENT_CELL_COLUMN") bayIndex = skinInstance.GetProperty("SKIN_CURRENT_BAY_INDEX") ptPanel = skinInstance.GetCellProperty(level, inLevelIndex, "CELL_CORNER_POINTS") defaultBayList = skinInstance.GetProperty("BAY_LIST") # new bay index passed in to this function via currentBay, currentBay is modified by design functions when a panel bay has to be changed. # (bayIndex is the original bay index at this cell location before design functions potentialty changed it). newBayIndex = PanelBay_List.index(currentBay) if self.__m_DataFunction == None: return [PanelBay_List[bayIndex], bayIndex] #check if bayindex should not be changed (bayStayList) if self.__m_filterBayID_List <> []: filterBayList = copy.deepcopy(self.__m_filterBayID_List) for i in range(len(filterBayList)): filterBayList[i] -= 1 #convert to cero based list if newBayIndex not in filterBayList: return [PanelBay_List[newBayIndex], bayIndex] rndVal = self.__m_randomObject.random( ) # 0-1 random base value for algorithm #obtain panel center point to evaluate midDist = rs.VectorScale(rs.VectorCreate(ptPanel[3], ptPanel[0]), .5) centerPoint = rs.PointAdd(ptPanel[0], midDist) #multiple curves can be tested simultaneosly with algorithm dist = 0 flagPanel = False panelWidth = abs(rs.Distance(ptPanel[0], ptPanel[1])) panelHeight = abs(rs.Distance(ptPanel[1], ptPanel[3])) panelPlane = rs.PlaneFromPoints(ptPanel[0], ptPanel[1], ptPanel[2]) #panel bay plane if self.__m_modifierObjects == []: newBayIndex = self.__m_DataFunction.Run( PanelBay_List, [], level, inLevelIndex, defaultBayList, self.__m_randomObject, bayIndex, panelPlane) if newBayIndex >= len(PanelBay_List): self.warningData.append( "Invalid panel bay id value: newBayIndex - default panel id used" ) return [PanelBay_List[bayIndex], bayIndex] return [PanelBay_List[newBayIndex], bayIndex] for obj in self.__m_modifierObjects: #if not rs.IsObject(obj) : print "Invalid modifier object"; continue #look for falloff and bay data stored on curves name (with format: FALLOFF=float, BAY_LIST=integer) datalist = [] objData = obj.GetUserString('Data') dataList = list(objData.rsplit("/")) FALLOFF = self.__m_falloffRadius for data in dataList: if 'FALLOFF' in data: codeObj = compile(data, '<string>', 'single') eval(codeObj) if FALLOFF > -1: # a 0 value will skip the gradient check on current curve #is a curve? if obj.ObjectType == rc.DocObjects.ObjectType.Curve: #if a flat closed curve in same plane as panel catch all points inside if obj.IsClosed and obj.IsPlanar( sc.doc. ModelAbsoluteTolerance) and obj.IsInPlane( panelPlane, sc.doc.ModelAbsoluteTolerance): result = obj.Contains(centerPoint, panelPlane) if result == rc.Geometry.PointContainment.Inside or result == rc.Geometry.PointContainment.Coincident: flagPanel = True if flagPanel == False: paramCurve = 0.0 success, paramCurve = obj.ClosestPoint(centerPoint) closePoint = obj.PointAt(paramCurve) dist = abs((closePoint - centerPoint).Length) if not obj.IsClosed: #open curves flag panels with distance to panel center point <1/2 panel size heightDist = abs( closePoint.Z - centerPoint.Z ) + sc.doc.ModelAbsoluteTolerance widthDist = abs( (closePoint - rc.Geometry.Point3d( centerPoint.X, centerPoint.Y, closePoint.Z) ).Length) + sc.doc.ModelAbsoluteTolerance if heightDist < panelHeight / 2 and widthDist < panelWidth / 2: flagPanel = True #is a surface/polysurface? elif obj.ObjectType == rc.DocObjects.ObjectType.Brep: #get distance of current modifier object to current panel center point closePoint = obj.ClosestPoint(centerPoint) dist = abs((closePoint - centerPoint).Length) if dist < sc.doc.ModelAbsoluteTolerance + modDistTolerance: flagPanel = True # Invalid object, skip else: continue #RANDOMLY SELECT THE BLOCKS BASED ON THEIR PROXIMITY TO THE GRADIENT CENTERPOINT. #dblDist = rs.Distance(rs.EvaluateCurve(obj, rs.CurveClosestPoint(obj, centerPoint)), centerPoint) if flagPanel == False and FALLOFF > 0: if rndVal > dist / FALLOFF: flagPanel = True elif rndVal > dist - FALLOFF / rndVal / 15: flagPanel = True #replace bayindex data for this panel depending on data specified (generic or specifc index) if flagPanel: flagPanel = False PATTERN = [] for data in dataList: if 'PATTERN' in data: codeObj = compile(data, '<string>', 'single') eval(codeObj) newBayIndex = self.__m_DataFunction.Run( PanelBay_List, PATTERN, level, inLevelIndex, defaultBayList, self.__m_randomObject, bayIndex, panelPlane) #check for invalid id values if newBayIndex >= len(PanelBay_List): self.warningData.append( "Invalid panel bay id value: newBayIndex - default panel id used" ) return [PanelBay_List[bayIndex], bayIndex] #return the new panel bay and keep bay index unchanged return [PanelBay_List[newBayIndex], bayIndex]
def transonic_airliner( Propulsion=1, # 1 - twin, 2 - quad EngineDia=2.9, # Diameter of engine intake highlight FuselageScaling=[55.902, 55.902, 55.902], # [x,y,z] scale factors NoseLengthRatio=0.182, # Proportion of forward tapering section of the fuselage TailLengthRatio=0.293, # Proportion of aft tapering section of the fuselage WingScaleFactor=44.56, WingChordFactor=1.0, Topology=1, # Topology = 2 will yield a box wing airliner - use with caution, this is just for demo purposes. SpanStation1=0.31, # Inboard engine at this span station SpanStation2=0.625, # Outboard engine at this span station (ignored if Propulsion=1) EngineCtrBelowLE=0.3558, # Engine below leading edge, normalised by the length of the nacelle - range: [0.35,0.5] EngineCtrFwdOfLE=0.9837, # Engine forward of leading edge, normalised by the length of the nacelle - range: [0.85,1.5] Scarf_deg=3): # Engine scarf angle # Build fuselage geometry rs.EnableRedraw(False) try: FuselageOMLSurf, SternPoint = fuselage_oml.FuselageOML( NoseLengthRatio, TailLengthRatio, Scaling=FuselageScaling, NoseCoordinates=[0, 0, 0], CylindricalMidSection=False, SimplificationReqd=False) except: print "Fuselage fitting failed - stopping." return FuselageHeight = FuselageScaling[2] * 0.105 FuselageLength = FuselageScaling[0] FuselageWidth = FuselageScaling[1] * 0.106 rs.Redraw() if FuselageOMLSurf is None: print "Failed to fit fuselage surface, stopping." return FSurf = rs.CopyObject(FuselageOMLSurf) # Position of the apex of the wing if FuselageHeight < 8.0: WingApex = [0.1748 * FuselageLength, 0, -0.0523 * FuselageHeight] #787:[9.77,0,-0.307] else: WingApex = [0.1748 * FuselageLength, 0, -0.1 * FuselageHeight] #787:[9.77,0,-0.307] # Set up the wing object, including the list of user-defined functions that # describe the spanwise variations of sweep, dihedral, etc. LooseSurf = 1 if Topology == 1: SegmentNo = 10 Wing = liftingsurface.LiftingSurface(WingApex, ta.mySweepAngleFunctionAirliner, ta.myDihedralFunctionAirliner, ta.myTwistFunctionAirliner, ta.myChordFunctionAirliner, ta.myAirfoilFunctionAirliner, LooseSurf, SegmentNo, TipRequired=True) elif Topology == 2: SegmentNo = 101 Wing = liftingsurface.LiftingSurface(WingApex, ta.mySweepAngleFunctionAirliner, bw.myDihedralFunctionBoxWing, ta.myTwistFunctionAirliner, ta.myChordFunctionAirliner, ta.myAirfoilFunctionAirliner, LooseSurf, SegmentNo, TipRequired=True) # Instantiate the wing object and add it to the document rs.EnableRedraw(False) WingSurf, ActualSemiSpan, LSP_area, RootChord, AR, WingTip = Wing.GenerateLiftingSurface( WingChordFactor, WingScaleFactor) rs.Redraw() if Topology == 1: # Add wing to body fairing WTBFXCentre = WingApex[ 0] + RootChord / 2.0 + RootChord * 0.1297 # 787: 23.8 if FuselageHeight < 8.0: WTBFZ = RootChord * 0.009 #787: 0.2 WTBFheight = 0.1212 * RootChord #787:2.7 WTBFwidth = 1.08 * FuselageWidth else: WTBFZ = WingApex[2] + 0.005 * RootChord WTBFheight = 0.09 * RootChord WTBFwidth = 1.15 * FuselageWidth WTBFlength = 1.167 * RootChord #787:26 WTBFXStern = WTBFXCentre + WTBFlength / 2.0 CommS = "_Ellipsoid %3.2f,0,%3.2f %3.2f,0,%3.2f %3.2f,%3.2f,%3.2f %3.2f,0,%3.2f " % ( WTBFXCentre, WTBFZ, WTBFXStern, WTBFZ, 0.5 * (WTBFXCentre + WTBFXStern), 0.5 * WTBFwidth, WTBFZ, 0.5 * (WTBFXCentre + WTBFXStern), WTBFheight) rs.EnableRedraw(False) rs.CurrentView("Perspective") rs.Command(CommS) LO = rs.LastCreatedObjects() WTBF = LO[0] rs.Redraw() # Trim wing inboard section CutCirc = rs.AddCircle3Pt((0, WTBFwidth / 4, -45), (0, WTBFwidth / 4, 45), (90, WTBFwidth / 4, 0)) CutCircDisk = rs.AddPlanarSrf(CutCirc) CutDisk = CutCircDisk[0] rs.ReverseSurface(CutDisk, 1) rs.TrimBrep(WingSurf, CutDisk) elif Topology == 2: # Overlapping wing tips CutCirc = rs.AddCircle3Pt((0, 0, -45), (0, 0, 45), (90, 0, 0)) CutCircDisk = rs.AddPlanarSrf(CutCirc) CutDisk = CutCircDisk[0] rs.ReverseSurface(CutDisk, 1) rs.TrimBrep(WingSurf, CutDisk) # Engine installation (nacelle and pylon) if Propulsion == 1: # Twin, wing mounted SpanStation = SpanStation1 NacelleLength = 1.95 * EngineDia rs.EnableRedraw(False) EngineSection, Chord = act.CutSect(WingSurf, SpanStation) CEP = rs.CurveEndPoint(Chord) EngineStbd, PylonStbd = engine.TurbofanNacelle( EngineSection, Chord, CentreLocation=[ CEP.X - EngineCtrFwdOfLE * NacelleLength, CEP.Y, CEP.Z - EngineCtrBelowLE * NacelleLength ], ScarfAngle=Scarf_deg, HighlightRadius=EngineDia / 2.0, MeanNacelleLength=NacelleLength) rs.Redraw() elif Propulsion == 2: # Quad, wing-mounted NacelleLength = 1.95 * EngineDia rs.EnableRedraw(False) EngineSection, Chord = act.CutSect(WingSurf, SpanStation1) CEP = rs.CurveEndPoint(Chord) EngineStbd1, PylonStbd1 = engine.TurbofanNacelle( EngineSection, Chord, CentreLocation=[ CEP.X - EngineCtrFwdOfLE * NacelleLength, CEP.Y, CEP.Z - EngineCtrBelowLE * NacelleLength ], ScarfAngle=Scarf_deg, HighlightRadius=EngineDia / 2.0, MeanNacelleLength=NacelleLength) rs.DeleteObjects([EngineSection, Chord]) EngineSection, Chord = act.CutSect(WingSurf, SpanStation2) CEP = rs.CurveEndPoint(Chord) EngineStbd2, PylonStbd2 = engine.TurbofanNacelle( EngineSection, Chord, CentreLocation=[ CEP.X - EngineCtrFwdOfLE * NacelleLength, CEP.Y, CEP.Z - EngineCtrBelowLE * NacelleLength ], ScarfAngle=Scarf_deg, HighlightRadius=EngineDia / 2.0, MeanNacelleLength=NacelleLength) rs.Redraw() # Script for generating and positioning the fin rs.EnableRedraw(False) # Position of the apex of the fin P = [0.6524 * FuselageLength, 0.003, FuselageHeight * 0.384] #P = [36.47,0.003,2.254]55.902 RotVec = rs.VectorCreate([1, 0, 0], [0, 0, 0]) LooseSurf = 1 SegmentNo = 200 Fin = liftingsurface.LiftingSurface(P, tail.mySweepAngleFunctionFin, tail.myDihedralFunctionFin, tail.myTwistFunctionFin, tail.myChordFunctionFin, tail.myAirfoilFunctionFin, LooseSurf, SegmentNo) ChordFactor = 1.01 #787:1.01 if Topology == 1: ScaleFactor = WingScaleFactor / 2.032 #787:21.93 elif Topology == 2: ScaleFactor = WingScaleFactor / 3.5 FinSurf, FinActualSemiSpan, FinArea, FinRootChord, FinAR, FinTip = Fin.GenerateLiftingSurface( ChordFactor, ScaleFactor) FinSurf = rs.RotateObject(FinSurf, P, 90, axis=RotVec) FinTip = rs.RotateObject(FinTip, P, 90, axis=RotVec) if Topology == 1: # Tailplane P = [0.7692 * FuselageLength, 0.000, FuselageHeight * 0.29] RotVec = rs.VectorCreate([1, 0, 0], [0, 0, 0]) LooseSurf = 1 SegmentNo = 100 TP = liftingsurface.LiftingSurface(P, tail.mySweepAngleFunctionTP, tail.myDihedralFunctionTP, tail.myTwistFunctionTP, tail.myChordFunctionTP, tail.myAirfoilFunctionTP, LooseSurf, SegmentNo) ChordFactor = 1.01 ScaleFactor = 0.388 * WingScaleFactor #787:17.3 TPSurf, TPActualSemiSpan, TPArea, TPRootChord, TPAR, TPTip = TP.GenerateLiftingSurface( ChordFactor, ScaleFactor) rs.EnableRedraw(True) rs.DeleteObjects([EngineSection, Chord]) try: rs.DeleteObjects([CutCirc]) except: pass try: rs.DeleteObjects([CutCircDisk]) except: pass # Windows # Cockpit windows: rs.EnableRedraw(False) CockpitWindowTop = 0.305 * FuselageHeight CWC1s, CWC2s, CWC3s, CWC4s = fuselage_oml.CockpitWindowContours( Height=CockpitWindowTop, Depth=6) FuselageOMLSurf, Win1 = rs.SplitBrep(FuselageOMLSurf, CWC1s, delete_input=True) FuselageOMLSurf, Win2 = rs.SplitBrep(FuselageOMLSurf, CWC2s, delete_input=True) FuselageOMLSurf, Win3 = rs.SplitBrep(FuselageOMLSurf, CWC3s, delete_input=True) FuselageOMLSurf, Win4 = rs.SplitBrep(FuselageOMLSurf, CWC4s, delete_input=True) rs.DeleteObjects([CWC1s, CWC2s, CWC3s, CWC4s]) (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax) = act.ObjectsExtents([Win1, Win2, Win3, Win4]) CockpitBulkheadX = Xmax CockpitWallPlane = rs.PlaneFromPoints([CockpitBulkheadX, -15, -15], [CockpitBulkheadX, 15, -15], [CockpitBulkheadX, -15, 15]) CockpitWall = rs.AddPlaneSurface(CockpitWallPlane, 30, 30) if 'WTBF' in locals(): rs.TrimBrep(WTBF, CockpitWall) rs.DeleteObject(CockpitWall) # Window lines WIN = [1] NOWIN = [0] # A typical window pattern (including emergency exit windows) WinVec = WIN + 2 * NOWIN + 9 * WIN + 3 * NOWIN + WIN + NOWIN + 24 * WIN + 2 * NOWIN + WIN + NOWIN + 14 * WIN + 2 * NOWIN + WIN + 20 * WIN + 2 * NOWIN + WIN + NOWIN + 20 * WIN if FuselageHeight < 8.0: # Single deck WindowLineHeight = 0.3555 * FuselageHeight WinX = 0.1157 * FuselageLength WindowPitch = 0.609 WinInd = -1 while WinX < 0.75 * FuselageLength: WinInd = WinInd + 1 if WinVec[WinInd] == 1 and WinX > CockpitBulkheadX: WinStbd, WinPort, FuselageOMLSurf = fuselage_oml.MakeWindow( FuselageOMLSurf, WinX, WindowLineHeight) act.AssignMaterial(WinStbd, "Plexiglass") act.AssignMaterial(WinPort, "Plexiglass") WinX = WinX + WindowPitch else: # Fuselage big enough to accommodate two decks # Lower deck WindowLineHeight = 0.17 * FuselageHeight #0.166 WinX = 0.1 * FuselageLength #0.112 WindowPitch = 0.609 WinInd = 0 while WinX < 0.757 * FuselageLength: WinInd = WinInd + 1 if WinVec[WinInd] == 1 and WinX > CockpitBulkheadX: WinStbd, WinPort, FuselageOMLSurf = fuselage_oml.MakeWindow( FuselageOMLSurf, WinX, WindowLineHeight) act.AssignMaterial(WinStbd, "Plexiglass") act.AssignMaterial(WinPort, "Plexiglass") WinX = WinX + WindowPitch # Upper deck WindowLineHeight = 0.49 * FuselageHeight WinX = 0.174 * FuselageLength #0.184 WinInd = 0 while WinX < 0.757 * FuselageLength: WinInd = WinInd + 1 if WinVec[WinInd] == 1 and WinX > CockpitBulkheadX: WinStbd, WinPort, FuselageOMLSurf = fuselage_oml.MakeWindow( FuselageOMLSurf, WinX, WindowLineHeight) act.AssignMaterial(WinStbd, "Plexiglass") act.AssignMaterial(WinPort, "Plexiglass") WinX = WinX + WindowPitch rs.Redraw() act.AssignMaterial(FuselageOMLSurf, "White_composite_external") act.AssignMaterial(WingSurf, "White_composite_external") try: act.AssignMaterial(TPSurf, "ShinyBARedMetal") except: pass act.AssignMaterial(FinSurf, "ShinyBARedMetal") act.AssignMaterial(Win1, "Plexiglass") act.AssignMaterial(Win2, "Plexiglass") act.AssignMaterial(Win3, "Plexiglass") act.AssignMaterial(Win4, "Plexiglass") # Mirror the geometry as required act.MirrorObjectXZ(WingSurf) act.MirrorObjectXZ(WingTip) try: act.MirrorObjectXZ(TPSurf) act.MirrorObjectXZ(TPTip) except: pass if Propulsion == 1: for ObjId in EngineStbd: act.MirrorObjectXZ(ObjId) act.MirrorObjectXZ(PylonStbd) elif Propulsion == 2: for ObjId in EngineStbd1: act.MirrorObjectXZ(ObjId) act.MirrorObjectXZ(PylonStbd1) for ObjId in EngineStbd2: act.MirrorObjectXZ(ObjId) act.MirrorObjectXZ(PylonStbd2) rs.DeleteObject(FSurf) rs.Redraw()
tempLine = rs.AddLine([0, 0, 0], tangent) rs.MoveObject(tempLine, c) dirLine = rs.RotateObject(tempLine, c, 90, None, True) offCurve = rs.OffsetCurve(tempLine, rs.CurveEndPoint(dirLine), (math.e**(rate * x)) - initThroat + throat) offPoints.append(rs.CurveStartPoint(offCurve)) rs.DeleteObject(offCurve) rs.DeleteObject(dirLine) dirLine = rs.RotateObject(tempLine, c, -90, None, True) offCurve = rs.OffsetCurve(tempLine, rs.CurveEndPoint(dirLine), (math.e**(rate * x)) - initThroat + throat) offPoints2.append(rs.CurveStartPoint(offCurve)) plane = rs.PlaneFromPoints( rs.CurveStartPoint(tempLine), rs.CurveStartPoint(offCurve), rs.VectorAdd(rs.CurveStartPoint(tempLine), [0, 0, 1])) radius = rs.Distance(rs.CurveStartPoint(tempLine), rs.CurveStartPoint(offCurve)) circle = rs.AddCircle(plane, radius) rs.DeleteObject(offCurve) rs.DeleteObject(dirLine) rs.DeleteObject(tempLine) circleProfiles.append(circle) x = x + 1 polyLines = [] for curve in circleProfiles: rad = rs.CurveRadius(curve, rs.CurveStartPoint(curve)) cLength = math.sqrt(((rad * math.cos((math.pi) / 4)) - rad)**2 +
import rhinoscriptsyntax as rs ### GetPoint tmp_point = rs.GetPoint("Point", (0, 0, 0)) ### Gei width, height tmp_width = rs.GetReal("Width", 2, 0, 10) tmp_height = rs.GetReal("Height", 3) ### (1) copy, move, define plane, del pt ### Bake tmp_point_c0 = rs.CopyObject(tmp_point) tmp_point_c1 = rs.CopyObject(tmp_point) tmp_plane = rs.PlaneFromPoints(tmp_point, rs.MoveObject(tmp_point_c0, (1, 0, 0)), rs.MoveObject(tmp_point_c1, (0, 1, 0))) tmp_point_x = rs.MoveObject(tmp_point_c0, (1, 0, 0)) tmp_point_y = rs.MoveObject(tmp_point_c1, (0, 1, 0)) tmp_plane = rs.PlaneFromPoints(tmp_point, tmp_point_x, tmp_point_y) rs.DeleteObject(tmp_point_x) rs.DeleteObject(tmp_point_y) ### (2) pointadd ### OK #tmp_point_x = rs.PointAdd(tmp_point, (1,0,0)) #tmp_point_y = rs.PointAdd(tmp_point, (0,1,0)) #tmp_plane = rs.PlaneFromPoints(tmp_point, tmp_point_x, tmp_point_y) tmp_rect = rs.AddRectangle(tmp_plane, tmp_width, tmp_height)
def optimization_rotate(_origin_point, _x_point, _y_point, _unused_srf, _unused_line, _unused_polyline, _unused_mark_line, _used_srf1, unused_timber, tolerance): start_time = time.time() # 初期変数 origin_point = _origin_point x_point = _x_point y_point = _y_point unused_srf = _unused_srf unused_line = _unused_line unused_polyline = _unused_polyline unused_mark_line = _unused_mark_line used_srf1 = _used_srf1 angle1 = 0.1 angle2 = -0.03 curve_length = [] count1 = 0 angle2_flag = False end_joint_count = 0 # 回転平面を定義する 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) # 描画 # rotate_axis = AddVector(rotate_p, rotate_vec) # print("-------------------------------------------------------") # 衝突判定 for i in range(200): curve = rs.IntersectBreps(unused_srf, used_srf1) # もし接触しなかった場合 if curve is None: curve_length = [] if i == 0: angle2_flag = True angle2 = -1.0 if i == 1: angle = (angle1 * -1.1) rs.RotateObject(unused_srf, rotate_p, angle, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle, rotate_vec) if i == 199: print("tan2: Can not optimize") # input("Can not optimize") # object削除 if curve: for k in range(0, len(curve)): rs.DeleteObject(curve[k]) # 平面をもとの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) # run time console end_time = time.time() optimization_rotate_run_time = end_time - start_time # print("---------------------------------------------------") # print("optimization_rotate Run time: %s" % optimization_rotate_run_time) return False # console # print("There is not curve[%s] angle2: %s" % (i, angle2)) rs.RotateObject(unused_srf, rotate_p, angle2, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle2, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle2, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle2, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle2, rotate_vec) count1 = count1 + 1 # もし20回連続で接触しない場合、回転方向を逆転する if count1 == 10 and angle2_flag: angle2 = angle2 * -1.0 angle = 10 * angle2 rs.RotateObject(unused_srf, rotate_p, angle, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle, rotate_vec) angle2_flag = False continue # もし接触した場合 else: length = 0 for j in range(0, len(curve)): if rs.IsCurve(curve[j]): length = length + rs.CurveLength(curve[j]) else: rs.RotateObject(unused_srf, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle1, rotate_vec) continue # 接点2の接触部の長さを格納する curve_length.append(length) # もし衝突交線の値が大きくなる場合、回転の方向を逆転する if len(curve_length) == 5: if curve_length[0] < curve_length[1] < curve_length[ 2] < curve_length[3] < curve_length[4]: angle1 = angle1 * -1.0 # print("update angle1") # print("angle1: %s" % angle1) angle = 3.0 * angle1 rs.RotateObject(unused_srf, rotate_p, angle, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle, rotate_vec) curve_length = [] # 接合条件を満たした場合 if length < tolerance: select_curve = curve[0] reference_point = createMidPointFromCurve(select_curve) check_domain = unused_timber.judgeSurfaceDomain( reference_point) # もし接触部が端部(domainが0か8の時) if check_domain == 0 or check_domain == 8: rs.RotateObject(unused_srf, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle1, rotate_vec) end_joint_count = end_joint_count + 1 if end_joint_count == 2: # print("tan2: Can not optimize(joint is ends)") # run time console end_time = time.time() optimization_rotate_run_time = end_time - start_time # print("---------------------------------------------------") # print("optimization_rotate Run time: %s" % optimization_rotate_run_time) return False continue else: # print("tan2 <count: %s | curve_length = %s>" % (i, length)) # 平面をもとの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) # run time console end_time = time.time() optimization_rotate_run_time = end_time - start_time # print("optimization_rotate Run time: %s" % optimization_rotate_run_time) return curve # 接合条件を満たさなかった場合 else: # angleを更新 if length < 45: if angle1 > 0: angle1 = 0.05 else: angle1 = -0.05 elif length < 60: if angle1 > 0: angle1 = 0.25 else: angle1 = -0.25 elif length < 70: if angle1 > 0: angle1 = 0.35 else: angle1 = -0.35 elif length < 100: if angle1 > 0: angle1 = 0.65 else: angle1 = -0.65 elif length < 120: if angle1 > 0: angle1 = 1.75 else: angle1 = -1.75 else: if angle1 > 0: angle1 = 2.0 else: angle1 = -2.0 rs.RotateObject(unused_srf, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_line, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_polyline, rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[0], rotate_p, angle1, rotate_vec) rs.RotateObject(unused_mark_line[1], rotate_p, angle1, rotate_vec) # print("curve length[%s]: %s | angle1: %s" % (i, length, angle1)) # object削除 for k in range(0, len(curve)): rs.DeleteObject(curve[k]) if i == 199: # print("tan2: Can not optimize") if curve: for k in range(0, len(curve)): rs.DeleteObject(curve[k]) # 平面をもとの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) # run time console end_time = time.time() optimization_rotate_run_time = end_time - start_time # print("---------------------------------------------------") # print("optimization_rotate Run time: %s" % optimization_rotate_run_time) return False
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
endPoint2 = [4.0, 2.0, 0.0] line2 = [startPoint2, endPoint2] line2ID = rs.AddLine(line2[0], line2[1]) # Returns another ObjectID int1 = rs.LineLineIntersection( line1ID, line2ID) # passing the ObjectIDs to the function. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #Practice 6 #################################################################### import rhinoscriptsyntax as rs ptOrigin = rs.GetPoint("Plane origin") ptX = rs.GetPoint("Plane X-axis", ptOrigin) ptY = rs.GetPoint("Plane Y-axis", ptOrigin) dX = rs.Distance(ptOrigin, ptX) dY = rs.Distance(ptOrigin, ptY) arrPlane = rs.PlaneFromPoints(ptOrigin, ptX, ptY) rs.AddPlaneSurface(arrPlane, 1.0, 1.0) rs.AddPlaneSurface(arrPlane, dX, dY) #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #Practice 7 #################################################################### import rhinoscriptsyntax as rs import math #Call rs.EnableRedraw(False) for t in rs.frange(-50, 50, 1.25): #-100,90,3 arrPoint = [t * math.sin(5 * t), t * math.cos(5 * t), t] print(arrPoint) rs.AddPoint(arrPoint) #Call rs.EnableRedraw(True)
import rhinoscriptsyntax as rs count = 5 for i in xrange(count): for j in xrange(count): ### define pt, plane tmp_pt = rs.AddPoint(i * 2, j * 2, 0) tmp_pln = rs.PlaneFromPoints(tmp_pt, rs.PointAdd(tmp_pt, (1, 0, 0)), rs.PointAdd(tmp_pt, (0, 1, 0))) ### define extrude line line_ex = rs.AddLine((0, 0, 0), (0, 0, 1)) ### draw rect tmp_crv = rs.AddRectangle(tmp_pln, 1, 1) tmp_surf = rs.AddPlanarSrf(tmp_crv) tmp_box = rs.ExtrudeSurface(tmp_surf, line_ex, True) ### set color rs.AddMaterialToObject(tmp_box) index = rs.ObjectMaterialIndex(tmp_box) rs.MaterialName(index, str(i) + "_" + str(j)) rs.MaterialColor(index, ((255 / count) * i, 255 - ((255 / count) * j), 255 - ((255 / count) * j))) name = rs.MaterialName(index)
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
def get_brep_lid_info(brep, start_index, material_thickness): #get bounding box bb = rs.BoundingBox(brep) if bb: for i, point in enumerate(bb): pass #rs.AddTextDot(i,point) #set height height = wge.get_brep_height(brep) top_crv = rs.AddPolyline([bb[4], bb[5], bb[6], bb[7], bb[4]]) bottom_crv = rs.AddPolyline([bb[0], bb[1], bb[2], bb[3], bb[0]]) top_label_pt, _ = rs.CurveAreaCentroid(top_crv) bottom_label_pt, _ = rs.CurveAreaCentroid(bottom_crv) rs.DeleteObjects([top_crv, bottom_crv]) #add text dots d1 = rs.AddTextDot(str(start_index), top_label_pt) d2 = rs.AddTextDot(str(start_index + 1), bottom_label_pt) rs.ObjectLayer([d1, d2], "XXX_LCUT_00-GUIDES") #get middle section and get polycurve g_polycurves = wge.get_brep_plan_cut(brep, height / 2, D_TOL) #get plan cut at mid-height g_polycurve = g_polycurves[ 0] #extract the first curve, we assume there will only be one curve. seg_count = 0 if g_polycurve.GetType() == Rhino.Geometry.PolyCurve: wge.make_pcurve_ccw(g_polycurve) else: g_polycurve = wru.polylinecurve_to_polycurve(g_polycurve) wge.make_pcurve_ccw(g_polycurve) startpts, endpts, divpts = wge.get_polycurve_segment_points(g_polycurve) g_polyline = wru.polycurve_to_polyline(g_polycurve, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceDegrees) seg_count = g_polycurve.SegmentCount g_polycurve_lid = offset_pcurve(g_polycurve, material_thickness) #convert to polyline if needed. if g_polycurve.GetType() == Rhino.Geometry.PolylineCurve: g_polyline = wru.polycurve_to_polyline(g_polycurve_lid, doc.ModelAbsoluteTolerance, doc.ModelAngleToleranceDegrees) else: g_polyline = g_polycurve_lid crv_bbox = g_polyline.GetBoundingBox(False) if not crv_bbox.IsValid: return Rhino.Commands.Result.Failure #Print the min and max box coordinates in world coordinates Rhino.RhinoApp.WriteLine("World min: {0}", crv_bbox.Min) Rhino.RhinoApp.WriteLine("World max: {0}", crv_bbox.Max) pt_origin = crv_bbox.Corner(True, True, True) pt_x_axis = crv_bbox.Corner(False, True, True) pt_y_axis = crv_bbox.Corner(True, False, True) plane1 = rs.PlaneFromPoints(pt_origin, pt_x_axis, pt_y_axis) plane2 = rs.PlaneFromPoints([0, 0, 0], [1, 0, 0], [0, 1, 0]) transformation = Rhino.Geometry.Transform.ChangeBasis( rs.coerceplane(plane2), rs.coerceplane(plane1)) g_polyline.Transform(transformation) dims = [ rs.Distance(pt_origin, pt_x_axis), rs.Distance(pt_origin, pt_y_axis) ] #print g_polyline.PointCount Dimensions = namedtuple('Dimensions', 'x y') dims = Dimensions(rs.Distance(pt_origin, pt_x_axis), rs.Distance(pt_origin, pt_y_axis)) SidesInfo = namedtuple( 'SidesInfo', 'outline dims') #dims are bounding dims for the curve out_sides_info = SidesInfo(g_polyline, dims) return out_sides_info
def planeFromPts(pts=None): if pts == None: return plane = rs.PlaneFromPoints(pts[1], pts[0], pts[2]) return plane