[Partially solved] Selected element identification in .inp file

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [Help] Selected element identification in .inp file

Post by bernd »

small improvement ...

Code: Select all

sel=Gui.Selection.getSelectionEx()[0]
N=len(sel.SubElementNames)
shownode=[]
for i in range(N):
	A=sel.SubElementNames[i]
	newstr = ''.join((ch if ch in '0123456789.-' else ' ') for ch in A)
	newstr_ =" ".join(newstr.split())
	shownode.append(int(newstr_))

Gui.ActiveDocument.getObject(sel.ObjectName).HighlightedNodes = shownode
I can reproduce the problem. I try to have a look.
EkaitzEsteban
Posts: 108
Joined: Wed Sep 12, 2018 1:31 pm

Re: [Help] Selected element identification in .inp file

Post by EkaitzEsteban »

bernd wrote: Wed Sep 26, 2018 9:24 am small improvement ...

Code: Select all

sel=Gui.Selection.getSelectionEx()[0]
N=len(sel.SubElementNames)
shownode=[]
for i in range(N):
	A=sel.SubElementNames[i]
	newstr = ''.join((ch if ch in '0123456789.-' else ' ') for ch in A)
	newstr_ =" ".join(newstr.split())
	shownode.append(int(newstr_))

Gui.ActiveDocument.getObject(sel.ObjectName).HighlightedNodes = shownode
I can reproduce the problem. I try to have a look.
great!
EkaitzEsteban
Posts: 108
Joined: Wed Sep 12, 2018 1:31 pm

Re: [Help] Selected element identification in .inp file

Post by EkaitzEsteban »

Hello,

Finally I create a first version of a macro for node selection (too much for improving yet).
Once a node is selected, the macro highlights the selected node and also all the nodes from the adjacent elements. It is quite limited but solve a part of my problem. See figure:
NodeSelectorexample.png
NodeSelectorexample.png (560.04 KiB) Viewed 1720 times
I have two more questions:

Is it possible to change the color of the highlighted nodes?

and it is possible to highlight, or change the color of the wireframe?

I check this options by typing in python API:

Code: Select all

dir(Gui.ActiveDocument.getObject("FEMMeshGmsh")) 
#['Annotation', 'BackfaceCulling', 'BoundingBox', 'Content', 'DisplayMode', 'ElementColor', 'HighlightedNodes', 'IV', 'Icon', 'LineWidth', 'MaxFacesShowInner', 'MemSize', 'Module', 'NodeColor', 'NodeDisplacement', 'Object', 'PointColor', 'PointSize', 'PropertiesList', 'Proxy', 'RootNode', 'Selectable', 'SelectionStyle', 'ShapeColor', 'ShapeMaterial', 'ShowInner', 'Transparency', 'TypeId', 'Visibility', 'VisibleElementFaces', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'addDisplayMode', 'addExtension', 'addProperty', 'applyDisplacement', 'claimChildren', 'finishEditing', 'getAllDerivedFrom', 'getDocumentationOfProperty', 'getEditorMode', 'getGroupOfProperty', 'getPropertyByName', 'getTypeIdOfProperty', 'getTypeOfProperty', 'hasExtension', 'hide', 'isDerivedFrom', 'isEditing', 'isVisible', 'listDisplayModes', 'removeProperty', 'setEditorMode', 'setNodeColorByScalars', 'setNodeDisplacementByVectors', 'setTransformation', 'show', 'startEditing', 'supportedProperties', 'toString', 'update']


but I dont know which are callbacks or properties....
Thank you so much for your help!!!
EkaitzEsteban
Posts: 108
Joined: Wed Sep 12, 2018 1:31 pm

Re: [Help] Selected element identification in .inp file

Post by EkaitzEsteban »

Hello,

This still works? https://www.freecadweb.org/wiki/FEM_Mesh

because I am unable to employ this example in my mesh....

Visual handling
Highlight some nodes on the view:

Code: Select all

import FreeCAD, Fem

m = Fem.FemMesh()

m.addNode(0,1,0)
m.addNode(0,0,1)
m.addNode(1,0,0)
m.addNode(0,0,0)
m.addNode(0,0.5,0.5)
m.addNode(0.5,0.03,.5)
m.addNode(0.5,0.5,0.03)
m.addNode(0,0.5,0)
m.addNode(0.03,0,0.5)
m.addNode(0.5,0,0)
m.addVolume([1,2,3,4,5,6,7,8,9,10])

Fem.show(m)
Gui.ActiveDocument.ActiveObject.HighlightedNodes = [1,2,3] 
Postprocessing colors and displacement: Highlight some nodes on the view:

# set the volume 1 to red
Gui.ActiveDocument.ActiveObject.ElementColor= {1:(1,0,0)}
# set the node 1 and 2 to a certain Color and interpolate the survace
Gui.ActiveDocument.ActiveObject.NodeColor= {1:(1,0,0),2:(1,0,0)}
# set the node 1 and 2 to a certain displacement
Gui.ActiveDocument.ActiveObject.NodeDisplacement= {1:FreeCAD.Vector(1,0,0),2:FreeCAD.Vector(1,0,0)}
# double the factor of the displacement shown
Gui.ActiveDocument.ActiveObject.animate(2.0) 
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [Help] Selected element identification in .inp file

Post by bernd »

EkaitzEsteban wrote: Wed Sep 26, 2018 1:10 pm This still works? https://www.freecadweb.org/wiki/FEM_Mesh
It should ... I will try to have a look at your questions later on ...
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [Help] Selected element identification in .inp file

Post by bernd »

EkaitzEsteban wrote: Wed Sep 26, 2018 12:11 pm Is it possible to change the color of the highlighted nodes?
No not with Python. Do you know C++ ? If you compile FreeCAD it's possible.
EkaitzEsteban wrote: Wed Sep 26, 2018 12:11 pm and it is possible to highlight, or change the color of the wireframe?
No neither highlight nor change color. What is possible on edge meshes is selecting.

As you may see the mesh view provider (the cpp class govern for all your needs) needs some love, because alls your needs are doable but needs some C++ deverlopment.

Bernd
EkaitzEsteban
Posts: 108
Joined: Wed Sep 12, 2018 1:31 pm

Re: [Help] Selected element identification in .inp file

Post by EkaitzEsteban »

bernd wrote: Wed Sep 26, 2018 1:27 pm
EkaitzEsteban wrote: Wed Sep 26, 2018 1:10 pm This still works? https://www.freecadweb.org/wiki/FEM_Mesh
It should ... I will try to have a look at your questions later on ...
Hello Bernd,

I tried using a very simple example. Load Cantilever beam 3D from the start page

Code: Select all

Gui.getDocument("FemCalculixCantilever3D").getObject("Box_Mesh").Visibility=True
A=Gui.getDocument("FemCalculixCantilever3D").getObject("Box_Mesh")
A.ElementColor={1:(1,0,0)}
I expected to get an element 1 with red color. However, all the mesh becomes green :cry:

Can someone know about that?
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [Help+Bug] Selected element identification in .inp file

Post by bernd »

EkaitzEsteban wrote: Wed Sep 26, 2018 7:26 am EDIT: I found a BUG. If you select a again the highlighted node. This one is then renamed to Node1.
I try to explain. Use the abovementioned code with solely one node. e.g Node33

If you click again in the highlighted Node33, in the selection view you will see Node1 :shock:
https://forum.freecadweb.org/viewtopic. ... 48#p258746 and issue #3618
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [Help] Selected element identification in .inp file

Post by bernd »

remember volumes of the famous :mrgreen: cantilever starts with 149 thus

Code: Select all

Gui.getDocument("FemCalculixCantilever3D").getObject("Box_Mesh").Visibility=True
A=Gui.getDocument("FemCalculixCantilever3D").getObject("Box_Mesh")
A.ElementColor={149:(1,0,0)}
It seams if the element could not be colored all or non (which means all will be green) elements are colored. BTW the code ... https://github.com/FreeCAD/FreeCAD/blob ... #L178-L192 and https://github.com/FreeCAD/FreeCAD/blob ... #L631-L652


screen.jpg
screen.jpg (178.1 KiB) Viewed 1695 times
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: [Help+Bug] Selected element identification in .inp file

Post by bernd »

bernd wrote: Wed Sep 26, 2018 4:15 pm
EkaitzEsteban wrote: Wed Sep 26, 2018 7:26 am EDIT: I found a BUG. If you select a again the highlighted node. This one is then renamed to Node1.
I try to explain. Use the abovementioned code with solely one node. e.g Node33

If you click again in the highlighted Node33, in the selection view you will see Node1 :shock:
https://forum.freecadweb.org/viewtopic. ... 48#p258746 and issue #3618
fixed in commit git commit 00bf21d. Sometimes werner is faster in fixing bugs than we in reporting :mrgreen:
Post Reply