
Moderator: bernd
You still haven't made this public, right?josegegas wrote: ↑Tue Nov 12, 2019 5:17 amMade some more progress today... fixing errors in the code, a bit more complicated simulations start to be really fun:
https://www.youtube.com/watch?v=YyUkuVBGgyU&t=315s
![]()
Code: Select all
obj = App.ActiveDocument.addObject("Part::FeaturePython", "MBDsolid")
MBDObject(obj) # Class that sets ups the general properties of the scripted object
MBDViewProvider(obj.ViewObject) # Class that sets up the visual properties
class MBDViewProvider:
def __init__(self, vobj):
vobj.Proxy = self
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def execute(self, vobj):
return
def getIcon(self):
return os.path.join(os.path.dirname(__file__), "icons", "MDBobject.svg")
No, not public yet. I'll make it public once it is more usable. I'm still catching errors...vocx wrote: ↑Tue Nov 12, 2019 6:02 amYou still haven't made this public, right?josegegas wrote: ↑Tue Nov 12, 2019 5:17 amMade some more progress today... fixing errors in the code, a bit more complicated simulations start to be really fun:
https://www.youtube.com/watch?v=YyUkuVBGgyU&t=315s
![]()
My advice is to use dedicated icons for your scripted objects (those that appear on the tree view). This makes the workbench look more professional, because it doesn't use the plain "cube" icon from the Part Workbench. It also prevents confusion, as some of your objects may only work with your particular workbench.
When you create your scripted object, you can assign a "view provider" to define visual properties, including the icon.Code: Select all
obj = App.ActiveDocument.addObject("Part::FeaturePython", "MBDsolid") MBDObject(obj) # Class that sets ups the general properties of the scripted object MBDViewProvider(obj.ViewObject) # Class that sets up the visual properties class MBDViewProvider: def __init__(self, vobj): vobj.Proxy = self def __getstate__(self): return None def __setstate__(self, state): return None def execute(self, vobj): return def getIcon(self): return os.path.join(os.path.dirname(__file__), "icons", "MDBobject.svg")
Code: Select all
import FreeCAD
class VPGroup:
def __init__(self, obj):
obj.Proxy = self
def getIcon(self):
'''Return the icon in XPM format which will appear in the tree view. This method is\
optional and if not defined a default icon is shown.'''
return """
/* XPM */
static const char * ViewProviderBox_xpm[] = {
"16 16 6 1",
" c None",
". c #141010",
"+ c #615BD2",
"@ c #C39D55",
"# c #000000",
"$ c #57C355",
" ........",
" ......++..+..",
" .@@@@.++..++.",
" .@@@@.++..++.",
" .@@ .++++++.",
" ..@@ .++..++.",
"###@@@@ .++..++.",
"##$.@@$#.++++++.",
"#$#$.$$$........",
"#$$####### ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
" #$#$$$$$# ",
" ##$$$$$# ",
" ####### "};
"""
obj = App.ActiveDocument.addObject("App::DocumentObjectGroupPython")
VPGroup(obj.ViewObject)
Code: Select all
import FreeCAD
class MyCustomGroup():
def __init__(self, obj):
obj.addExtension("App::GroupExtensionPython", self)
class MyCustomGroupViewProvider():
def __init__(self, obj):
obj.addExtension("Gui::ViewProviderGroupExtensionPython", self)
obj.Proxy = self
def getIcon(self):
'''Return the icon in XPM format which will appear in the tree view. This method is\
optional and if not defined a default icon is shown.'''
return """
/* XPM */
static const char * ViewProviderBox_xpm[] = {
"16 16 6 1",
" c None",
". c #141010",
"+ c #615BD2",
"@ c #C39D55",
"# c #000000",
"$ c #57C355",
" ........",
" ......++..+..",
" .@@@@.++..++.",
" .@@@@.++..++.",
" .@@ .++++++.",
" ..@@ .++..++.",
"###@@@@ .++..++.",
"##$.@@$#.++++++.",
"#$#$.$$$........",
"#$$####### ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
"#$$#$$$$$# ",
" #$#$$$$$# ",
" ##$$$$$# ",
" ####### "};
"""
obj = App.ActiveDocument.addObject("Part::FeaturePython","Group")
MyCustomGroup(obj)
MyCustomGroupViewProvider(obj.ViewObject)
Code: Select all
class MyCustomGroup():
def __init__(self, obj):
obj.addExtension("App::GroupExtensionPython", self)
def allowObject(self, obj):
#check if obj is allowed, maybe by type?
return obj.isDerivedFrom("Part::FeaturePython")
The folder object corresponds to a Std Group which is created asjosegegas wrote: ↑Tue Nov 12, 2019 6:23 amYes I was wondering how to add icons to the scripted objects. I will do this. Thanks! Also, do you know how to make an object part of another object? I mean, as in the FEM workbench, when you create a new analysis, the analysis itself contains scripted objects, such as the mesh, the material, constraints, etc. I'd like to do the same instead of using those containers with the folder icon, or are these the same?
Cheers
Code: Select all
obj = App.ActiveDocument.addObject("App::DocumentObjectGroup", "Group")
Code: Select all
# Real object
class MBDSolid:
def __init__(self, obj, tp="MBDSolid"):
if obj:
obj.Proxy = self
self.Type = tp
obj.addProperty("App::PropertyLinkList", "Components", "Base", QT_TRANSLATE_NOOP("App::Property", "The components of this block"))
# This property will appear in the property editor
# Then the view provider
class MBDViewProvider:
def __init__(self, vobj):
vobj.Proxy = self
self.Object = vobj.Object
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def attach(self,vobj):
self.Object = vobj.Object
def execute(self, vobj):
return
def getIcon(self):
return os.path.join(os.path.dirname(__file__), "icons", "MDBobject.svg")
def claimChildren(self):
objs = []
if hasattr(self.Object, "Components"):
objs.extend(self.Object.Components)
return objs
# Those objects that are inside the Components property will appear as children in the tree
Very nice indeed! Two questions...
saso wrote: ↑Tue Nov 12, 2019 10:25 amVery nice indeed! Two questions...
Is it already possible, or do you see that it could be possible in the future, to solve with this such examples as freecad-heini-1 has asked for here https://forum.freecadweb.org/viewtopic. ... 10#p343888 and https://forum.freecadweb.org/viewtopic. ... 20#p344564 ? As I understand it is basically about the contact (collision) between two surfaces...
Do you think it would be possible to have with this also interactive simulations, so that the model would be solved but then instead of running it as an animation, one would be able to pick a part of it with the mouse and move it manually?
Yes, lately I was actually thinking about something similar, this is why I asked this questionsjosegegas wrote: ↑Tue Nov 12, 2019 12:23 pmI actually think that MBDyn can do as the definitive asembly workbench for FreeCAD. As you can see in my videos, the parts move perfectly because MBDyn takes care of the assembly, it looks for all the constraints and everything. I'm quite existed about this.