def Activated (self): import pipeCmd, frameCmd from Part import Plane refFace=[f for f in frameCmd.faces() if type(f.Surface)==Plane][0] FreeCAD.activeDocument().openTransaction('Lay-down the pipe') for b in frameCmd.beams(): if pipeCmd.isPipe(b): pipeCmd.laydownTheTube(b,refFace) FreeCAD.activeDocument().recompute() FreeCAD.activeDocument().commitTransaction()
def Activated(self): import pipeCmd, frameCmd from Part import Plane refFace = [f for f in frameCmd.faces() if type(f.Surface) == Plane][0] FreeCAD.activeDocument().openTransaction('Lay-down the pipe') for b in frameCmd.beams(): if pipeCmd.isPipe(b): pipeCmd.laydownTheTube(b, refFace) FreeCAD.activeDocument().recompute() FreeCAD.activeDocument().commitTransaction()
def getL(self): l=[p.Height for p in frameCmd.beams() if pipeCmd.isPipe(p)] if l: refL=min(l) self.lab0.setText(str(refL)) self.refL=float(refL) self.edit1.setText("%.2f" %(self.refL*self.slider.value()/100.0)) else: self.lab0.setText('<reference>') self.refL=0.0 self.edit1.setText(str(self.slider.value())+'%')
def Activated (self): import pipeCmd, frameCmd from Part import Plane selex=FreeCADGui.Selection.getSelectionEx() for sx in selex: sxFaces=[f for f in frameCmd.faces([sx]) if type(f.Surface)==Plane] if len(sxFaces)>0: refFace=sxFaces[0] support=sx.Object FreeCAD.activeDocument().openTransaction('Raise-up the support') for b in frameCmd.beams(): if pipeCmd.isPipe(b): pipeCmd.laydownTheTube(b,refFace,support) break FreeCAD.activeDocument().recompute() FreeCAD.activeDocument().commitTransaction()
def breakPipe(self): p2nd=None FreeCAD.activeDocument().openTransaction('Break pipes') if self.edit1.text()[-1]=='%': pipes=[p for p in frameCmd.beams() if pipeCmd.isPipe(p)] for p in pipes: p2nd=pipeCmd.breakTheTubes(float(p.Height)*float(self.edit1.text().rstrip('%').strip())/100,pipes=[p],gap=float(self.edit2.text())) if p2nd and self.combo.currentText()!='<none>': for p in p2nd: pipeCmd.moveToPyLi(p,self.combo.currentText()) else: p2nd=pipeCmd.breakTheTubes(float(self.edit1.text()),gap=float(self.edit2.text())) if p2nd and self.combo.currentText()!='<none>': for p in p2nd: pipeCmd.moveToPyLi(p,self.combo.currentText()) FreeCAD.activeDocument().commitTransaction() FreeCAD.activeDocument().recompute()
def insert(self): # insert the curve #self.lastElbow=None self.lastAngle=0 self.dial.setValue(0) DN=OD=thk=PRating=None d=self.pipeDictList[self.sizeList.currentRow()] try: if float(self.edit1.text())>180: self.edit1.setText("180") ang=float(self.edit1.text()) except: ang=float(pq(d['BendAngle'])) selex=FreeCADGui.Selection.getSelectionEx() if len(selex)==0: # no selection -> insert one elbow at origin propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk'])),ang,float(pq(d['BendRadius']))] FreeCAD.activeDocument().openTransaction('Insert elbow in (0,0,0)') self.lastElbow=pipeCmd.makeElbow(propList) if self.combo.currentText()!='<none>': pipeCmd.moveToPyLi(self.lastElbow,self.combo.currentText()) FreeCAD.activeDocument().commitTransaction() elif len(selex)==1 and len(selex[0].SubObjects)==1: #one selection -> ... if hasattr(selex[0].Object,'PType') and selex[0].Object.PType in ['Pipe','Elbow','Cap','Reduct']: DN=selex[0].Object.PSize OD=float(selex[0].Object.OD) thk=float(selex[0].Object.thk) BR=None for prop in self.pipeDictList: if prop['PSize']==DN: BR=float(pq(prop['BendRadius'])) if BR==None: BR=1.5*OD/2 propList=[DN,OD,thk,ang,BR] else: propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk'])),ang,float(pq(d['BendRadius']))] if selex[0].SubObjects[0].ShapeType=="Vertex": # ...on vertex FreeCAD.activeDocument().openTransaction('Insert elbow on vertex') self.lastElbow=pipeCmd.makeElbow(propList,selex[0].SubObjects[0].Point) if self.combo.currentText()!='<none>': pipeCmd.moveToPyLi(self.lastElbow,self.combo.currentText()) FreeCAD.activeDocument().commitTransaction() elif selex[0].SubObjects[0].ShapeType=="Edge" and selex[0].SubObjects[0].curvatureAt(0)!=0: # ...on center of curved edge P=selex[0].SubObjects[0].centerOfCurvatureAt(0) N=selex[0].SubObjects[0].normalAt(0).cross(selex[0].SubObjects[0].tangentAt(0)).normalize() FreeCAD.activeDocument().openTransaction('Insert elbow on curved edge') self.lastElbow=pipeCmd.makeElbow(propList,P) # ,Z) if pipeCmd.isPipe(selex[0].Object): ax=selex[0].Object.Shape.Solids[0].CenterOfMass-P rot=FreeCAD.Rotation(self.lastElbow.Ports[0],ax) self.lastElbow.Placement.Rotation=rot.multiply(self.lastElbow.Placement.Rotation) Port0=pipeCmd.getElbowPort(self.lastElbow) self.lastElbow.Placement.move(P-Port0) elif pipeCmd.isElbow(selex[0].Object): p0,p1=[selex[0].Object.Placement.Rotation.multVec(p) for p in selex[0].Object.Ports] if frameCmd.isParallel(p0,N): self.lastElbow.Placement.Rotation=FreeCAD.Rotation(self.lastElbow.Ports[0],p0*-1) else: self.lastElbow.Placement.Rotation=FreeCAD.Rotation(self.lastElbow.Ports[0],p1*-1) self.lastElbow.Placement.move(P-pipeCmd.getElbowPort(self.lastElbow)) else: rot=FreeCAD.Rotation(self.lastElbow.Ports[0],N) self.lastElbow.Placement.Rotation=rot.multiply(self.lastElbow.Placement.Rotation) self.lastElbow.Placement.move(self.lastElbow.Placement.Rotation.multVec(self.lastElbow.Ports[0])*-1) if self.combo.currentText()!='<none>': pipeCmd.moveToPyLi(self.lastElbow,self.combo.currentText()) FreeCAD.activeDocument().recompute() FreeCAD.activeDocument().commitTransaction() else: # multiple selection -> insert one elbow at intersection of two edges or beams or pipes ## # selection of axes things=[] for objEx in selex: # if the profile is not defined and the selection is one piping object, take its profile for elbow if OD==thk==None and hasattr(objEx.Object,'PType') and objEx.Object.PType in ['Pipe','Elbow','Cap','Reduct']: DN=objEx.Object.PSize OD=objEx.Object.OD thk=objEx.Object.thk PRating=objEx.Object.PRating # if the object is a beam or pipe, append it to the "things".. if len(frameCmd.beams([objEx.Object]))==1: things.append(objEx.Object) else: # ..else append its edges for edge in frameCmd.edges([objEx]): things.append(edge) if len(things)>=2: break FreeCAD.activeDocument().openTransaction('Insert elbow on intersection') try: #create the feature if None in [DN,OD,thk,PRating]: propList=[d['PSize'],float(pq(d['OD'])),float(pq(d['thk'])),ang,float(pq(d['BendRadius']))] self.lastElbow=pipeCmd.makeElbowBetweenThings(*things[:2],propList=propList) self.lastElbow.PRating=self.ratingList.item(self.ratingList.currentRow()).text() else: for prop in self.pipeDictList: if prop['PSize']==DN: BR=float(pq(prop['BendRadius'])) if BR==None: BR=1.5*OD/2 propList=[DN,OD,thk,ang,BR] self.lastElbow=pipeCmd.makeElbowBetweenThings(*things[:2],propList=propList) self.lastElbow.PRating=PRating if self.combo.currentText()!='<none>': pipeCmd.moveToPyLi(self.lastElbow,self.combo.currentText()) except: FreeCAD.Console.PrintError('Creation of elbow is failed\n') FreeCAD.activeDocument().commitTransaction() #### FreeCAD.activeDocument().recompute()