def FromEdgetoPlane(): PointPlane = [] CurveIdList = [] Brep = [] edges = rs.GetEdgeCurves() if edges: for edgeinfo in edges: Brep.append(edgeinfo[1]) CurveIdList.append(edgeinfo[0]) for CurveId in CurveIdList: if rs.IsCircle(CurveId): Pt = rs.CircleCenterPoint(CurveId) Normal = rs.CurveNormal(CurveId) LenghtNormal = rs.VectorLength(Normal) LenghNormal = self.m_foronumero.Text LenghNormal = int(LenghNormal) Normal = (LenghNormal * Normal[0], LenghNormal * Normal[1], LenghNormal * Normal[2]) PtStill = rs.AddPoint(Pt) Ptmoved = rs.MoveObject(Pt, Normal) Ptmoved = rs.coerce3dpoint(Ptmoved) PtStill = rs.coerce3dpoint(PtStill) PointPlane.append([ PtStill[0], PtStill[1], PtStill[2], Normal[0], Normal[1], Normal[2] ]) #PointPlane.append([Ptmoved[0],Ptmoved[1],Ptmoved[2],Normal[0],Normal[1],Normal[2]]) return (PointPlane, Brep)
def setCurveDir(objs): count = 0 for obj in objs: # if rs.IsCurve(obj) and rs.IsCurvePlanar(obj): if rs.IsCurve(obj) and rs.IsCurvePlanar(obj): normal = rs.CurveNormal(obj) if normal and normal[2] < 0: count += 1 rs.ReverseCurve(obj) normal2 = rs.CurveNormal(obj) print "Curve {} flipped {}{}".format(obj, normal, normal2) print "reversed " + str(count) + " curves"
def setCurveDir(objs): count = 0 for obj in objs: if rs.IsCurve(obj) and rs.IsCurvePlanar(obj): sp = rs.AddPoint(rs.CurveEndPoint(obj)) tangent = rs.CurveTangent(obj, rs.CurveDomain(obj)[0]) print tangent p2 = rs.CopyObject(sp, tangent * -10) rs.AddPoint(p2) # rs.Command("Dir") # for i in range(0,rs.PolyCurveCount(obj)): # l = rs.CurveLength(obj,i) # if l < 4: # print l # layer=rs.ObjectLayer(obj) # segments = rs.ExplodeCurves(obj, True) # obj = rs.JoinCurves(segments, True) # rs.ObjectLayer(obj, layer) # rs.ObjectLayer(obj, layer) normal = rs.CurveNormal(obj) result = rs.CurveAreaCentroid(obj) if result: print normal start = result[0] end = (result[0].X + 100 * normal[0], result[0].Y + 100 * normal[1], result[0].Z + 100 * normal[2]) rs.AddLine(result[0], end) if normal and normal[2] < 0: count += 1 rs.ReverseCurve(obj) # print "Curve {} flipped {}{}".format(obj, normal, normal2) # try to find discontinuities print "reversed " + str(count) + " curves"
def SetPlanarCurve(self, type="Any", guid=None): if (type == "Any"): prompt = "Select a planar pitch curve" elif (type == "Circle"): prompt = "Select the pitch circle" newCurve = rs.GetCurveObject(prompt, True, True) if guid is None else [guid] if (newCurve is None): Rhino.RhinoApp.WriteLine("Exit: No curve was selected") return False isPlanar = rs.IsCurvePlanar(newCurve[0]) if (isPlanar == False): newCurve = None Rhino.RhinoApp.WriteLine("Exit: Selected curve was not planar") return False self.curve = newCurve #Accept the curve into the object because the curve exists and it is planar self.isClosed = rs.IsCurveClosed(self.curve[0]) self.normal = rs.CurveNormal( self.curve[0]) #For non planar curves the script already exited. self.isCircle = rs.IsCircle(self.curve[0]) if (type == "Circle" and self.isCircle != True): Rhino.RhinoApp.WriteLine("Exit: Selected curve was not a circle") return False self.crvLen = rs.CurveLength(self.curve[0]) if (self.isCircle == True): Rhino.RhinoApp.WriteLine("Selected: Circle") self.origin = rs.CircleCenterPoint(self.curve[0]) self.plane = rs.PlaneFromNormal( self.origin, self.normal, rs.CurveStartPoint(self.curve[0]) - self.origin) #PlaneFromNormal(origin, normal, xaxis=None) self.SetPD() #Propagate the value updates self.SetBC() #Propagate the value updates return if (self.isClosed == True): Rhino.RhinoApp.WriteLine( "Selected: Closed non-circular planar curve") return else: Rhino.RhinoApp.WriteLine("Selected: Open planar curve")
def FromEdgetoPlane(): PointPlane = [] CurveIdList = [] Brep = [] edges = rs.GetEdgeCurves() if edges: for edgeinfo in edges: Brep.append(edgeinfo[1]) CurveIdList.append(edgeinfo[0]) # print CurveIdList for CurveId in CurveIdList: if rs.IsCircle(CurveId): # print "Sono un cerchio" Pt = rs.CircleCenterPoint(CurveId) Normal = rs.CurveNormal(CurveId) LenghtNormal = rs.VectorLength(Normal) LenghNormal = rs.GetString("give me the lengh of the hole", "100") LenghNormal = int(LenghNormal) Normal = (LenghNormal * Normal[0], LenghNormal * Normal[1], LenghNormal * Normal[2]) print Normal PtStill = rs.AddPoint(Pt) Ptmoved = rs.MoveObject(Pt, Normal) Ptmoved = rs.coerce3dpoint(Ptmoved) PtStill = rs.coerce3dpoint(PtStill) # print Ptmoved # print PtStill PointPlane.append([ PtStill[0], PtStill[1], PtStill[2], Normal[0], Normal[1], Normal[2] ]) #PointPlane.append([Ptmoved[0],Ptmoved[1],Ptmoved[2],Normal[0],Normal[1],Normal[2]]) return (PointPlane, Brep)
def makeGcodeFromSlicedCurve(self, slicedCurve, layer): deleteItem = [] tmpText = "" #it may shit if rs.IsCurveClosed(slicedCurve) is False: #slicedCurve = rs.CloseCurve(slicedCurve) startPoint = rs.CurveStartPoint(slicedCurve) endPoint = rs.CurveEndPoint(slicedCurve) curveForFix = rs.AddCurve([startPoint, endPoint]) curves = [] curves.append(slicedCurve) curves.append(curveForFix) slicedCurve = rs.JoinCurves(curves) #dirVec = rs.CurveNormal(slicedCurve) dirVec = self.normalVec #shell by shell #shell inside to outside for shell in range(self.gcoder.getNumShellOutline()): nozzleDia = self.gcoder.getExtruderDiameter() ''' if shell == 0: offsetCurve = rs.OffsetCurve(slicedCurve, tuple(dirVec), nozzleDia/2.0) else: #offsetCurve = rs.OffsetCurve(slicedCurve, tuple(dirVec), self.gcoder.getLayerHeight() * shell) offsetCurve = rs.OffsetCurve(slicedCurve, tuple(dirVec), nozzleDia/2.0 + nozzleDia*shell) ''' if shell == self.gcoder.getNumShellOutline() - 1: ##offsetCurve = rs.OffsetCurve(slicedCurve, dirVec, -nozzleDia/2.0) offsetCurve = rs.OffsetCurve(slicedCurve, dirVec, nozzleDia / 2.0) else: try: ##offsetCurve = rs.OffsetCurve(slicedCurve, dirVec, -(nozzleDia/2.0 + nozzleDia*(self.gcoder.getNumShellOutline()-shell-1))) offsetCurve = rs.OffsetCurve( slicedCurve, dirVec, (nozzleDia / 2.0 + nozzleDia * (self.gcoder.getNumShellOutline() - shell - 1))) except: print('offset failed\nslicedCurve') print(slicedCurve) print('dirVec') print(dirVec) #skip, when offset fail if offsetCurve == None: #print('failed to offset curve') continue if isinstance(offsetCurve, list) and len(offsetCurve) > 1: rs.DeleteObjects(offsetCurve) continue #explodedCurve = rs.ExplodeCurves(offsetCurve) #lines from explodedCurve #from outline to gcode #explodCurve is not enough #you need to convert curve to polyline #and then get point from editPoint prePoint = None currentPoint = None convertedPolyline = rs.ConvertCurveToPolyline(offsetCurve) vertices = rs.CurveEditPoints(convertedPolyline) rs.DeleteObject(convertedPolyline) flag = True for ver in vertices: currentPoint = ver if flag: tmpText = "G1 X{0} Y{1} Z{2} F{3}\n".format( currentPoint[0], currentPoint[1], currentPoint[2], 3600) flag = False else: self.gcoder.calcEValue(rs.Distance(currentPoint, prePoint)) tmpText = "G1 X{0} Y{1} Z{2} E{3} F{4}\n".format( currentPoint[0], currentPoint[1], currentPoint[2], self.gcoder.getEValue(), 1800) prePoint = currentPoint self.gcoder.addGcode(tmpText) #rs.DeleteObjects(explodedCurve) #from outline to fill gocde #if shell is last one, it needs to fill layer or infill #inside to outside if shell == (self.gcoder.getNumShellOutline() - 1): rs.DeleteObject(offsetCurve) ##offsetCurveForFill = rs.OffsetCurve(slicedCurve, dirVec, -(nozzleDia/2.0 + nozzleDia*(self.gcoder.getNumShellOutline()))) offsetCurveForFill = rs.OffsetCurve( slicedCurve, dirVec, (nozzleDia / 2.0 + nozzleDia * (self.gcoder.getNumShellOutline()))) #newOffsetCurve = rs.OffsetCurve(offsetCurve, tuple(dirVec), self.gcoder.getLayerHeight()) if offsetCurveForFill == None: #print('failed to offset curve') break if isinstance(offsetCurveForFill, list) and len(offsetCurveForFill) > 1: rs.DeleteObjects(offsetCurveForFill) break ''' offsetCurveForFill = rs.OffsetCurve(offsetCurve, tuple(dirVec), nozzleDia) #detect failed to offset if isinstance(offsetCurveForFill, list) and len(offsetCurveForFill) > 1: continue ''' #fill for middle paralell layer for paralellLayer in range(len( self.paralellIntersectedCurves)): if layer >= self.indexParalellSurfaces[ paralellLayer] and abs( layer - self.indexParalellSurfaces[paralellLayer] ) < self.gcoder.getNumTopLayer(): ''' dirVecForParalell = rs.CurveAreaCentroid(self.paralellIntersectedCurves[paralellLayer]) dirVecForParalell = dirVecForParalell[0] ''' dirVecForParalell = rs.CurveNormal( self.paralellIntersectedCurves[paralellLayer]) offsetParalell = rs.OffsetCurve( self.paralellIntersectedCurves[paralellLayer], dirVecForParalell, -(nozzleDia / 2.0 + nozzleDia * (self.gcoder.getNumShellOutline()))) #debug ''' #print('layer') #print(layer) rs.UnselectAllObjects() rs.SelectObject(offsetParalell) rs.Command('Move') ''' #it needs to debug, it's close self.setLayerFill(offsetParalell, layer) continue #self.setInfill(vec, newOffsetCurve, offsetParalell) if layer < (self.gcoder.getNumBottomLayer()): self.setLayerFill(offsetCurveForFill, layer) rs.DeleteObject(offsetCurveForFill) elif layer > ( int(self.distancePrinting / self.fixedLayerHeight) - self.gcoder.getNumTopLayer()): self.setLayerFill(offsetCurveForFill, layer) rs.DeleteObject(offsetCurveForFill) else: self.setInfill(offsetCurveForFill, layer) if offsetCurveForFill is not None: rs.DeleteObject(offsetCurveForFill) #rs.DeleteObjects(newOffsetCurve) #DEBUG rs.DeleteObjects(offsetCurve) rs.DeleteObject(slicedCurve)
def setSurfaceForSlicing(self): explodedSurfaces = rs.ExplodePolysurfaces(self.addtiveObj) editPoint = [] #get editPoint from polysurfaces if len(explodedSurfaces) == 0: #use obj meshed = rhino.Geometry.Mesh.CreateFromBrep( rs.coercebrep(self.addtiveObj)) editPoint = rs.MeshVertices(meshed[0]) else: for i in explodedSurfaces: meshed = rhino.Geometry.Mesh.CreateFromBrep(rs.coercebrep(i)) vertices = rs.MeshVertices(meshed[0]) editPoint.extend(vertices) rs.DeleteObjects(explodedSurfaces) minValue = [] maxValue = [] basePointForPlane = None basePointForDistance = None for i in range(len(editPoint)): if i == 0: basePointForPlane = editPoint[0] basePointForDistance = editPoint[0] for j in range(3): minValue.append(editPoint[0][j]) maxValue.append(editPoint[0][j]) continue else: if basePointForPlane[2] > editPoint[i][2]: basePointForPlane = editPoint[i] if basePointForDistance[2] < editPoint[i][2]: basePointForDistance = editPoint[i] for j in range(3): if minValue[j] > editPoint[i][j]: minValue[j] = editPoint[i][j] elif maxValue[j] < editPoint[i][j]: maxValue[j] = editPoint[i][j] #why? self.basePointForPlane = basePointForPlane plane = rs.PlaneFromNormal(basePointForPlane, self.normalVec) #calculating distance printing self.calcDistance(plane, editPoint) #make base surface pntForSur = [] line = (minValue[0], minValue[1], minValue[2]), (minValue[0], minValue[1], maxValue[2]) pntForSur.append(rs.LinePlaneIntersection(line, plane)) line = (minValue[0], maxValue[1], minValue[2]), (minValue[0], maxValue[1], maxValue[2]) pntForSur.append(rs.LinePlaneIntersection(line, plane)) line = (maxValue[0], maxValue[1], minValue[2]), (maxValue[0], maxValue[1], maxValue[2]) pntForSur.append(rs.LinePlaneIntersection(line, plane)) line = (maxValue[0], minValue[1], minValue[2]), (maxValue[0], minValue[1], maxValue[2]) pntForSur.append(rs.LinePlaneIntersection(line, plane)) lineForSur = [] for i in range(4): lineForSur.append(rs.AddLine(pntForSur[i], pntForSur[(i + 1) % 4])) joinedCurve = rs.JoinCurves(lineForSur) rs.DeleteObjects(lineForSur) curveForSur = rs.OffsetCurve(joinedCurve, rs.CurveNormal(joinedCurve), 30) self.sliceSurface = rs.AddPlanarSrf(curveForSur) if len(curveForSur) > 1 or rs.IsPointOnSurface( self.sliceSurface, rs.CurveStartPoint(joinedCurve)) is False: rs.DeleteObjects(curveForSur) if self.sliceSurface is not None: rs.DeleteObject(self.sliceSurface) curveForSur = rs.OffsetCurve(joinedCurve, rs.CurveNormal(joinedCurve), -30) self.sliceSurface = rs.AddPlanarSrf(curveForSur) rs.DeleteObjects(joinedCurve) rs.DeleteObjects(curveForSur) self.fixedLayerHeight = float( self.gcoder.getLayerHeight() * (1.0 / math.cos(math.radians(self.angleOfSurface)))) self.addtiveObj = rs.CopyObject(self.addtiveObj, (0, 0, self.fixedLayerHeight * 0.9)) self.sliceSurface = rs.MoveObject(self.sliceSurface, (0, 0, self.fixedLayerHeight * 0.9))
import rhinoscriptsyntax as rs curve = rs.GetObject("Select a curve", 4) length = rs.CurveLength(curve) domain = rs.CurveDomain(curve) t = (domain[1] - domain[0]) / 2 midpoint = rs.EvaluateCurve(curve, t) tangent = rs.CurveTangent(curve, t) normal = rs.CurveNormal(curve, t) print("length:" + str(length)) print("domain =" + str(domain[0]) + str(domain[1])) print("co-ordinates of midpoint = " + str(midpoint)) print("tangent vector = " + str(tangent)) print("normal vector = " + str(normal))
def handrailGen(self, sender, e): flip = self.flipC.Checked hType = self.handrailTypeC.SelectedIndex handrailOffset = int(self.handrailOffsetC.Value) * scale tread = int(self.treadC.Value) * scale riser = int(self.riserC.Value) * scale numSteps = int(self.numStepsC.Value) hEndLength = int(self.handrailExtensionC.Value) * scale pipeDiameter = int(self.handrailDiameterC.Value) * scale hHeight = int(self.handrailHeightC.Value) * scale topLine = rs.AddLine(line[0], line[1]) rs.ObjectName(topLine, "BC6#DT5LCQX*#8r97Tquf5gNF") topPoint = line[0] genHandrail = self.genHandrailBool.Checked rs.EnableRedraw(False) if genHandrail == False: iteration = rs.ObjectsByName( "qe7g&G5LzXEvbudtPT8xCxQbisusFVqCPqMsiHK2jc") if iteration: rs.DeleteObjects(iteration) rs.EnableRedraw(True) if genHandrail == True: # Delete any existing iteration iteration = rs.ObjectsByName( "qe7g&G5LzXEvbudtPT8xCxQbisusFVqCPqMsiHK2jc") if iteration: rs.DeleteObjects(iteration) # get perp line - length of stair t = rs.CurveClosestPoint(topLine, topPoint) planeNormal = rs.CurveNormal(topLine) tangent = rs.CurveTangent(topLine, t) if flip == False: curveNormal = rs.VectorCrossProduct(planeNormal, tangent) else: curveNormal = rs.VectorReverse( rs.VectorCrossProduct(planeNormal, tangent)) # Get guide curve scaledV = rs.VectorReverse( rs.VectorScale(curveNormal, tread*numSteps)) ptGuide1 = rs.AddPoint(line[0]) ptGuide2 = rs.CopyObject(ptGuide1, scaledV) rs.MoveObjects([ptGuide1, ptGuide2], [ 0, 0, (riser*numSteps)*-1]) curve = rs.AddCurve([ptGuide1, ptGuide2]) # Get vector for step run vectorRun = rs.VectorCreate( topPoint, topPoint + curveNormal * tread) # Setup curves for handrail curve1 = curve curve2 = rs.MoveObject(rs.CopyObject(curve1, rs.VectorCreate(line[1], rs.CurveStartPoint(curve1))), [0, 0, (riser * numSteps)*-1]) midPoint = rs.CurveMidPoint(userCurve) # Main slanted handrail curve pt1 = rs.MoveObject(rs.MoveObject(rs.CurveStartPoint(curve1), vectorRun), [ 0, 0, hHeight + (riser*numSteps)]) pt2 = rs.MoveObject(rs.MoveObject( rs.CurveEndPoint(curve1), vectorRun), [0, 0, hHeight]) mainCurve = rs.AddCurve([pt1, pt2]) # Top leveled handrail curve at 300mm standard DDA pt3 = rs.CopyObject(pt1, rs.VectorReverse( rs.VectorScale(rs.VectorUnitize(vectorRun), hEndLength))) topCurve = rs.AddCurve([pt1, pt3]) # Bottom leveled handrail curve at 300mm standard DDA pt4 = rs.CopyObject(pt2, rs.VectorScale( rs.VectorUnitize(vectorRun), hEndLength)) bottomCurve = rs.AddCurve([pt2, pt4]) # Start list of construction geometry for later cleanup hGeoList = [curve1, curve2, pt1, pt2, mainCurve, pt3, topCurve, pt4, bottomCurve, ptGuide1, ptGuide2, curve, topLine] # IF STATEMENTS FOR HANDRAIL TYPE # 1 180 degree, no return if hType == 0: # Lower Handrail return hpt1 = rs.CopyObject(pt4, [0, 0, (pipeDiameter * 2) * -1]) hpt2 = rs.MoveObject(rs.CopyObject( pt4, [0, 0, pipeDiameter * -1]), rs.VectorScale(rs.VectorUnitize(vectorRun), pipeDiameter)) lowerH = rs.AddArc3Pt(pt4, hpt1, hpt2) # Upper Handrail return hpt3 = rs.CopyObject(pt3, [0, 0, (pipeDiameter * 2) * -1]) hpt4 = rs.MoveObject(rs.CopyObject(pt3, [0, 0, pipeDiameter * -1]), rs.VectorReverse( rs.VectorScale(rs.VectorUnitize(vectorRun), pipeDiameter))) upperH = rs.AddArc3Pt(pt3, hpt3, hpt4) # Draw leg upper lpt1 = rs.CurveMidPoint(topCurve) lpt2 = rs.CopyObject(lpt1, [0, 0, hHeight*-1]) lCurveUpper = rs.AddCurve([lpt1, lpt2]) # Draw leg lower lpt3 = rs.CopyObject(pt2, [0, 0, hHeight*-1]) lCurveLower = rs.AddCurve([pt2, lpt3]) # Make vectors to move handrails into place moveShort = rs.VectorScale(userVector, handrailOffset) moveLong = rs.VectorScale( userVector, rs.CurveLength(userCurve) - (handrailOffset*2)) # Join, offset skeleton hCurve = rs.JoinCurves( [mainCurve, topCurve, bottomCurve, lowerH, upperH]) hCurve1 = rs.CopyObject(hCurve, moveShort) lCurveUpper1 = rs.CopyObject(lCurveUpper, moveShort) lCurveLower1 = rs.CopyObject(lCurveLower, moveShort) # Pipe skeleton pipe1 = rs.AddPipe( hCurve1, 0, pipeDiameter/2, blend_type=0, cap=1) pipe2 = rs.AddPipe( lCurveUpper1, 0, pipeDiameter/2, blend_type=0, cap=1) pipe3 = rs.AddPipe( lCurveLower1, 0, pipeDiameter/2, blend_type=0, cap=1) # form list of generated geo handrailGeo1 = [pipe1, pipe2, pipe3] # Name geo for deletion for i in handrailGeo1: rs.ObjectName( i, "qe7g&G5LzXEvbudtPT8xCxQbisusFVqCPqMsiHK2jc") # copy handrailGeo2 = rs.CopyObjects(handrailGeo1, moveLong) # Cleanup construction linework hGeoList.extend([hpt1, hpt2, lowerH, hpt3, hpt4, upperH, lpt2, lpt3, lCurveLower, hCurve, hCurve1, lCurveUpper1, lCurveLower1, lCurveUpper]) rs.DeleteObjects(hGeoList) rs.EnableRedraw(True) # 2 180 degree, full return if hType == 1: rs.EnableRedraw(False) # Lower handrail return hpt1 = rs.CopyObject(pt4, [0, 0, (hEndLength/3)*-2]) hpt2 = rs.CopyObject(pt2, [0, 0, (hEndLength/3)*-2]) hCurve11 = rs.AddPolyline([pt4, hpt1, hpt2]) lowerH = rs.JoinCurves([bottomCurve, hCurve11]) # Upper handrail return hpt3 = rs.CopyObject(pt3, [0, 0, (hEndLength/3)*-2]) hpt4 = rs.CopyObject(rs.CurveMidPoint( topCurve), [0, 0, (hEndLength/3)*-2]) hCurve2 = rs.AddPolyline([pt3, hpt3, hpt4]) upperH = rs.JoinCurves([topCurve, hCurve2]) # Draw leg upper lpt1 = rs.CurveMidPoint(topCurve) lpt2 = rs.CopyObject(lpt1, [0, 0, hHeight*-1]) lCurveUpper = rs.AddCurve([lpt1, lpt2]) # Draw leg lower lpt3 = rs.CopyObject(pt2, [0, 0, hHeight*-1]) lCurveLower = rs.AddCurve([pt2, lpt3]) # Make vectors to move handrails into place moveShort = rs.VectorScale(userVector, handrailOffset) moveLong = rs.VectorScale( userVector, rs.CurveLength(userCurve) - (handrailOffset*2)) # Pipe skeleton move hCurve1 = rs.JoinCurves([lowerH, upperH, mainCurve]) rs.MoveObjects( [hCurve1, lCurveUpper, lCurveLower], moveShort) # Pipe pipe1 = rs.AddPipe( hCurve1, 0, pipeDiameter/2, blend_type=0, cap=1) pipe2 = rs.AddPipe( lCurveUpper, 0, pipeDiameter/2, blend_type=0, cap=1) pipe3 = rs.AddPipe( lCurveLower, 0, pipeDiameter/2, blend_type=0, cap=1) handrailGeo1 = [pipe1, pipe2, pipe3] # Name geo for deletion for i in handrailGeo1: rs.ObjectName( i, "qe7g&G5LzXEvbudtPT8xCxQbisusFVqCPqMsiHK2jc") # Move and copy into position handrailGeo2 = rs.CopyObjects(handrailGeo1, moveLong) # Cleanup hGeoList.extend([hpt1, hpt2, hCurve11, lowerH, hpt3, hpt4, hCurve2, upperH, lpt2, lCurveUpper, lpt3, lCurveLower, hCurve1]) rs.DeleteObjects(hGeoList) rs.EnableRedraw(True) # 3 Ground triangle return if hType == 2: rs.EnableRedraw(False) # Draw leg upper lpt1 = rs.CurveMidPoint(topCurve) lpt2 = rs.CopyObject(lpt1, [0, 0, hHeight*-1]) lCurveUpper = rs.AddCurve([lpt1, lpt2]) # Draw leg lower lpt3 = rs.CopyObject(pt2, [0, 0, hHeight*-1]) lCurveLower = rs.AddCurve([pt2, lpt3]) # Lower Return lowerH = rs.AddCurve([pt4, lpt3]) # Upper Return upperH = rs.AddCurve([pt3, lpt2]) # Make vectors to move handrails into place moveShort = rs.VectorScale(userVector, handrailOffset) moveLong = rs.VectorScale( userVector, rs.CurveLength(userCurve) - (handrailOffset*2)) # Join Curves and move hCurve = rs.JoinCurves( [mainCurve, topCurve, bottomCurve, lowerH, upperH]) rs.MoveObjects( [hCurve, lCurveUpper, lCurveLower], moveShort) # pipe pipe1 = rs.AddPipe(hCurve, 0, pipeDiameter / 2, blend_type=0, cap=1) pipe2 = rs.AddPipe( lCurveUpper, 0, pipeDiameter/2, blend_type=0, cap=1) pipe3 = rs.AddPipe( lCurveLower, 0, pipeDiameter/2, blend_type=0, cap=1) handrailGeo1 = [pipe1, pipe2, pipe3] # Name geo for deletion for i in handrailGeo1: rs.ObjectName( i, "qe7g&G5LzXEvbudtPT8xCxQbisusFVqCPqMsiHK2jc") # move and copy into place handrailGeo2 = rs.CopyObjects(handrailGeo1, moveLong) # Cleanup hGeoList.extend( [lpt2, lCurveUpper, lpt3, lCurveLower, lowerH, upperH, hCurve, topLine]) rs.DeleteObjects(hGeoList) rs.EnableRedraw(True) # 4 Ground return if hType == 3: rs.EnableRedraw(False) # Draw leg upper lpt1 = rs.CurveMidPoint(topCurve) lpt2 = rs.CopyObject(lpt1, [0, 0, hHeight*-1]) lCurveUpper = rs.AddCurve([lpt1, lpt2]) # Draw leg lower lpt3 = rs.CopyObject(pt2, [0, 0, hHeight*-1]) lCurveLower = rs.AddCurve([pt2, lpt3]) # Lower Return hpt1 = rs.CopyObject(pt4, [0, 0, hHeight*-1]) hCurve1 = rs.AddCurve([pt4, hpt1]) # Upper Return hpt2 = rs.CopyObject(pt3, [0, 0, hHeight*-1]) hCurve2 = rs.AddCurve([pt3, hpt2]) # Join curves hCurve = rs.JoinCurves( [mainCurve, topCurve, bottomCurve, hCurve1, hCurve2]) # Get Vectors moveShort = rs.VectorScale(userVector, handrailOffset) moveLong = rs.VectorScale( userVector, rs.CurveLength(userCurve) - (handrailOffset*2)) # move rs.MoveObjects( [hCurve, lCurveUpper, lCurveLower], moveShort) # Pipe pipe1 = rs.AddPipe(hCurve, 0, pipeDiameter / 2, blend_type=0, cap=1) pipe2 = rs.AddPipe( lCurveUpper, 0, pipeDiameter/2, blend_type=0, cap=1) pipe3 = rs.AddPipe( lCurveLower, 0, pipeDiameter/2, blend_type=0, cap=1) handrailGeo1 = [pipe1, pipe2, pipe3] # Name geo for deletion for i in handrailGeo1: rs.ObjectName( i, "qe7g&G5LzXEvbudtPT8xCxQbisusFVqCPqMsiHK2jc") # move and copy into place handrailGeo2 = rs.CopyObjects(handrailGeo1, moveLong) # Clean up hGeoList.extend([lpt2, lCurveUpper, lpt3, lCurveLower, hpt1, hCurve1, hpt2, hCurve2, hCurve, topLine]) rs.DeleteObjects(hGeoList) rs.EnableRedraw(True) # 5 Wall return if hType == 4: rs.EnableRedraw(False) # Draw leg upper lpt1 = rs.CurveMidPoint(topCurve) lpt2 = rs.CopyObject(lpt1, [0, 0, hHeight*-1]) lCurveUpper = rs.AddCurve([lpt1, lpt2]) # Draw leg lower lpt3 = rs.CopyObject(pt2, [0, 0, hHeight*-1]) lCurveLower = rs.AddCurve([pt2, lpt3]) # get vectors vector1 = rs.VectorScale(rs.VectorUnitize( rs.VectorReverse(userVector)), handrailOffset) vector2 = rs.VectorScale( userVector, rs.CurveLength(userCurve)) # Lower Return hpt1 = rs.CopyObject(pt4, vector1) hCurve1 = rs.AddCurve([pt4, hpt1]) # Upper Return hpt2 = rs.CopyObject(pt3, vector1) hCurve2 = rs.AddCurve([pt3, hpt2]) # Join main curves hCurveMain1 = rs.JoinCurves( [mainCurve, topCurve, bottomCurve]) # Get Vectors moveShort = rs.VectorScale(userVector, handrailOffset) moveLong = rs.VectorScale( userVector, rs.CurveLength(userCurve) - handrailOffset) # Copy hanrail 2 hCurveMain2 = rs.CopyObject(hCurveMain1, moveLong) hCurve3 = rs.CopyObject(hCurve1, vector2) hCurve4 = rs.CopyObject(hCurve2, vector2) lCurveUpper2 = rs.CopyObject(lCurveUpper, moveLong) lCurveLower2 = rs.CopyObject(lCurveLower, moveLong) # Join curves hCurveJoined1 = rs.JoinCurves( [hCurve1, hCurve2, hCurveMain1]) hCurveJoined2 = rs.JoinCurves( [hCurveMain2, hCurve3, hCurve4, ]) # Pipe pipe1 = rs.AddPipe( hCurveJoined1, 0, pipeDiameter/2, blend_type=0, cap=1) pipe2 = rs.AddPipe( lCurveLower, 0, pipeDiameter/2, blend_type=0, cap=1) pipe3 = rs.AddPipe( lCurveUpper, 0, pipeDiameter/2, blend_type=0, cap=1) pipe4 = rs.AddPipe( hCurveJoined2, 0, pipeDiameter/2, blend_type=0, cap=1) pipe5 = rs.AddPipe( lCurveUpper2, 0, pipeDiameter/2, blend_type=0, cap=1) pipe6 = rs.AddPipe( lCurveLower2, 0, pipeDiameter/2, blend_type=0, cap=1) handrailGeo1 = [pipe1, pipe2, pipe3, pipe3, pipe4, pipe5, pipe6] # Name geo for deletion for i in handrailGeo1: rs.ObjectName( i, "qe7g&G5LzXEvbudtPT8xCxQbisusFVqCPqMsiHK2jc") # Move handrail 1 into place rs.MoveObjects([pipe1, pipe2, pipe3], moveShort) # Cleanup hGeoList.extend([lpt2, lCurveUpper, lpt3, lCurveLower, hpt1, hCurve1, hpt2, hCurve2, hCurveMain1, hCurveMain2, hCurve3, hCurve4, lCurveUpper2, lCurveLower2, hCurveJoined1, hCurveJoined2]) rs.DeleteObjects(hGeoList) rs.EnableRedraw(True)
def stairGen(self, sender, e): # Variables and defaults tread = int(self.treadC.Value) * scale riser = int(self.riserC.Value) * scale numSteps = int(self.numStepsC.Value) flip = self.flipC.Checked stairLength = tread * numSteps genStair = self.genStairBool.Checked curveList = [] junkList = [] # get user line for top width of stair rs.EnableRedraw(False) if genStair == False: iteration = rs.ObjectsByName( "GdC9V&^a^rGZZNgiWFH&aTRQLLscu*9AZCmhk8t2!a") if iteration: rs.DeleteObject(iteration) rs.EnableRedraw(True) if genStair == True: # Delete any existing iteration iteration = rs.ObjectsByName( "GdC9V&^a^rGZZNgiWFH&aTRQLLscu*9AZCmhk8t2!a") if iteration: rs.DeleteObject(iteration) topLine = rs.AddLine(line[0], line[1]) topPoint = line[0] stepPoint = topPoint # get perp line - length of stair t = rs.CurveClosestPoint(topLine, topPoint) planeNormal = rs.CurveNormal(topLine) tangent = rs.CurveTangent(topLine, t) curveNormal = rs.VectorCrossProduct(planeNormal, tangent) # Get vector vectorRun = rs.VectorCreate( topPoint, topPoint + curveNormal * tread) # Bool flip direction of stair (add bool option in GUI) if flip == True: vector = rs.VectorReverse(vectorRun) else: vector = vectorRun # loop through number of steps to gen step curve for i in range(numSteps): pt01 = rs.AddPoint(stepPoint) pt02 = rs.CopyObject(pt01, vector) pt03 = rs.CopyObject(pt02, [0, 0, riser*-1]) curve = rs.AddPolyline([pt01, pt02, pt03]) curveList.append(curve) stepPoint = rs.CurveEndPoint(curve) rs.DeleteObjects([pt01, pt02, pt03]) # Extrude stair curve to full width joinedCurve = rs.JoinCurves(curveList) bottomPoint = rs.CopyObject( line[0], [0, 0, (riser*numSteps)*-1]) stairBottom = rs.CurveEndPoint(joinedCurve) curve = rs.AddPolyline([line[0], bottomPoint, stairBottom]) # createhandrail curve and return it handRailCurve = rs.AddCurve([bottomPoint, stairBottom]) curveList.append(curve) joinedCurves = rs.JoinCurves(curveList) stair = rs.ExtrudeCurveStraight(joinedCurves, line[0], line[1]) rs.CapPlanarHoles(stair) # this identifies the generated stair geometry rs.ObjectName( stair, "GdC9V&^a^rGZZNgiWFH&aTRQLLscu*9AZCmhk8t2!a") # clean up leftover geometry junkList.extend([bottomPoint, joinedCurve, joinedCurves, topLine, handRailCurve]) junkList = junkList + curveList rs.DeleteObjects(junkList) rs.EnableRedraw(True)
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