本文整理汇总了Python中FreeCAD.Placement方法的典型用法代码示例。如果您正苦于以下问题:Python FreeCAD.Placement方法的具体用法?Python FreeCAD.Placement怎么用?Python FreeCAD.Placement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FreeCAD
的用法示例。
在下文中一共展示了FreeCAD.Placement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: linkSetup
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
def linkSetup(self,obj):
super(AsmElement,self).linkSetup(obj)
if not hasProperty(obj,'Offset'):
obj.addProperty("App::PropertyPlacement","Offset"," Link",'')
if not hasProperty(obj,'Placement'):
obj.addProperty("App::PropertyPlacement","Placement"," Link",'')
obj.setPropertyStatus('Placement','Hidden')
if not hasProperty(obj,'LinkTransform'):
obj.addProperty("App::PropertyBool","LinkTransform"," Link",'')
obj.LinkTransform = True
if not hasProperty(obj,'Detach'):
obj.addProperty('App::PropertyBool','Detach', ' Link','')
obj.setPropertyStatus('LinkTransform',['Immutable','Hidden'])
obj.setPropertyStatus('LinkedObject','ReadOnly')
obj.configLinkProperty('LinkedObject','Placement','LinkTransform')
parent = getattr(obj,'_Parent',None)
if parent:
self.parent = parent.Proxy
AsmElement.migrate(obj)
self.version = AsmVersion()
示例2: getElementPlacement
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
def getElementPlacement(obj,mat=None):
'''Get the placement of an element
obj: either a document object or a tuple(obj,subname)
mat: if not None, then this should be a matrix, and the returned
placement will be relative to this transformation matrix.
'''
if not isElement(obj):
if not isinstance(obj,(tuple,list)):
pla = obj.Placement
else:
_,mat = obj[0].getSubObject(obj[1],1,FreeCAD.Matrix())
pla = FreeCAD.Placement(mat)
else:
pla = FreeCAD.Placement(getElementPos(obj),getElementRotation(obj))
if not mat:
return pla
return FreeCAD.Placement(mat.inverse()).multiply(pla)
示例3: make_profile_sketch
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
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
示例4: zipRotation
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
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
示例5: makeSingle
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
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()
示例6: shapeReferenceAxis
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
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
示例7: makeShell
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
def makeShell(L=1000,W=1500,H=1500,thk1=6,thk2=8):
'''
makeShell(L,W,H,thk1,thk2)
Adds the shell of a tank, given
L(ength): default=800
W(idth): default=400
H(eight): default=500
thk (thickness): default=6
'''
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Serbatoio")
pipeFeatures.Shell(a,L,W,H,thk1,thk2)
a.ViewObject.Proxy=0
a.Placement.Base=FreeCAD.Vector(0,0,0)
a.ViewObject.ShapeColor=0.0,0.0,1.0
a.ViewObject.Transparency=85
FreeCAD.ActiveDocument.recompute()
return a
示例8: reverseTheTube
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
def reverseTheTube(objEx):
'''
reverseTheTube(objEx)
Reverse the orientation of objEx spinning it 180 degrees around the x-axis
of its shape.
If an edge is selected, it's used as pivot.
'''
disp=None
selectedEdges=[e for e in objEx.SubObjects if e.ShapeType=='Edge']
if selectedEdges:
for edge in frameCmd.edges([objEx]):
if edge.curvatureAt(0):
disp=edge.centerOfCurvatureAt(0)-objEx.Object.Placement.Base
break
elif frameCmd.beams([objEx.Object]):
ax=frameCmd.beamAx(objEx.Object)
disp=ax*((edge.CenterOfMass-objEx.Object.Placement.Base).dot(ax))
rotateTheTubeAx(objEx.Object,FreeCAD.Vector(1,0,0),180)
if disp:
objEx.Object.Placement.move(disp*2)
示例9: placeoTherElbow
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
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
示例10: laydownTheTube
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
def laydownTheTube(pipe=None, refFace=None, support=None):
'''
laydownTheTube(pipe=None, refFace=None, support=None)
Makes one pipe touch one face if the center-line is parallel to it.
If support is not None, support is moved towards pipe.
'''
if not(pipe and refFace): # without argument take from selection set
refFace=[f for f in frameCmd.faces() if type(f.Surface)==Part.Plane][0]
pipe=[p for p in frameCmd.beams() if hasattr(p,'OD')] [0]
try:
if type(refFace.Surface)==Part.Plane and frameCmd.isOrtho(refFace,frameCmd.beamAx(pipe)) and hasattr(pipe,'OD'):
dist=rounded(refFace.normalAt(0,0).multiply(refFace.normalAt(0,0).dot(pipe.Placement.Base-refFace.CenterOfMass)-float(pipe.OD)/2))
if support:
support.Placement.move(dist)
else:
pipe.Placement.move(dist.multiply(-1))
else:
FreeCAD.Console.PrintError('Face is not flat or not parallel to axis of pipe\n')
except:
FreeCAD.Console.PrintError('Wrong selection\n')
示例11: breakTheTubes
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
def breakTheTubes(point,pipes=[],gap=0):
'''
breakTheTube(point,pipes=[],gap=0)
Breaks the "pipes" at "point" leaving a "gap".
'''
pipes2nd=list()
if not pipes:
pipes=[p for p in frameCmd.beams() if isPipe(p)]
if pipes:
for pipe in pipes:
if point<float(pipe.Height) and gap<(float(pipe.Height)-point):
propList=[pipe.PSize,float(pipe.OD),float(pipe.thk),float(pipe.Height)-point-gap]
pipe.Height=point
Z=frameCmd.beamAx(pipe)
pos=pipe.Placement.Base+Z*(float(pipe.Height)+gap)
pipe2nd=makePipe(propList,pos,Z)
pipes2nd.append(pipe2nd)
#FreeCAD.activeDocument().recompute()
return pipes2nd
示例12: join
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
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')
示例13: resetPlacement
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
def resetPlacement():
# restore the placement of all objects
EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly
# set everything to its initial position
for traj in EAFolder.Group:
for name in traj.names:
obj = FreeCAD.ActiveDocument.getObject(name)
# create placement from initial placement list
plm = EAFolder.InitialPlacements[name]
base = FreeCAD.Vector(plm[0][0], plm[0][1], plm[0][2])
rot = FreeCAD.Rotation(plm[1][0], plm[1][1], plm[1][2], plm[1][3])
obj.Placement = FreeCAD.Placement(base, rot)
示例14: goToEnd
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
def goToEnd():
# start animation
EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly.Group
for traj in EAFolder:
objects = []
for name in traj.names:
objects.append(FreeCAD.ActiveDocument.getObject(name))
inc_D = traj.Distance / float(1)
inc_R = traj.Revolutions / float(1)
for i in range(1):
if i == 0:
dir_vectors = []
rot_vectors = []
rot_centers = []
for s in range(len(objects)):
dir_vectors.append(FreeCAD.Vector(tuple(traj.dir_vectors[s])))
rot_vectors.append(FreeCAD.Vector(tuple(traj.rot_vectors[s])))
rot_centers.append(FreeCAD.Vector(tuple(traj.rot_centers[s])))
for n in range(len(objects)):
obj = objects[n]
obj_base = dir_vectors[n]*inc_D
obj_rot = FreeCAD.Rotation(rot_vectors[n], inc_R*360)
obj_rot_center = rot_centers[n]
incremental_placement = FreeCAD.Placement(obj_base, obj_rot, obj_rot_center)
obj.Placement = incremental_placement.multiply(obj.Placement)
FreeCAD.Gui.updateGui()
示例15: updateTrajectoryLines
# 需要导入模块: import FreeCAD [as 别名]
# 或者: from FreeCAD import Placement [as 别名]
def updateTrajectoryLines():
EAFolder = FreeCAD.ActiveDocument.ExplodedAssembly.Group
# remove all the previous trajectory lines
for traj in EAFolder:
for lines in traj.Group:
FreeCAD.ActiveDocument.removeObject(lines.Name)
# re-draw all trajectories
for traj in EAFolder:
lines_compound = []
objects = []
for name in traj.names:
objects.append(FreeCAD.ActiveDocument.getObject(name))
inc_D = traj.Distance
dir_vectors = []
rot_centers = []
for s in range(len(objects)):
dir_vectors.append(FreeCAD.Vector(tuple(traj.dir_vectors[s])))
rot_centers.append(FreeCAD.Vector(tuple(traj.rot_centers[s])))
for n in range(len(objects)):
pa = rot_centers[n]# objects[n].Placement.Base
pb = rot_centers[n] + dir_vectors[n]*inc_D
lines_compound.append(Part.makeLine(pa, pb))
l_obj = FreeCAD.ActiveDocument.addObject('Part::Feature','trajectory_line')
l_obj.Shape = Part.makeCompound(lines_compound)
l_obj.ViewObject.DrawStyle = "Dashed"
l_obj.ViewObject.LineWidth = 1.0
traj.addObject(l_obj)
FreeCAD.Gui.updateGui()