FreeCAD as pre-post procesor for MBDyn

About the development of the FEM module/workbench.

Moderator: bernd

josegegas
Posts: 39
Joined: Sat Feb 11, 2017 12:54 am
Location: New Zealand

Re: FreeCAD as pre-post procesor for MBDyn

Postby josegegas » Wed Nov 20, 2019 6:58 am

Yes, you are right, I think I need a bit more planning and less coding haha. Great advice, thanks!
User avatar
HarryvL
Posts: 1053
Joined: Sat Jan 06, 2018 7:38 pm

Re: FreeCAD as pre-post procesor for MBDyn

Postby HarryvL » Wed Nov 20, 2019 9:14 am

josegegas wrote:
Wed Nov 20, 2019 5:04 am
Hi. Every time I make a change to the code, to test if it works as intended, I have to close FreeCAD and open it again, so that it "loads" the module with the changes... This is making me loose too much time. Is there a way to avoid this? Like forcing FreeCAD to load the module without closing it and opening again? I've tested to go from one workbench to another, but it seems FreeCAD loads all only once. How do you guys work?
Try reload(). See here: https://forum.freecadweb.org/viewtopic. ... lit=reload
josegegas
Posts: 39
Joined: Sat Feb 11, 2017 12:54 am
Location: New Zealand

Re: FreeCAD as pre-post procesor for MBDyn

Postby josegegas » Wed Nov 20, 2019 12:08 pm

Another quick question. Is there any method that gets executed when the user clicks (single click) on a given object in the tree view? What I want to achieve: When the user clicks on an object, some other objects in the 3D scene get highlighted. Is this possible?
vocx
Posts: 2350
Joined: Thu Oct 18, 2018 9:18 pm

Re: FreeCAD as pre-post procesor for MBDyn

Postby vocx » Wed Nov 20, 2019 6:12 pm

josegegas wrote:
Wed Nov 20, 2019 12:08 pm
Another quick question. Is there any method that gets executed when the user clicks (single click) on a given object in the tree view? What I want to achieve: When the user clicks on an object, some other objects in the 3D scene get highlighted. Is this possible?
I think what you want sounds like is possible but only in C++. That's basically what realthunder did in 0.19. Now when you hover over an object in the tree view, the corresponding element is highlighted in the 3D view.

Maybe there is an interface to override this behavior, but I wouldn't know for certain, you'd have to ask realthunder.
User avatar
microelly2
Posts: 4500
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: FreeCAD as pre-post procesor for MBDyn

Postby microelly2 » Wed Nov 20, 2019 8:47 pm

josegegas wrote:
Wed Nov 20, 2019 12:08 pm
Another quick question. Is there any method that gets executed when the user clicks (single click) on a given object in the tree view?
selection observer can handle selections

Code: Select all


class SelObserver:

    def addSelection(self,doc,obj,sub,pnt): 
        print ("Selection added",obj)


s =SelObserver()
FreeCADGui.Selection.addObserver(s)                       # install the function mode resident
#FreeCADGui.Selection.removeObserver(s)                   # Uninstall the resident function 

User avatar
microelly2
Posts: 4500
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: FreeCAD as pre-post procesor for MBDyn

Postby microelly2 » Wed Nov 20, 2019 8:53 pm

here an example how I use reload for fast development. I use some naming convention and reloads the implementation file for each call

Code: Select all

class FreeCadNodeBase(NodeBase):
    '''common methods for FreeCAD integration'''
    
    
    def __init__(self, name="FreeCADNode",**kvargs):
        
        super(FreeCadNodeBase, self).__init__(name)
        self._debug = False
        self._preview=False
    
    @timer
    def compute(self, *args, **kwargs):
        if self._debug:
            say("debug on for ",self)
        import nodeeditor.dev
        reload (nodeeditor.dev)
        a=eval("nodeeditor.dev.run_{}(self)".format(self.__class__.__name__))
        if self._debug: say("Done:",self)
        if self._preview:
            say("create preview")
            self.preview()
The class definition - here I only define the interface (parameters)

Code: Select all

class FreeCAD_Blinker(FreeCadNodeBase):
    '''
    blinker sender
    '''

    def __init__(self, name="baked",**kvargs):

        super(self.__class__, self).__init__(name)
        self.inExec = self.createInputPin(DEFAULT_IN_EXEC_NAME, 'ExecPin', None, self.compute)
        self.outExec = self.createOutputPin(DEFAULT_OUT_EXEC_NAME, 'ExecPin')
        self.signal=self.createInputPin('signalName', 'StringPin', 'blink')
        self.data=self.createInputPin('signalMessage', 'StringPin')
        self.d3=self.createInputPin('signalObject', 'FCobjPin')
        self.d3=self.createInputPin('sleep', 'FloatPin')
and the compute fucntion in noteeditor/dev.py

Code: Select all

def run_FreeCAD_Blinker(self):
 ....