"BodyBuilder", a PartDesign macro for assembling bodies

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
last_not_used_login
Posts: 76
Joined: Sun Feb 05, 2023 12:47 am

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by last_not_used_login »

@freedman
When I try to execute I see an exception:

Code: Select all

FreeCAD/Macro/BodyBuilder3.FCMacro", line 1247, in <module>
    visCB = cbToolBox() 
  File "C:/Users/antos/AppData/Roaming/FreeCAD/Macro/BodyBuilder3.FCMacro", line 106, in __init__
    tw = mw.findChild(QDock,twname).findChild(QTree) 
<class 'AttributeError'>: 'NoneType' object has no attribute 'findChild'
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by freedman »

That code was given to me by a coder and I remember having an issue but I thought we got it fixed. Not sure what to tell you, maybe someone more skilled can chime in and propose something.
last_not_used_login
Posts: 76
Joined: Sun Feb 05, 2023 12:47 am

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by last_not_used_login »

freedman wrote: Tue Mar 07, 2023 12:37 am That code was given to me by a coder and I remember having an issue but I thought we got it fixed. Not sure what to tell you, maybe someone more skilled can chime in and propose something.
What do you have selected in the view tree when you click execute? I believe exception says that nothing is selected.
I guess something have to be selected in the tree when clicking "execute"
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by freedman »

You can try this, around line 102, comment the code to look like this ( adding # to the start of each line), then run the macro.

Code: Select all

#        mw=Gui.getMainWindow()            # make a connection to a mouse selection in the tree
#        QDock,QTree = QtGui.QDockWidget, QtGui.QTreeWidget
#        for twname in ('Tree view','Combo View'):
#            tw = mw.findChild(QDock,twname).findChild(QTree) 
#            if tw:
#                tw.itemClicked.connect(self.on_click_code) 
I will try to help but after reading some of your posts I'm not sure you enough experience with FreeCAD. It takes time to learn what to look for while modeling with the program. At the same time I would like to see what someone with little experience can do. :)

By commenting this code, the selection of Bodies will be allowed in the tree (while in Builder Edit), this is not what I intended. If the macro runs OK after the change then I will see what I can do to fix the selections.
Thanks
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by onekk »

Something is not found as it returns None when you issue:

Code: Select all

tw = mw.findChild(QDock,twname).findChild(QTree) 
Probably mw or the result of the findChild() on twname

As the line is complicated debugging it is not easy, modifying the code as follow will make clear what is not found, twp or tw, ie mainwindow or QTree in twp.

Code: Select all

twp = mw.findChild(QDock, twname)
tw = twp.findChild(QTree) 
Hope it helps.

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by adrianinsaval »

freedman wrote: Tue Mar 07, 2023 1:17 am

Code: Select all

#        mw=Gui.getMainWindow()            # make a connection to a mouse selection in the tree
#        QDock,QTree = QtGui.QDockWidget, QtGui.QTreeWidget
#        for twname in ('Tree view','Combo View'):
#            tw = mw.findChild(QDock,twname).findChild(QTree) 
#            if tw:
#                tw.itemClicked.connect(self.on_click_code) 
When not commented this likely fails because the user doesn't have the independent tree view widget enabled (it's not enabled by default IIRC). What's inside the for loop should likely be inside a try block
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by freedman »

Thanks adrianinsaval, that makes things clear.
If I have to wrap this in a try: then I will need a different solution.

This is what I'm trying to do:
I want to filter feature Selections, 3D or Tree. For instance, if I click the last feature in the tree or any face of that object in the 3D I get the same return using getSelections.

Is there a way to know which one is being clicked on? Hmmm, maybe mouse coords or something from OCC vs the GUI.
Thanks
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by freedman »

I solved the issue: how to know if a selection comes from the tree or the 3D.

Code: Select all

p = Gui.ActiveDocument.ActiveView.getCursorPos() 
self.listObjects = Gui.ActiveDocument.ActiveView.getObjectsInfo(p)
if self.listObjects == None:
	print("Your selecting in the tree")
Put the above code in a getselection() routine. Easy to see how it works, there are no listobjects in a tree selection.
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by freedman »

I built a new user interface for BodyBuilder, I will upload to git later, it will be version 4.0 . Here is a video of editing the Lid binding offsets while editing the Knob Sketch. Having the controls right in the 3D makes for really good model diagnostics. This should be useful when I try to fit a couple things together on some design.

Box, lid, knob are all Bodies bound together.

You can see how View Section cuts the face of the Sketch as I move the solid back. :)
Attachments
GIF_sketchview.gif
GIF_sketchview.gif (868.27 KiB) Viewed 985 times
freedman
Veteran
Posts: 3436
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Releasing "BodyBuilder", a PartDesign macro for assembling bodies

Post by freedman »

Working on my hot water solar dish design and testing BodyBuilder. When complete the dish will pump hot water/steam to a fan driven register in the house. The sun tracking structure will also hold a couple solar panels to run the pump and fan i.e, a stand alone system, just add water :) .

Here is a video of BodyBuilder at work, the macro is designed to do quick testing/prototyping of complex models. My work style is a little different than recommended, I add very few dimensions to my objects because it's mostly concept and design verification. I want to verify the design idea and test different parts to see if they fit. Once I understand the structure and how everything fits I go back and start to add real material sizes.

This is why I made the macro, it allows for quick try this and that, don't like it, then delete it and try again. Put some brackets up there and think about wind loads, move things around and try for a balanced system.

I will be uploading 4.1 to git and will start writing usage instructions. This is my last video on this post, hope you liked them, it's time for me to finalize the macro. It works!
Attachments
GIF_dish1.gif
GIF_dish1.gif (867.26 KiB) Viewed 874 times
Post Reply