two setEdit(...) in cascade

About the development of the FEM module/workbench.

Moderator: bernd

Post Reply
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

two setEdit(...) in cascade

Post by Jee-Bee »

I have created a macro recording with some part FEM in it.
In the FEM ther are two times setEdit(...) where i have to edit some Gui.
The case is it shows only the second Gui(Mesh creation).

Code: Select all

App.activeDocument().addObject('Fem::FemMeshShapeNetgenObject', 'Fusion_Mesh')
App.activeDocument().ActiveObject.Shape = App.activeDocument().Fusion
Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name)
The first is ignored(Material selction)

Code: Select all

MechanicalMaterial.makeMechanicalMaterial('MechanicalMaterial')
App.activeDocument().Analysis.Member = App.activeDocument().Analysis.Member + [App.ActiveDocument.ActiveObject]
Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name)
Is there some method to create a both Gui steps after each other?
I can imagine that this is more ore less FreeCAD broad so if it has moved to some other topic location it is fine

Hole Script

Code: Select all

# -*- coding: utf-8 -*-

# Macro Begin: /Users/UserName/Library/Preferences/FreeCAD/Macro/test_rec.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
import FreeCAD
import Part
import _CommandAnalysis
import FemGui
import FemAnalysis
import FemSolverCalculix
import Fem
import _CommandMechanicalMaterial
import MechanicalMaterial
import _CommandMeshNetgenFromShape
import _CommandControlSolver

App.newDocument("Unnamed")
#App.setActiveDocument("Unnamed")
#App.ActiveDocument=App.getDocument("Unnamed")
#Gui.ActiveDocument=Gui.getDocument("Unnamed")
#Gui.activateWorkbench("PartWorkbench")
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.ActiveObject.Label = "Cube"
App.ActiveDocument.recompute()
#Gui.SendMsgToActiveView("ViewFit")
FreeCAD.getDocument("Unnamed").getObject("Box").Length = '5 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Length = '50 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Width = '0 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Width = '50 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Height = '0 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Height = '50 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Height = '500 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Height = '50 mm'
FreeCAD.getDocument("Unnamed").getObject("Box").Length = '250 mm'
App.ActiveDocument.addObject("Part::Box","Box")
App.ActiveDocument.ActiveObject.Label = "Cube"
App.ActiveDocument.recompute()
#Gui.SendMsgToActiveView("ViewFit")
FreeCAD.getDocument("Unnamed").getObject("Box001").Length = '0 mm'
FreeCAD.getDocument("Unnamed").getObject("Box001").Length = '20 mm'
FreeCAD.getDocument("Unnamed").getObject("Box001").Length = '250 mm'
FreeCAD.getDocument("Unnamed").getObject("Box001").Width = '0 mm'
FreeCAD.getDocument("Unnamed").getObject("Box001").Width = '50 mm'
FreeCAD.getDocument("Unnamed").getObject("Box001").Height = '0 mm'
FreeCAD.getDocument("Unnamed").getObject("Box001").Height = '50 mm'
FreeCAD.getDocument("Unnamed").getObject("Box001").Placement = App.Placement(App.Vector(20,0,0),App.Rotation(App.Vector(0,0,1),0))
FreeCAD.getDocument("Unnamed").getObject("Box001").Placement = App.Placement(App.Vector(250,0,0),App.Rotation(App.Vector(0,0,1),0))
App.activeDocument().addObject("Part::Fuse","Fusion")
App.activeDocument().Fusion.Base = App.activeDocument().Box
App.activeDocument().Fusion.Tool = App.activeDocument().Box001
#Gui.activeDocument().hide("Box")
#Gui.activeDocument().hide("Box001")
#Gui.ActiveDocument.Fusion.ShapeColor=Gui.ActiveDocument.Box.ShapeColor
#Gui.ActiveDocument.Fusion.DisplayMode=Gui.ActiveDocument.Box.DisplayMode
#Gui.activateWorkbench("FemWorkbench")
FemAnalysis.makeFemAnalysis('Analysis')
FemGui.setActiveAnalysis(App.activeDocument().ActiveObject)
FemSolverCalculix.makeFemSolverCalculix('CalculiX')
FemGui.getActiveAnalysis().Member = FemGui.getActiveAnalysis().Member + [App.activeDocument().ActiveObject]
App.activeDocument().addObject("Fem::ConstraintFixed","FemConstraintFixed")
App.activeDocument().FemConstraintFixed.Scale = 1
App.activeDocument().Analysis.Member = App.activeDocument().Analysis.Member + [App.activeDocument().FemConstraintFixed]
for amesh in App.activeDocument().Objects:
    if "FemConstraintFixed" == amesh.Name:
        amesh.ViewObject.Visibility = True
    elif "Mesh" in amesh.TypeId:
        aparttoshow = amesh.Name.replace("_Mesh","")
        for apart in App.activeDocument().Objects:
            if aparttoshow == apart.Name:
                apart.ViewObject.Visibility = True
        amesh.ViewObject.Visibility = False

App.ActiveDocument.recompute()
#Gui.activeDocument().setEdit('FemConstraintFixed')
App.ActiveDocument.FemConstraintFixed.Scale = 6
App.ActiveDocument.FemConstraintFixed.References = [(App.ActiveDocument.Fusion,"Face1")]
App.ActiveDocument.recompute()
#Gui.activeDocument().resetEdit()
App.activeDocument().addObject("Fem::ConstraintForce","FemConstraintForce")
App.activeDocument().FemConstraintForce.Force = 1.0
App.activeDocument().FemConstraintForce.Reversed = False
App.activeDocument().FemConstraintForce.Scale = 1
App.activeDocument().Analysis.Member = App.activeDocument().Analysis.Member + [App.activeDocument().FemConstraintForce]
for amesh in App.activeDocument().Objects:
    if "FemConstraintForce" == amesh.Name:
        amesh.ViewObject.Visibility = True
    elif "Mesh" in amesh.TypeId:
        aparttoshow = amesh.Name.replace("_Mesh","")
        for apart in App.activeDocument().Objects:
            if aparttoshow == apart.Name:
                apart.ViewObject.Visibility = True
        amesh.ViewObject.Visibility = False

App.ActiveDocument.recompute()
#Gui.activeDocument().setEdit('FemConstraintForce')
App.ActiveDocument.FemConstraintForce.Force = 10000
App.ActiveDocument.FemConstraintForce.Direction = None
App.ActiveDocument.FemConstraintForce.Reversed = False
App.ActiveDocument.FemConstraintForce.Scale = 6
App.ActiveDocument.FemConstraintForce.References = [(App.ActiveDocument.Fusion,"Face10")]
App.ActiveDocument.recompute()
#Gui.activeDocument().resetEdit()
App.activeDocument().addObject("Fem::ConstraintForce","FemConstraintForce001")
App.activeDocument().FemConstraintForce001.Force = 1.0
App.activeDocument().FemConstraintForce001.Reversed = False
App.activeDocument().FemConstraintForce001.Scale = 1
App.activeDocument().Analysis.Member = App.activeDocument().Analysis.Member + [App.activeDocument().FemConstraintForce001]
for amesh in App.activeDocument().Objects:
    if "FemConstraintForce001" == amesh.Name:
        amesh.ViewObject.Visibility = True
    elif "Mesh" in amesh.TypeId:
        aparttoshow = amesh.Name.replace("_Mesh","")
        for apart in App.activeDocument().Objects:
            if aparttoshow == apart.Name:
                apart.ViewObject.Visibility = True
        amesh.ViewObject.Visibility = False

App.ActiveDocument.recompute()
#Gui.activeDocument().setEdit('FemConstraintForce001')
App.ActiveDocument.FemConstraintForce001.Force = 500
App.ActiveDocument.FemConstraintForce001.Direction = None
App.ActiveDocument.FemConstraintForce001.Reversed = False
App.ActiveDocument.FemConstraintForce001.Scale = 6
App.ActiveDocument.FemConstraintForce001.References = [(App.ActiveDocument.Fusion,"Edge9")]
App.ActiveDocument.recompute()
#Gui.activeDocument().resetEdit()
MechanicalMaterial.makeMechanicalMaterial('MechanicalMaterial')
App.activeDocument().Analysis.Member = App.activeDocument().Analysis.Member + [App.ActiveDocument.ActiveObject]
Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name)
App.activeDocument().addObject('Fem::FemMeshShapeNetgenObject', 'Fusion_Mesh')
App.activeDocument().ActiveObject.Shape = App.activeDocument().Fusion
Gui.activeDocument().setEdit(App.ActiveDocument.ActiveObject.Name)
#Gui.activeDocument().resetEdit()
# Macro End: /Users/UserName/Library/Preferences/FreeCAD/Macro/test_rec.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: two setEdit(...) in cascade

Post by bernd »

Do you really need the setEdit? BTW: Have you seen: FEM_Tutorial_Python
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: two setEdit(...) in cascade

Post by Jee-Bee »

bernd wrote:Do you really need the setEdit? BTW: Have you seen: FEM_Tutorial_Python
Not sure if i need it twice. it is just that the gui in 'MechanicalMaterial' and 'Netgen Mesh' is not recorded by using record Macro.
So no material is set and no mesh size eighter.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: two setEdit(...) in cascade

Post by bernd »

Jee-Bee wrote:
bernd wrote:Do you really need the setEdit? BTW: Have you seen: FEM_Tutorial_Python
Not sure if i need it twice. it is just that the gui in 'MechanicalMaterial' and 'Netgen Mesh' is not recorded by using record Macro.
So no material is set and no mesh size eighter.
How to add a material by python without setEdit is shown in the tutorial link posted. How to add a netgen mesh object by python is shown in here: viewtopic.php?f=18&t=16944#p134519 But it has some problems. You could use the GMSH mesh object. It can be fully scripted by python.
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: two setEdit(...) in cascade

Post by Jee-Bee »

thanks
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: two setEdit(...) in cascade

Post by Jee-Bee »

thanks
however i have to figure out what to do with GMSH... Start with an error :o

Code: Select all

We gone start GMSH FEM mesh run!
  Part to mesh: Name --> Fusion,  Label --> Fusion, ShapeType --> Compound
  CharacteristicLengthMax: 25.0
  CharacteristicLengthMin: 0.0
  ElementOrder: 2
Found: Compound
I do not know what is inside your Compound. Dimension was set to 3 anyway.
maybe something to do with http://www.freecadweb.org/wiki/index.ph ... F.E2.80.8E
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: two setEdit(...) in cascade

Post by bernd »

This is just an warning, because a Compound could be anything. It is not really clear what the user would like to mesh if a compound is used. Did you really get an error? Would you post the shape you where trying to mesh and got an error with?
Jee-Bee wrote:maybe something to do with http://www.freecadweb.org/wiki/index.ph ... F.E2.80.8E
No with this: viewtopic.php?f=8&t=16773
Post Reply