+1 and another one +1ickby wrote:Hm it seems it would be nice to have a "python only" workflow for all FEM calculations, without having any document objects... I think one day we should do that for FEM too.
Parametrized FEM study
Moderator: bernd
Forum rules
and Helpful information for the FEM forum
and Helpful information for the FEM forum
Re: Parametrized FEM study
Re: Parametrized FEM study
+1ickby wrote:Hm it seems it would be nice to have a "python only" workflow for all FEM calculations, without having any document objects.
Bernd, your code works, but no mesh appears when taking the part from selection, so something is different compared to making a part programmatically:
Code: Select all
import Part
import Fem
import FemMeshTools
import FemGui
sel = FreeCADGui.Selection.getSelection()
if len(sel)==1:
part2 = part[0]
femmesh_obj = App.ActiveDocument.addObject('Fem::FemMeshShapeNetgenObject', 'MyMesh')
femmesh_obj.Shape = part2
femmesh_obj.MaxSize = 1
App.ActiveDocument.recompute()
femmesh_obj.FemMesh
Re: Parametrized FEM study
No it is not the selection. The problem is somewhere else. It only works on some cases. Mhh I have never seen someone using NetGenMeshPlugin by python. Means there might be some issues with this.Brucesc2 wrote:Bernd, your code works, but no mesh appears when taking the part from selection, so something is different compared to making a part programmatically:
the second mesh is empty
Code: Select all
import Part
box = Part.makeBox(10,10,10)
App.ActiveDocument.addObject('Part::Box', 'MyBox')
# first try FEM mesh
femmesh_obj = App.ActiveDocument.addObject('Fem::FemMeshShapeNetgenObject', 'MyMesh')
femmesh_obj.Shape = App.ActiveDocument.MyBox
femmesh_obj.MaxSize = 1
App.ActiveDocument.recompute()
femmesh_obj.FemMesh
# remove FEM mesh
App.getDocument("box").removeObject("MyMesh")
App.ActiveDocument.recompute()
# second try FEM mesh
femmesh_obj2 = App.ActiveDocument.addObject('Fem::FemMeshShapeNetgenObject', 'MyMesh')
femmesh_obj2.Shape = App.ActiveDocument.MyBox
femmesh_obj2.MaxSize = 1
App.ActiveDocument.recompute()
femmesh_obj2.FemMesh
Re: Parametrized FEM study
Had a look at the very simple FEM objects FemShellThickness https://github.com/FreeCAD/FreeCAD/blob ... ickness.py and https://github.com/FreeCAD/FreeCAD/blob ... ickness.pyickby wrote:Hm it seems it would be nice to have a "python only" workflow for all FEM calculations, without having any document objects. Like the Mesh object which allows pure python handling, the same would be nice for material, constraitns, calculation, postproccesing etc.
Normally in FreeCAD every functionality is provided in a python interface of some kind (like FEM:Mesh object or Part::Shape) and the document objects only wrap those python functionality. I think one day we should do that for FEM too.
Just some simple question. To add some new Attributes I need an object to add the attributes. How do I create an object without adding it to the document? As an example and Fem::FeaturePython. I only know how to add it to the document.
Code: Select all
App.ActiveDocument.addObject("Fem::FeaturePython", "MyFeaturePython")
Re: Parametrized FEM study
I'm not entirely sure I get your question, so sorry if I miss the point with my answer.bernd wrote: Just some simple question. To add some new Attributes I need an object to add the attributes. How do I create an object without adding it to the document? As an example and Fem::FeaturePython. I only know how to add it to the document.Code: Select all
App.ActiveDocument.addObject("Fem::FeaturePython", "MyFeaturePython")
Document objects are only intended to be used the way you showed, the are intended to be added to the document. AFAIK there is no way to initiate those in Python directly. If one would like to have the functionality of the document object in python one would need to do the following:
1. Create a standalone class which includes all functionality. This is not a document object, just something like FEM::Mehs or Part::Shape, e.g. FEM::Constraint (and subclasses for individual contraitns)
2. One creates a new Property which can hold the class created in point 1, FEM::PropertyConstraint
3. One creates special document Objects that usees FEM::PropertyConstraint and in "execute" retrive the object FEM::Constraint from this property. Than execute can use the methods provided by FEM::Constraint to do its thing.
With this setup the ser could use for example FEM::Constraint in his python scripts. If carefully designed FEM workbench would provide a python only class for making analysis, maybe Fem::analysis, that accepts such FEM::Constraint objects as input together with other objects like fEM::Material etc. But that needs some serious API design thinking.
I think most of the design showed above must be created in c++, at least point 1+2. Point 3 can be done in python only. So it is quite some effort...
Re: Parametrized FEM study
Your answer perfectly explained it to me, and yes that would be cool to have, but for sure I'm not gone start some development in this regard today or tomorrow but we should keep your idea issue #3055