Embedded FreeCAD not finding module 'six' when defining CalculixCcxTools

About the development of the FEM module/workbench.

Moderator: bernd

Post Reply
theScriven
Posts: 1
Joined: Sun Feb 05, 2023 5:52 pm

Embedded FreeCAD not finding module 'six' when defining CalculixCcxTools

Post by theScriven »

I am trying run a FreeCAD FEM simulation of a part with FreeCAD embedded into VSCode. Currently, I believe that I have successfully embedded FreeCAD into VSCode, but when I attempt to run syntax torn directly from the wiki to test that everything is working correctly, my code is unable to find the Calculix related module 'six'. Is there any guidance y'all can offer to me as why VSCode isn't recognizing the module. "pip install six" reports that the module is installed. I've included my code below. I'm using freeCAD version 0.20.1 which runs Python 3.8.10. My VSCode is also running Python 3.8.10. I'm trying to get this code to work so that it can eventually be turned into a function that will run with different geometry to report information to an optimization routine, hence the necessity of using VSCode.
Line 38 is where the attached code experiences an error. Line 30 of "write_constraint_centrif.py" attempts to import a module called "six," which causes an error. I assume this is associated with Line 38 of the attached code. I'm sorry if this is a dumb question, I'm a mechanical engineering student a little over my head in the coding. Any guidance would be appreciated!

Code: Select all

# Embed freeCAD into the python IDE
FREECADPATH = 'C:/Program Files/FreeCAD 0.20/bin'
import sys
sys.path.append(FREECADPATH)
# Import in the actual packages from freeCAD
import FreeCAD as App
import FreeCADGui
#import FreeCADGui
# import function to make a new file
import library as lib
# name the file directory properly; requires just a file name 
# and the actual directory to save the file to
fileDirectory = "C://FreeCAD Files//"
fileName = "testingSaveFile"
# make a new file
lib.newFile(fileDirectory, fileName)
# Make a box. In the actual code, this is handled by newLandingLeg()
doc = App.activeDocument()
box = doc.addObject("Part::Box", "myBox")
box.Length = 4
box.Width = 8
box.Height = 24
box.Placement = App.Placement(App.Vector(1,2,3), App.Rotation(75, 60, 30))
# recompute should ensure everything renders correctly. right now, it doesn't work
doc.recompute
# Save document
doc.save()
# WORKING AS OF 2/5/2023


# Begin FEA
import ObjectsFem
# Copy pasted from wiki page: https://wiki.freecad.org/FEM_Tutorial_Python
# analysis
analysis_object = ObjectsFem.makeAnalysis(doc, "Analysis")

# solver (we gone use the well tested CcxTools solver object)
solver_object = ObjectsFem.makeSolverCalculixCcxTools(doc, "CalculiX")
solver_object.GeometricalNonlinearity = 'linear'
solver_object.ThermoMechSteadyState = True
solver_object.MatrixSolverType = 'default'
solver_object.IterationsControlParameterTimeUse = False
analysis_object.addObject(solver_object)

# material
material_object = ObjectsFem.makeMaterialSolid(doc, "SolidMaterial")
mat = material_object.Material
mat['Name'] = "Steel-Generic"
mat['YoungsModulus'] = "210000 MPa"
mat['PoissonRatio'] = "0.30"
mat['Density'] = "7900 kg/m^3"
material_object.Material = mat
analysis_object.addObject(material_object)

# fixed_constraint
fixed_constraint = ObjectsFem.makeConstraintFixed(doc, "FemConstraintFixed")
fixed_constraint.References = [(doc.Box, "Face1")]
analysis_object.addObject(fixed_constraint)

# force_constraint
force_constraint = ObjectsFem.makeConstraintForce(doc, "FemConstraintForce")
force_constraint.References = [(doc.Box, "Face2")]
force_constraint.Force = 9000000.0
force_constraint.Direction = (doc.Box, ["Edge5"])
force_constraint.Reversed = True
analysis_object.addObject(force_constraint)
Attachments
testController.py
(2.29 KiB) Downloaded 33 times
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Embedded FreeCAD not finding module 'six' when defining CalculixCcxTools

Post by wmayer »

my code is unable to find the Calculix related module 'six'.
six is not related to Calculix. It is a module that simplifies the code if Python2 and Python3 must be supported. If you can't get it with pip you can also download it from here: http://archive.ubuntu.com/ubuntu/pool/m ... rig.tar.gz Inside the archive you will find the file six.py
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Embedded FreeCAD not finding module 'six' when defining CalculixCcxTools

Post by onekk »

As Python2 is deprecated, probably the code you are trying to use is obsolete and probably there are more up to date versions around.

Using Python2 code today is not an option, if you want to make something to be used "in future" as Linux distributions are dropping support for Python2, as it was deprecated in 2020.

https://www.python.org/doc/sunset-python-2/

Hope it helps

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply