I'm capturing distance variation between a vertex and a planar face on an Assembly4 document by varying the "Angle" variable.
This version of my code will not update the variation of distance and keep the initial distance, even if I calculate it inside the loop, "FacesJM" and "Sommets" initialization is outside the loop on variable.
Code: Select all
import FreeCAD
App.setActiveDocument('Test')
D403=[]
Sommets=[]
FacesJM=[]
FacesJM.append(App.ActiveDocument.Body.getSubObject('Pocket014.Face38'))
Sommets.append(App.ActiveDocument.Part.getSubObject('Body002.BaseFeature.Vertex403'))
with open("CoordinatesTest.csv", "w") as f:
sys.stdout=f
print("Angle,D403")
for i in range(3600):
FreeCAD.getDocument('TestAlignement').getObject('Variables').Angle = i/10
App.activeDocument().recompute(None,True,True)
D403.append(Sommets[0].Point.distanceToPlane(FacesJM[0].CenterOfMass, FacesJM[0].normalAt(0,0)))
print("%3d,%8.10f" % (i,D403[i]))
This version of my code will update correctly the distance.
Code: Select all
import FreeCAD
App.setActiveDocument('Test')
D403=[]
with open("CoordinatesTest.csv", "w") as f:
sys.stdout=f
print("Angle,D403")
for i in range(3600):
Sommets=[]
FacesJM=[]
FacesJM.append(App.ActiveDocument.Body.getSubObject('Pocket014.Face38'))
Sommets.append(App.ActiveDocument.Part.getSubObject('Body002.BaseFeature.Vertex403'))
FreeCAD.getDocument('TestAlignement').getObject('Variables').Angle = i/10
App.activeDocument().recompute(None,True,True)
D403.append(Sommets[0].Point.distanceToPlane(FacesJM[0].CenterOfMass, FacesJM[0].normalAt(0,0)))
print("%3d,%8.10f" % (i,D403[i]))
Thanks!
Edit: Added proper version of FreeCAD and precision on version.
Code: Select all
OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.1.29410 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: f5d13554ecc7a456fb6e970568ae5c74ba727563
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: French/France (fr_FR)
Installed mods:
* Assembly4 0.12.4
* boltsfc 2022.11.5
* ExtremeProDark 2.5.3
* fasteners 0.4.23
* freecad.gears 1.0.0
* Render 2022.2.0