def accept(self): # extend if self.target != None and len(frameCmd.beams()) > 0: FreeCAD.activeDocument().openTransaction('Extend beam') for beam in frameCmd.beams(): frameCmd.extendTheBeam(beam, self.target) FreeCAD.activeDocument().recompute() FreeCAD.activeDocument().commitTransaction()
def accept(self): # extend if self.target!=None and len(frameCmd.beams())>0: FreeCAD.activeDocument().openTransaction('Extend beam') for beam in frameCmd.beams(): frameCmd.extendTheBeam(beam,self.target) FreeCAD.activeDocument().recompute() FreeCAD.activeDocument().commitTransaction()
def addSelection(self, doc, obj, sub, pnt): lastSel = FreeCAD.getDocument(doc).getObject(obj) subLastSel = lastSel.Shape.getElement(sub) if lastSel.TypeId == 'Part::FeaturePython' and hasattr( lastSel, "Height") and subLastSel.ShapeType == "Edge": self.edges.append(subLastSel) self.beams.append(lastSel) FreeCAD.Console.PrintMessage('Edge/beam pair nr.' + str(len(self.edges)) + ' selected.\n') if (len(self.edges) == len(self.beams) == 2): if frameCmd.isOrtho(*self.edges): self.beams.reverse() FreeCAD.ActiveDocument.openTransaction('Adjust angle') for i in range(len(self.edges)): frameCmd.extendTheBeam(self.beams[i], self.edges[i]) FreeCAD.ActiveDocument.commitTransaction() FreeCAD.Console.PrintWarning("Adjustment executed.\n") else: FreeCAD.Console.PrintError("Edges must be orthogonal.\n") self.edges = [] self.beams = [] FreeCADGui.Selection.clearSelection() FreeCAD.activeDocument().recompute() FreeCAD.Console.PrintWarning("Repeat selection or press [ESC]\n")
def update(self, fp, edges=None): import pipeCmd, frameCmd from DraftVecUtils import rounded from math import degrees if not edges and hasattr(fp.Base, 'Shape'): edges = fp.Base.Shape.Edges if not edges: FreeCAD.Console.PrintError('Base has not valid edges\n') return pipes = list() for e in edges: #---Create the tube--- p = pipeCmd.makePipe([fp.PSize, fp.OD, fp.thk, e.Length], pos=e.valueAt(0), Z=e.tangentAt(0)) p.PRating = fp.PRating p.PSize = fp.PSize pipeCmd.moveToPyLi(p, fp.Label) pipes.append(p) n = len(pipes) - 1 if n and not frameCmd.isParallel(frameCmd.beamAx(pipes[n]), frameCmd.beamAx(pipes[n - 1])): #---Create the curve--- propList = [fp.PSize, fp.OD, fp.thk, 90, fp.BendRadius] c = pipeCmd.makeElbowBetweenThings(edges[n], edges[n - 1], propList) portA, portB = [c.Placement.multVec(port) for port in c.Ports] #---Trim the tube--- p1, p2 = pipes[-2:] frameCmd.extendTheBeam(p1, portA) frameCmd.extendTheBeam(p2, portB) pipeCmd.moveToPyLi(c, fp.Label)
def update(self,fp,edges=None): import pipeCmd, frameCmd from DraftVecUtils import rounded from math import degrees if not edges and hasattr(fp.Base,'Shape'): edges=fp.Base.Shape.Edges if not edges: FreeCAD.Console.PrintError('Base has not valid edges\n') return pipes=list() for e in edges: #---Create the tube--- p=pipeCmd.makePipe([fp.PSize,fp.OD,fp.thk,e.Length],pos=e.valueAt(0),Z=e.tangentAt(0)) p.PRating=fp.PRating p.PSize=fp.PSize pipeCmd.moveToPyLi(p,fp.Label) pipes.append(p) n=len(pipes)-1 if n and not frameCmd.isParallel(frameCmd.beamAx(pipes[n]),frameCmd.beamAx(pipes[n-1])): #---Create the curve--- propList=[fp.PSize,fp.OD,fp.thk,90,fp.BendRadius] c=pipeCmd.makeElbowBetweenThings(edges[n],edges[n-1],propList) if c: portA,portB=[c.Placement.multVec(port) for port in c.Ports] #---Trim the tube--- p1,p2=pipes[-2:] frameCmd.extendTheBeam(p1,portA) frameCmd.extendTheBeam(p2,portB) pipeCmd.moveToPyLi(c,fp.Label)
def addSelection(self,doc,obj,sub,pnt): lastSel=FreeCAD.getDocument(doc).getObject(obj) subLastSel=lastSel.Shape.getElement(sub) if lastSel.TypeId=='Part::FeaturePython' and hasattr(lastSel,"Height") and self.target!=None: frameCmd.extendTheBeam(lastSel,self.target) if self.target==None and subLastSel.ShapeType in ["Edge","Face","Vertex"]: self.target=subLastSel FreeCAD.Console.PrintMessage('Target selected.\n')
def makeElbowBetweenThings(thing1=None, thing2=None, propList=None): ''' makeElbowBetweenThings(thing1, thing2, propList=None): Place one elbow at the intersection of thing1 and thing2. Things can be any combination of intersecting beams, pipes or edges. If nothing is passed as argument, the function attempts to take the first two edges selected in the view. propList is one optional list with 5 elements: DN (string): nominal diameter OD (float): outside diameter thk (float): shell thickness BA (float): bend angle - that will be recalculated! - BR (float): bend radius Default is "DN50 (SCH-STD)" Remember: property PRating must be defined afterwards ''' if not (thing1 and thing2): thing1, thing2 = frameCmd.edges()[:2] P = frameCmd.intersectionCLines(thing1, thing2) directions = list() try: for thing in [thing1, thing2]: if frameCmd.beams([thing]): directions.append( rounded( (frameCmd.beamAx(thing).multiply(thing.Height / 2) + thing.Placement.Base) - P)) elif hasattr(thing, 'ShapeType') and thing.ShapeType == 'Edge': directions.append(rounded(thing.CenterOfMass - P)) except: return None ang = 180 - degrees(directions[0].getAngle(directions[1])) if ang == 0 or ang == 180: return None if not propList: propList = ["DN50", 60.3, 3.91, ang, 45.24] else: propList[3] = ang elb = makeElbow(propList, P, directions[0].negative().cross(directions[1].negative())) # mate the elbow ends with the pipes or edges b = frameCmd.bisect(directions[0], directions[1]) elbBisect = rounded(frameCmd.beamAx(elb, FreeCAD.Vector( 1, 1, 0))) #if not rounded, fail in plane xz rot = FreeCAD.Rotation(elbBisect, b) elb.Placement.Rotation = rot.multiply(elb.Placement.Rotation) # trim the adjacent tubes #FreeCAD.activeDocument().recompute() # may delete this row? portA = elb.Placement.multVec(elb.Ports[0]) portB = elb.Placement.multVec(elb.Ports[1]) for tube in [t for t in [thing1, thing2] if frameCmd.beams([t])]: vectA = tube.Shape.Solids[0].CenterOfMass - portA vectB = tube.Shape.Solids[0].CenterOfMass - portB if frameCmd.isParallel(vectA, frameCmd.beamAx(tube)): frameCmd.extendTheBeam(tube, portA) else: frameCmd.extendTheBeam(tube, portB) return elb
def addSelection(self, doc, obj, sub, pnt): lastSel = FreeCAD.getDocument(doc).getObject(obj) subLastSel = lastSel.Shape.getElement(sub) if lastSel.TypeId == 'Part::FeaturePython' and hasattr( lastSel, "Height") and self.target != None: frameCmd.extendTheBeam(lastSel, self.target) if self.target == None and subLastSel.ShapeType in [ "Edge", "Face", "Vertex" ]: self.target = subLastSel FreeCAD.Console.PrintMessage('Target selected.\n')
def trim(self): if len(frameCmd.beams())==1: pipe=frameCmd.beams()[0] comPipeEdges=[e.CenterOfMass for e in pipe.Shape.Edges] eds=[e for e in frameCmd.edges() if not e.CenterOfMass in comPipeEdges] FreeCAD.activeDocument().openTransaction('Trim pipes') for edge in eds: frameCmd.extendTheBeam(frameCmd.beams()[0],edge) FreeCAD.activeDocument().commitTransaction() FreeCAD.activeDocument().recompute() else: FreeCAD.Console.PrintError("Wrong selection\n")
def update(self, fp, edges=None): import pipeCmd, frameCmd from DraftVecUtils import rounded from math import degrees if not edges and hasattr(fp.Base, 'Shape'): edges = fp.Base.Shape.Edges if not edges: FreeCAD.Console.PrintError('Base has not valid edges\n') return pipes = list() for e in edges: #---Create the tube--- p = pipeCmd.makePipe([fp.PSize, fp.OD, fp.thk, e.Length], pos=e.valueAt(0), Z=e.tangentAt(0)) p.PRating = fp.PRating p.PSize = fp.PSize pipeCmd.moveToPyLi(p, fp.Label) pipes.append(p) n = len(pipes) - 1 if n and not frameCmd.isParallel(frameCmd.beamAx(pipes[n]), frameCmd.beamAx(pipes[n - 1])): #---Create the curve: method 1--- #P=rounded(frameCmd.intersectionCLines(pipes[n-1],pipes[n])) #alternative -> P=pipes[n].Placement.Base #dir1=rounded((frameCmd.beamAx(pipes[n-1]).multiply(pipes[n-1].Height/2)+pipes[n-1].Placement.Base)-P).normalize() #dir2=rounded((frameCmd.beamAx(pipes[n]).multiply(pipes[n].Height/2)+pipes[n].Placement.Base)-P).normalize() #ang=180.0-degrees(dir1.getAngle(dir2)) #propList=[fp.PSize,fp.OD,fp.thk,ang,fp.BendRadius] #c=pipeCmd.makeElbow(propList,P,dir1.negative().cross(dir2.negative())) #elbBisect=rounded(frameCmd.beamAx(c,FreeCAD.Vector(1,1,0))).normalize() # if not rounded, it fails with linux when sketch is vertical!(?) #rot=FreeCAD.Rotation(elbBisect,frameCmd.bisect(dir1,dir2)) #c.Placement.Rotation=rot.multiply(c.Placement.Rotation) #---Create the curve: method 2--- propList = [fp.PSize, fp.OD, fp.thk, 90, fp.BendRadius] c = pipeCmd.makeElbowBetweenThings( edges[n], edges[n - 1], propList) #before was ...(p1,p2,propList) portA = c.Placement.multVec(c.Ports[0]) portB = c.Placement.multVec(c.Ports[1]) #---Trim the tube: method 1--- #for tube in pipes[-2:]: # vectA=c.Placement.Rotation.multVec(c.Ports[0]) # if frameCmd.isParallel(vectA,frameCmd.beamAx(tube)): # frameCmd.extendTheBeam(tube,portA) # else: # frameCmd.extendTheBeam(tube,portB) #---Trim the tube: method 2--- p1, p2 = pipes[-2:] frameCmd.extendTheBeam(p1, portA) frameCmd.extendTheBeam(p2, portB) pipeCmd.moveToPyLi(c, fp.Label)
def Activated(self): import frameCmd, pipeCmd if len(frameCmd.beams()) > 1: p1, p2 = frameCmd.beams()[:2] try: P = frameCmd.intersectionCLines(p1, p2) com1 = p1.Shape.Solids[0].CenterOfMass com2 = p2.Shape.Solids[0].CenterOfMass v1 = P - com1 v2 = com2 - P curves = [ e for e in FreeCADGui.Selection.getSelection() if hasattr(e, 'PType') and hasattr(e, 'BendAngle') ] if curves: FreeCAD.ActiveDocument.openTransaction('Place one curve') pipeCmd.placeoTherElbow(curves[0], v1, v2, P) FreeCAD.ActiveDocument.recompute( ) # recompute for the elbow port1, port2 = pipeCmd.portsPos(curves[0]) if (com1 - port1).Length < (com1 - port2).Length: frameCmd.extendTheBeam(p1, port1) frameCmd.extendTheBeam(p2, port2) else: frameCmd.extendTheBeam(p1, port2) frameCmd.extendTheBeam(p2, port1) FreeCAD.ActiveDocument.recompute( ) # recompute for the pipes FreeCAD.ActiveDocument.commitTransaction() else: FreeCAD.Console.PrintError('Select at least one elbow') except: FreeCAD.Console.PrintError('Intersection point not found\n') else: FreeCAD.Console.PrintError('Select two intersecting pipes\n')
def Activated (self): import frameCmd, pipeCmd if len(frameCmd.beams())>1: p1,p2=frameCmd.beams()[:2] try: P=frameCmd.intersectionCLines(p1,p2) com1=p1.Shape.Solids[0].CenterOfMass com2=p2.Shape.Solids[0].CenterOfMass v1=P-com1 v2=com2-P curves=[e for e in FreeCADGui.Selection.getSelection() if hasattr(e,'PType') and hasattr(e,'BendAngle')] if curves: FreeCAD.ActiveDocument.openTransaction('Place one curve') pipeCmd.placeoTherElbow(curves[0],v1,v2,P) FreeCAD.ActiveDocument.recompute() # recompute for the elbow port1,port2=pipeCmd.portsPos(curves[0]) if (com1-port1).Length<(com1-port2).Length: frameCmd.extendTheBeam(p1,port1) frameCmd.extendTheBeam(p2,port2) else: frameCmd.extendTheBeam(p1,port2) frameCmd.extendTheBeam(p2,port1) FreeCAD.ActiveDocument.recompute() # recompute for the pipes FreeCAD.ActiveDocument.commitTransaction() else: FreeCAD.Console.PrintError('Select at least one elbow') except: FreeCAD.Console.PrintError('Intersection point not found\n') else: FreeCAD.Console.PrintError('Select two intersecting pipes\n')
def extendTheTubes2intersection(pipe1=None,pipe2=None,both=True): ''' Does what it says; also with beams. If arguments are None, it picks the first 2 selected beams(). ''' if not (pipe1 and pipe2): try: pipe1,pipe2=frameCmd.beams()[:2] except: FreeCAD.Console.PrintError('Insufficient arguments for extendTheTubes2intersection\n') P=frameCmd.intersectionCLines(pipe1,pipe2) if P!=None: frameCmd.extendTheBeam(pipe1,P) if both: frameCmd.extendTheBeam(pipe2,P)
def addSelection(self,doc,obj,sub,pnt): lastSel=FreeCAD.getDocument(doc).getObject(obj) subLastSel=lastSel.Shape.getElement(sub) if lastSel.TypeId=='Part::FeaturePython' and hasattr(lastSel,"Height") and subLastSel.ShapeType=="Edge": self.edges.append(subLastSel) self.beams.append(lastSel) FreeCAD.Console.PrintMessage('Edge/beam pair nr.'+str(len(self.edges))+' selected.\n') if (len(self.edges)==len(self.beams)==2): if frameCmd.isOrtho(*self.edges): self.beams.reverse() FreeCAD.ActiveDocument.openTransaction('Adjust angle') for i in range(len(self.edges)): frameCmd.extendTheBeam(self.beams[i],self.edges[i]) FreeCAD.ActiveDocument.commitTransaction() FreeCAD.Console.PrintWarning("Adjustment executed.\n") else: FreeCAD.Console.PrintError("Edges must be orthogonal.\n") self.edges=[] self.beams=[] FreeCADGui.Selection.clearSelection() FreeCAD.activeDocument().recompute() FreeCAD.Console.PrintWarning("Repeat selection or press [ESC]\n")