Python FreeCAD.Rotation() Examples
The following are 30
code examples of FreeCAD.Rotation().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
FreeCAD
, or try the search function
.
Example #1
Source File: Animation.py From Animation with GNU General Public License v2.0 | 7 votes |
def rot(self,angle=0): FreeCAD.uu=self #say("rotate " + str(self.obj2.Label) + " angle=" +str(angle)) if self.obj2.ModeMotion =='Vector': #say(self.obj2.vectorMotion) a=FreeCAD.Placement() a.Base=self.obj2.vectorMotion zzz=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),angle) r=FreeCAD.Placement() r.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),angle) a2=r.multiply(a) self.obj2.vectorMotion=a2.Base FreeCAD.ActiveDocument.recompute() # self.obj2.vectorMotion=multiply(self.obj2.vectorMotion) #say(self.obj2.vectorMotion)
Example #2
Source File: friki.py From videoblog with GNU General Public License v2.0 | 7 votes |
def orientate(part, v, vref = FreeCAD.Vector(0, 0, 1)): #-- Special cases. Null vector. Ignore if v.Length == 0: return #-- Special case: Vector in the z axis, poiting to the negative if v.x == 0 and v.y==0 and v.z < 0: raxis = App.Vector(1, 0, 0) else: raxis = vref.cross(v) #-- Calculate the rotation angle (in degrees) angle = math.degrees(vref.getAngle(v)) #-- Rotate vectz! part.Placement.Rotation = FreeCAD.Rotation(raxis, angle) #-- Change the color to blue
Example #3
Source File: assembly.py From FreeCAD_assembly3 with GNU General Public License v3.0 | 7 votes |
def doFlip(obj, info, flipElement): if QtGui.QApplication.keyboardModifiers()==QtCore.Qt.ControlModifier: rot = FreeCAD.Rotation(FreeCAD.Vector(0,1,0),180) else: rot = FreeCAD.Rotation(FreeCAD.Vector(1,0,0),180) rot = FreeCAD.Placement(FreeCAD.Vector(), rot) FreeCAD.setActiveTransaction( 'Flip element' if flipElement else 'Flip part') try: if flipElement: obj.Offset = rot.multiply(obj.Offset) else: offset = utils.getElementPlacement(obj.getSubObject('')) offset = offset.multiply(rot).multiply(offset.inverse()) setPlacement(info.Part, offset.multiply(info.Placement)) obj.recompute(True) FreeCAD.closeActiveTransaction() except Exception: FreeCAD.closeActiveTransaction(True) raise
Example #4
Source File: HelicalSweepFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 7 votes |
def make_profile_sketch(self): import Sketcher sk = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Profile') sk.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(0,0,0,1)) sk.MapMode = "Deactivated" sk.addGeometry(Part.LineSegment(FreeCAD.Vector(100.0,0.0,0),FreeCAD.Vector(127.0,12.0,0)),False) sk.addConstraint(Sketcher.Constraint('PointOnObject',0,1,-1)) sk.addGeometry(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(125.0,17.0,0),FreeCAD.Vector(0,0,1),5.8),-1.156090,1.050925),False) sk.addConstraint(Sketcher.Constraint('Tangent',0,2,1,1)) sk.addGeometry(Part.LineSegment(FreeCAD.Vector(128.0,22.0,0),FreeCAD.Vector(100.0,37.0,0)),False) sk.addConstraint(Sketcher.Constraint('Tangent',1,2,2,1)) sk.addConstraint(Sketcher.Constraint('Vertical',0,1,2,2)) sk.addConstraint(Sketcher.Constraint('DistanceY',0,1,2,2,37.5)) sk.setDatum(4,FreeCAD.Units.Quantity('35.000000 mm')) sk.renameConstraint(4, u'Lead') sk.setDriving(4,False) sk.addConstraint(Sketcher.Constraint('Equal',2,0)) FreeCAD.ActiveDocument.recompute() return sk
Example #5
Source File: a2p_rigid.py From A2plus with GNU Lesser General Public License v2.1 | 6 votes |
def beautyDOFPrint(self): ''' pretty print output that describe the current DOF of the rigid ''' Msg('\n') Msg(u"Current Rigid = {}\n".format(self.label) ) if self.fixed: Msg(u" is Fixed\n") else: Msg(u" is not Fixed and has {} DegreesOfFreedom\n".format(self.currentDOF())) for rig in self.depsPerLinkedRigids.keys(): Msg(u" Depends on Rigid = {}\n".format(rig.label)) for dep in self.depsPerLinkedRigids[rig]: Msg(u" {}\n".format(dep) ) Msg(u" DOF Position free with this rigid = {}\n".format( len(self.dofPOSPerLinkedRigids[rig]))) Msg(u" DOF Rotation free with this rigid = {}\n".format( len(self.dofROTPerLinkedRigids[rig])))
Example #6
Source File: Numpy.py From NodeEditor with MIT License | 6 votes |
def zipRotation( x=('FloatPin', [0],{PinSpecifires.ENABLED_OPTIONS: PinOptions.ArraySupported}), y=('FloatPin', [1],{PinSpecifires.ENABLED_OPTIONS: PinOptions.ArraySupported}), z=('FloatPin', [2],{PinSpecifires.ENABLED_OPTIONS: PinOptions.ArraySupported}), angle=('FloatPin', [2],{PinSpecifires.ENABLED_OPTIONS: PinOptions.ArraySupported}) ) : """combine axis(x,y,z) and angle lists to a list of rotations""" res=np.array([x,y,z]).swapaxes(0,1) rots=[FreeCAD.Rotation(FreeCAD.Vector(list(a)),b) for a,b in zip(res,angle)] return rots # @staticmethod # @IMPLEMENT_NODE(returns=('RotationPin', [],{'constraint': '1', "enabledOptions": PinOptions.ArraySupported | PinOptions.AllowAny}), meta={'Category': 'numpy|array', 'Keywords': ['list','random']}) # def zipPlacement( # Base=('FloatPin', []),Rotation=('FloatPin', [])) : # """combine """ # # pms=[FreeCAD.Placement(base,rot) for base,rot in zip(Base,Rotation)] # return pms
Example #7
Source File: frameFeatures.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def makeSingle(self): FreeCAD.activeDocument().openTransaction('Insert Single Struct') if self.SType=='<by sketch>': profile=FreeCAD.ActiveDocument.getObjectsByLabel(self.form.listSizes.currentItem().text())[0] else: prop=self.sectDictList[self.form.listSizes.currentRow()] profile=newProfile(prop) if frameCmd.faces(): Z=FreeCAD.Vector(0,0,1) for f in frameCmd.faces(): beam=makeStructure(profile) beam.Placement=FreeCAD.Placement(f.CenterOfMass,FreeCAD.Rotation(Z,f.normalAt(0,0))) if self.form.editLength.text(): beam.Height=float(self.form.editLength.text()) else: for e in frameCmd.edges(): beam=makeStructure(profile) frameCmd.placeTheBeam(beam,e) if self.form.editLength.text(): beam.Height=float(self.form.editLength.text()) FreeCAD.ActiveDocument.recompute()
Example #8
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def join(obj1,port1,obj2,port2): ''' join(obj1,port1,obj2,port2) \t obj1, obj2 = two "Pype" parts \t port1, port2 = their respective ports to join ''' if hasattr(obj1,'PType') and hasattr(obj2,'PType'): if port1>len(obj1.Ports)-1 or port2>len(obj2.Ports)-1: FreeCAD.Console.PrintError('Wrong port(s) number\n') else: v1=portsDir(obj1)[port1] v2=portsDir(obj2)[port2] rot=FreeCAD.Rotation(v2,v1.negative()) obj2.Placement.Rotation=rot.multiply(obj2.Placement.Rotation) p1=portsPos(obj1)[port1] p2=portsPos(obj2)[port2] obj2.Placement.move(p1-p2) else: FreeCAD.Console.PrintError('Object(s) are not pypes\n')
Example #9
Source File: frameForms.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def getLength(self): roundDigits=3 if len(frameCmd.edges())>0: edge=frameCmd.edges()[0] self.form.edit4.setText(str(edge.Length)) self.form.edit5.setText('1') dx,dy,dz=list(edge.tangentAt(0)) self.form.edit1.setText(str(round(dx,roundDigits))) self.form.edit2.setText(str(round(dy,roundDigits))) self.form.edit3.setText(str(round(dz,roundDigits))) FreeCADGui.Selection.clearSelection() self.deleteArrow() from polarUtilsCmd import arrow where=FreeCAD.Placement() where.Base=edge.valueAt(0) where.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),edge.tangentAt(0)) size=[edge.Length/20.0,edge.Length/10.0,edge.Length/20.0] self.arrow=arrow(pl=where,scale=size,offset=edge.Length/2.0)
Example #10
Source File: frameForms.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def selectAction(self): edged = [objex for objex in FreeCADGui.Selection.getSelectionEx() if frameCmd.edges([objex])] if edged: self.Axis=frameCmd.edges([edged[0]])[0] self.deleteArrow() from polarUtilsCmd import arrow where=FreeCAD.Placement() where.Base=self.Axis.valueAt(self.Axis.LastParameter) where.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),self.Axis.tangentAt(self.Axis.LastParameter)) size=[self.Axis.Length/20.0,self.Axis.Length/10.0,self.Axis.Length/20.0] self.arrow=arrow(pl=where,scale=size,offset=self.Axis.Length/10.0) if self.Axis.curvatureAt(0): O=self.Axis.centerOfCurvatureAt(0) n=self.Axis.tangentAt(0).cross(self.Axis.normalAt(0)) from Part import Edge, Line self.Axis=(Edge(Line(FreeCAD.Vector(O),FreeCAD.Vector(O+n)))) self.form.lab1.setText(edged[0].Object.Label+": edge")
Example #11
Source File: anyShape.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def makeThing(n='Valvola', fn='ballDN15.stp', p='0:0:0', pos=None, Z=None): ''' makeThing(n,fn,p,pos,Z) n = name fn = file name p = ports string (e.g. "0:0:0/0:0:69") pos = position Vector Z = orientation Vector ''' if pos==None: pos=FreeCAD.Vector(0,0,0) if Z==None: Z=FreeCAD.Vector(0,0,1) a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython",n) AnyThing(a, name=n, fileName=fn, ports=p) a.ViewObject.Proxy=0 a.Placement.Base=pos rot=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),Z) a.Placement.Rotation=rot.multiply(a.Placement.Rotation) return a
Example #12
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def placeoTherElbow(c,v1=None,v2=None,P=None): ''' Like placeTheElbow() but with more math. ''' if not (v1 and v2): v1,v2=[e.tangentAt(0) for e in frameCmd.edges()] try: P=frameCmd.intersectionCLines(*frameCmd.edges()) except: pass if hasattr(c,'PType') and hasattr(c,'BendAngle') and v1 and v2: v1.normalize() v2.normalize() ortho=rounded(frameCmd.ortho(v1,v2)) bisect=rounded(v2-v1) cBisect=rounded(c.Ports[1].normalize()+c.Ports[0].normalize()) # math cZ=c.Ports[0].cross(c.Ports[1]) # more math ang=degrees(v1.getAngle(v2)) c.BendAngle=ang rot1=FreeCAD.Rotation(rounded(frameCmd.beamAx(c,cZ)),ortho) c.Placement.Rotation=rot1.multiply(c.Placement.Rotation) rot2=FreeCAD.Rotation(rounded(frameCmd.beamAx(c,cBisect)),bisect) c.Placement.Rotation=rot2.multiply(c.Placement.Rotation) if not P: P=c.Placement.Base c.Placement.Base=P
Example #13
Source File: a2p_rigid.py From A2plus with GNU Lesser General Public License v2.1 | 6 votes |
def applySolution(self, doc, solver): if self.tempfixed or self.fixed: return # Update FreeCAD's placements if deltaPlacement above Tolerances base1 = self.placement.Base base2 = self.savedPlacement.Base absPosMove = base1.sub(base2).Length axis1 = self.placement.Rotation.Axis axis2 = self.savedPlacement.Rotation.Axis angle = math.degrees(axis2.getAngle(axis1)) ''' if absPosMove >= solver.mySOLVER_POS_ACCURACY*1e-2 or angle >= solver.mySOLVER_SPIN_ACCURACY*1e-2: ob1 = doc.getObject(self.objectName) ob1.Placement = self.placement ''' ob1 = doc.getObject(self.objectName) ob1.Placement = self.placement
Example #14
Source File: NiCrSimMachine.py From NiCr with GNU General Public License v2.0 | 6 votes |
def onChanged(self, fp, prop): try: if prop == 'XLength' or prop == 'YLength' or prop == 'ZLength' or prop == 'FrameDiameter': self.addMachineToDocument( fp.FrameDiameter, fp.XLength, fp.YLength, fp.ZLength ) if prop == 'ReturnHome' and fp.ReturnHome: # reset machine position homePlm = FreeCAD.Placement(FreeCAD.Vector(0,0,0), FreeCAD.Rotation(FreeCAD.Vector(0,0,0),0)) FreeCAD.ActiveDocument.getObject('XA').Placement = homePlm FreeCAD.ActiveDocument.getObject('XB').Placement = homePlm FreeCAD.ActiveDocument.getObject('YA').Placement = homePlm FreeCAD.ActiveDocument.getObject('YB').Placement = homePlm fp.ReturnHome = False if prop == 'HideWireTrajectory': for obj in FreeCAD.ActiveDocument.WireTrajectory.Group: obj.ViewObject.Visibility = fp.HideWireTrajectory + 1 if prop == 'HideWire': FreeCAD.ActiveDocument.Wire.ViewObject.Visibility = fp.HideWire + 1 except AttributeError: pass
Example #15
Source File: geomUtils.py From qmt with MIT License | 6 votes |
def makeBB(BB): """Make a bounding box given BB tuple. Parameters ---------- BB : Returns ------- box """ doc = FreeCAD.ActiveDocument xMin, xMax, yMin, yMax, zMin, zMax = BB box = doc.addObject("Part::Box") centerVector = vec(xMin, yMin, zMin) box.Placement = FreeCAD.Placement( centerVector, FreeCAD.Rotation(vec(0.0, 0.0, 0.0), 0.0) ) box.Length = xMax - xMin box.Width = yMax - yMin box.Height = zMax - zMin doc.recompute() return box
Example #16
Source File: frameCmd.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def pivotTheBeam(ang=90, edge=None, beam=None): #OBSOLETE: replaced with rotateTheBeamAround ''' pivotTheBeam(ang=90) Rotates the selected object around the selected pivot (one of its edges) by ang degrees. ''' #if len(edges())!=1: # FreeCAD.Console.PrintError('Wrong selection\n') # return None if not (edge and beam): try: edge=edges()[0] beam=FreeCADGui.Selection.getSelection()[0] except: return rot=FreeCAD.Rotation(edge.tangentAt(0),ang) beam.Placement.Rotation=rot.multiply(beam.Placement.Rotation) edgePost=edges()[0] #save position for revert dist=edge.CenterOfMass-edgePost.CenterOfMass beam.Placement.move(dist)
Example #17
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def shapeReferenceAxis(obj=None, axObj=None): # function to get the reference axis of the shape for rotateTheTubeAx() # used in rotateTheTubeEdge() and pipeForms.rotateForm().getAxis() ''' shapeReferenceAxis(obj, axObj) Returns the direction of an axis axObj according the original Shape orientation of the object obj If arguments are None axObj is the normal to one circular edge selected and obj is the object selected. ''' if obj==None and axObj==None: selex=FreeCADGui.Selection.getSelectionEx() if len(selex)==1 and len(selex[0].SubObjects)>0: sub=selex[0].SubObjects[0] if sub.ShapeType=='Edge' and sub.curvatureAt(0)>0: axObj=sub.tangentAt(0).cross(sub.normalAt(0)) obj=selex[0].Object X=obj.Placement.Rotation.multVec(FreeCAD.Vector(1,0,0)).dot(axObj) Y=obj.Placement.Rotation.multVec(FreeCAD.Vector(0,1,0)).dot(axObj) Z=obj.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1)).dot(axObj) axShapeRef=FreeCAD.Vector(X,Y,Z) return axShapeRef
Example #18
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 6 votes |
def portsDir(o): ''' portsDir(o) Returns the orientation of Ports of the pype-object o ''' dirs=list() two_ways=['Pipe','Reduct','Flange'] if hasattr(o,'PType'): if o.PType in two_ways: dirs=[o.Placement.Rotation.multVec(p) for p in [FreeCAD.Vector(0,0,-1),FreeCAD.Vector(0,0,1)]] elif hasattr(o,'Ports') and hasattr(o,'Placement'): dirs=list() for p in o.Ports: if p.Length: dirs.append(rounded(o.Placement.Rotation.multVec(p).normalize())) else: dirs.append(rounded(o.Placement.Rotation.multVec(FreeCAD.Vector(0,0,-1)).normalize())) return dirs ################## COMMANDS ########################
Example #19
Source File: Kartan.py From Animation with GNU General Public License v2.0 | 5 votes |
def rotcross(part,alpha,phi): phi2=math.atan(math.cos(alpha*math.pi/180)*math.tan(phi*math.pi/180))*180/math.pi print(phi,phi2) rot = App.Rotation(App.Vector(0,0,1), phi) wy=rot.multVec(App.Vector(0,1,0)) rot2 = App.Rotation(App.Vector(0,0,1), phi2) wx1=rot2.multVec(App.Vector(1,0,0)) if phi <90 or phi>270: alpha=-alpha rotalpha=FreeCAD.Rotation(App.Vector(0,1,0), alpha) wx=rotalpha.multVec(wx1) r=(wx.x**2+wx.y**2)**0.5 beta=math.acos(r)*180/math.pi p1=FreeCAD.Placement() phi2=phi p1.Rotation=FreeCAD.Rotation(App.Vector(0,0,1),phi2) p2=FreeCAD.Placement() if 90<phi and phi<270: beta=-beta p2.Rotation=FreeCAD.Rotation(wy,beta) part.Placement=p2.multiply(p1) App.ActiveDocument.recompute()
Example #20
Source File: kicad.py From fcad_pcb with MIT License | 5 votes |
def _place(self,obj,pos,angle=None): if not self.add_feature: if angle: obj.rotate(Vector(),Vector(0,0,1),angle) obj.translate(pos) else: r = Rotation(Vector(0,0,1),angle) if angle else Rotation() obj.Placement = Placement(pos,r) obj.purgeTouched()
Example #21
Source File: Kartan.py From Animation with GNU General Public License v2.0 | 5 votes |
def onChanged(self,obj,prop): say("** onChanged " +str(obj.Label) + " " + prop) if prop=="Proxy": FreeCAD.animataionInit=True say("animation Init start!!!!!!!!!!!!!!!") if prop=="Label": FreeCAD.animataionInit=False say("Animation init beendet ---------------!!") if FreeCAD.animataionInit: say("erster Durchlauf - nix machen") return if hasattr(FreeCAD,"animationLock"): say(FreeCAD.animationLock) if FreeCAD.animationLock: say("Ende wegen Lock") return else: say("noch kein animation Lock") FreeCAD.animationLock=True say("------------------------------***Lock EIN") FreeCAD.mytoc=[self,obj,prop] if hasattr(FreeCAD,"animation"): oldval=FreeCAD.animation['changed'][2] val=obj.getPropertyByName(prop) say(prop + " old:" + str(oldval) + " new:" + str(val)) if prop=='obj': obj.obj.Links=[obj.objAxis1,obj.objAxis2,obj.objCross] if prop=='duration' or prop=='start': obj.end=obj.start+obj.duration if prop=='angleZenit': obj.objAxis2.Placement.Rotation.Angle=obj.angleZenit/180*math.pi FreeCAD.animationLock=False FreeCAD.activeDocument().recompute() say("******************************Lock aus")
Example #22
Source File: animplacement.py From Animation with GNU General Public License v2.0 | 5 votes |
def update(self): say("update ") import math time=self.obj2.time say(str(time)) x0=self.obj2.x0 x1=self.obj2.x1 y0=self.obj2.y0 y1=self.obj2.y1 z0=self.obj2.z0 z1=self.obj2.z1 arc0=self.obj2.arc0 arc1=self.obj2.arc1 try: sx=self.obj2.src.Placement.Base.x sy=self.obj2.src.Placement.Base.y sz=self.obj2.src.Placement.Base.z srx=self.obj2.src.Placement.Rotation.Axis.x sry=self.obj2.src.Placement.Rotation.Axis.y srz=self.obj2.src.Placement.Rotation.Axis.z sarc=self.obj2.src.Placement.Rotation.Angle except: saye("keine src festgelegt") xv=eval(self.obj2.x) yv=eval(self.obj2.y) zv=eval(self.obj2.z) arcv=eval(self.obj2.arc) rot=FreeCAD.Rotation(self.obj2.RotAxis,arcv) pl=FreeCAD.Placement(FreeCAD.Vector(xv,yv,zv),rot,self.obj2.RotCenter) say(pl) if str(self.obj2.target.TypeId) == 'App::Annotation': self.obj2.target.Position=(xv,yv,zv) else: self.obj2.target.Placement=pl self.obj2.Placement=pl
Example #23
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def attachToTube(port=None): pypes=[p for p in FreeCADGui.Selection.getSelection() if hasattr(p,'PType')] tube=None try: tubes=[t for t in pypes if t.PType=='Pipe'] if tubes: tube=tubes[0] pypes.pop(pypes.index(tube)) for p in pypes: p.MapMode = 'Concentric' if not port: port=tube.Proxy.nearestPort(p.Shape.Solids[0].CenterOfMass)[0] if port==0: if p.PType!='Flange': p.MapReversed = True else: p.MapReversed = False p.Support = [(tube,'Edge3')] elif port==1: if p.PType!='Flange': p.MapReversed = False else: p.MapReversed = True p.Support = [(tube,'Edge1')] if p.PType=='Elbow': p.AttachmentOffset = FreeCAD.Placement(FreeCAD.Vector(0, 0, p.Ports[0].Length), FreeCAD.Rotation(p.Ports[1],FreeCAD.Vector(0, 0, 1).negative())) FreeCAD.Console.PrintMessage('%s attached to %s\n' %(p.Label,tube.Label)) else: for p in pypes: p.MapMode='Deactivated' FreeCAD.Console.PrintMessage('Object Detached\n') except: FreeCAD.Console.PrintError('Nothing attached\n')
Example #24
Source File: polarUtilsCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def moveto(self,pl): import FreeCAD self.Placement=pl self.transform.translation.setValue(tuple(self.Placement.Base)) self.transform.rotation.setValue(tuple(self.Placement.Rotation.Q))
Example #25
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def makeValve(propList=[], pos=None, Z=None): '''add a Valve object makeValve(propList,pos,Z); propList is one optional list with at least 4 elements: DN (string): nominal diameter VType (string): type of valve OD (float): outside diameter ID (float): inside diameter H (float): length of pipe Kv (float): valve's flow factor (optional) Default is "DN50 ball valve ('ball')" pos (vector): position of insertion; default = 0,0,0 Z (vector): orientation: default = 0,0,1 ''' if pos==None: pos=FreeCAD.Vector(0,0,0) if Z==None: Z=FreeCAD.Vector(0,0,1) a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Valvola") if len(propList): pipeFeatures.Valve(a,*propList) else: pipeFeatures.Valve(a) a.ViewObject.Proxy=0 a.Placement.Base=pos rot=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),Z) a.Placement.Rotation=rot.multiply(a.Placement.Rotation) return a
Example #26
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def placeThePype(pypeObject, port=0, target=None, targetPort=0): ''' placeThePype(pypeObject, port=None, target=None, targetPort=0) pypeObject: a FeaturePython with PType property port: an optional port of pypeObject Aligns pypeObject's Placement to the Port of another pype which is selected in the viewport. The pype shall be selected to the circular edge nearest to the port concerned. ''' pos=Z=FreeCAD.Vector() if target and hasattr(target,'PType') and hasattr(target,'Ports'): # target is given pos=portsPos(target)[targetPort] Z=portsDir(target)[targetPort] else: # find target try: selex=FreeCADGui.Selection.getSelectionEx() target=selex[0].Object so=selex[0].SubObjects[0] except: FreeCAD.Console.PrintError('No geometry selected\n') return if type(so)==Part.Vertex: pick=so.Point else: pick=so.CenterOfMass if hasattr(target,'PType') and hasattr(target,'Ports'): # ...selection is another pype-object pos, Z = nearestPort(target, pick)[1:] elif frameCmd.edges([selex[0]]): # one or more edges selected... edge=frameCmd.edges([selex[0]])[0] if edge.curvatureAt(0)!=0: # ...and the first is curve pos=edge.centerOfCurvatureAt(0) Z=edge.tangentAt(0).cross(edge.normalAt(0)) # now place pypeObject on target pOport=pypeObject.Ports[port] if pOport==FreeCAD.Vector(): pOport=pypeObject.Ports[port] if pOport==FreeCAD.Vector(): pOport=FreeCAD.Vector(0,0,-1) pypeObject.Placement=FreeCAD.Placement(pos+Z*pOport.Length,FreeCAD.Rotation(pOport*-1,Z))
Example #27
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def rotateTheTubeAx(obj=None,vShapeRef=None, angle=45): ''' rotateTheTubeAx(obj=None,vShapeRef=None,angle=45) Rotates obj around the vShapeRef axis of its Shape by an angle. obj: if not defined, the first in the selection set vShapeRef: if not defined, the Z axis of the Shape angle: default=45 deg ''' if obj==None: obj=FreeCADGui.Selection.getSelection()[0] if vShapeRef==None: vShapeRef=FreeCAD.Vector(0,0,1) rot=FreeCAD.Rotation(frameCmd.beamAx(obj,vShapeRef),angle) obj.Placement.Rotation=rot.multiply(obj.Placement.Rotation)
Example #28
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def makeCap(propList=[], pos=None, Z=None): '''add a Cap object makeCap(propList,pos,Z); propList is one optional list with 4 elements: DN (string): nominal diameter OD (float): outside diameter thk (float): shell thickness Default is "DN50 (SCH-STD)" pos (vector): position of insertion; default = 0,0,0 Z (vector): orientation: default = 0,0,1 Remember: property PRating must be defined afterwards ''' if pos==None: pos=FreeCAD.Vector(0,0,0) if Z==None: Z=FreeCAD.Vector(0,0,1) a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Fondo") if len(propList)==3: pipeFeatures.Cap(a,*propList) else: pipeFeatures.Cap(a) a.ViewObject.Proxy=0 a.Placement.Base=pos rot=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),Z) a.Placement.Rotation=rot.multiply(a.Placement.Rotation) return a
Example #29
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def makeUbolt(propList=[], pos=None, Z=None): '''Adds a Ubolt object: makeUbolt(propList,pos,Z); propList is one optional list with 5 elements: PSize (string): nominal diameter ClampType (string): the clamp type or standard C (float): the diameter of the U-bolt H (float): the total height of the U-bolt d (float): the rod diameter pos (vector): position of insertion; default = 0,0,0 Z (vector): orientation: default = 0,0,1 Remember: property PRating must be defined afterwards ''' if pos==None: pos=FreeCAD.Vector(0,0,0) if Z==None: Z=FreeCAD.Vector(0,0,1) a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","U-Bolt") if len(propList)==5: pipeFeatures.Ubolt(a,*propList) else: pipeFeatures.Ubolt(a) a.ViewObject.Proxy=0 a.Placement.Base=pos rot=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),Z) a.Placement.Rotation=rot.multiply(a.Placement.Rotation) return a
Example #30
Source File: pipeCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def makeReduct(propList=[], pos=None, Z=None, conc=True): '''Adds a Reduct object makeReduct(propList=[], pos=None, Z=None, conc=True) propList is one optional list with 6 elements: PSize (string): nominal diameter OD (float): major diameter OD2 (float): minor diameter thk (float): major thickness thk2 (float): minor thickness H (float): length of reduction pos (vector): position of insertion; default = 0,0,0 Z (vector): orientation: default = 0,0,1 conc (bool): True for concentric or Flase for eccentric reduction Remember: property PRating must be defined afterwards ''' if pos==None: pos=FreeCAD.Vector(0,0,0) if Z==None: Z=FreeCAD.Vector(0,0,1) a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Riduz") propList.append(conc) pipeFeatures.Reduct(a,*propList) a.ViewObject.Proxy=0 a.Placement.Base=pos rot=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),Z) a.Placement.Rotation=rot.multiply(a.Placement.Rotation) return a