-
Notifications
You must be signed in to change notification settings - Fork 1
/
FPUtils.py
executable file
·56 lines (48 loc) · 1.67 KB
/
FPUtils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import FreeCAD
def getParentPartPlacement(obj):
placementList = []
objToInspect = obj
while True:
parentPart = None
for parent in objToInspect.InList:
if parent.TypeId == 'App::Part':
placementList.append(parent.Placement)
parentPart = parent
if parentPart:
objToInspect = parentPart
else:
break
ret = FreeCAD.Placement()
placementList.reverse()
for p in placementList:
ret = ret.multiply(p)
return ret
def freeCADPlacementToPropertyPythonObject(freeCADPlacement):
plm = freeCADPlacement
base = (plm.Base[0], plm.Base[1], plm.Base[2])
rot = plm.Rotation.Q
placement = (base, rot)
return placement
def propertyPythonObjectToFreeCADPlacement(plm):
placement = FreeCAD.Placement()
placement.Base = FreeCAD.Vector(plm[0][0], plm[0][1], plm[0][2])
placement.Rotation = FreeCAD.Rotation(plm[1][0], plm[1][1], plm[1][2], plm[1][3])
return placement
def isClose(a, b, rel_tol=1e-09, abs_tol=0.0):
return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
def clamp(n, minn, maxn):
return max(min(maxn, n), minn)
def getChildsWithPlacementRecursive(obj, placementObjects):
if hasattr(obj, "Placement"):
placementObjects.append(obj)
if hasattr(obj, "Group"):
for child in obj.Group:
getChildsWithPlacementRecursive(child, placementObjects)
def getChildsWithPlacement(obj):
ret = []
getChildsWithPlacementRecursive(obj, ret)
return ret
def arrayRootObject(obj):
import re
label = re.sub("\[\d+]", '[0]', obj.Label)
return FreeCAD.ActiveDocument.getObjectsByLabel(label)[0]