我有一个草图,两条线之间的角度固定。我还有一个与草图分区相关联的尺寸(来自草稿)。我需要更改草图上的角度并获取尺寸的实际值。我还需要从外部 python 模块(嵌入)
代码是:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
import numpy as np
FREECADPATH = r'/usr/lib/freecad/lib'
sys.path.append(FREECADPATH)
import FreeCAD as App
import FreeCADGui as Gui
filePath = r"thePath..."
if App.ActiveDocument:
doc = App.ActiveDocument
else:
doc = App.open(filePath)
angSmpl = np.linspace(10, 40, num=10)
sk = doc.Sketch
for angle in angSmpl:
a = sk.getDatum('rotHex').Value
sk = doc.Sketch
sk.setDatum('rotHex', App.Units.Quantity(str(int(angle))+' deg'))
doc.recompute()
b = sk.getDatum('rotHex').Value
res = doc.getObjectsByLabel('heightHex')[0].Distance
print a, b, res
输出是:
FreeCAD 0.16, Libs: 0.16R6707 (Git)
Fasteners workbench Loaded
Sheet Metal workbench loaded
Importing project files......
(100.0 %)
32.0 10.0 330.599 mm
10.0 13.0 330.599 mm
13.0 16.0 330.599 mm
16.0 20.0 330.599 mm
20.0 23.0 330.599 mm
23.0 26.0 330.599 mm
26.0 30.0 330.599 mm
30.0 33.0 330.599 mm
33.0 36.0 330.599 mm
36.0 40.0 330.599 mm
为什么变量“res”没有改变它的值?如何正确解决此任务?
感谢您的帮助。
freecad 模型在这里:MyModel