Part__Feature_solid with the object name

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Oli772
Posts: 26
Joined: Wed Apr 27, 2022 2:35 pm

Part__Feature_solid with the object name

Post by Oli772 »

Hello,
I am doing a Part_BooleanFragments operation as below

Code: Select all

App.newDocument("Unnamed")
Gui.ActiveDocument.mergeProject("/home/.../part1.FCStd")
Gui.ActiveDocument.mergeProject("/home/.../part2.FCStd")
Gui.ActiveDocument.mergeProject("/home/.../part3.FCStd")

### Begin command Part_BooleanFragments
j = BOPTools.SplitFeatures.makeBooleanFragments(name='BooleanFragments')
j.Objects = [App.ActiveDocument.Part__Feature_solid, App.ActiveDocument.Part__Feature_solid001, App.ActiveDocument.Part__Feature_solid002]
j.Mode = 'Standard'
j.Proxy.execute(j)
j.purgeTouched()
for obj in j.ViewObject.Proxy.claimChildren():
    obj.ViewObject.hide()
### End command Part_BooleanFragments
Howeve I would like, in the "j.Objects" command, to replace the name "Part__Feature_solid" with something linked to the true name of the part, "part1" in that case
So the command would be

Code: Select all

j.Objects = [App.ActiveDocument."something...part1", App.ActiveDocument."something...part2", App.ActiveDocument."something...part3"]
How can I do that ?
Thanks
Oli
Syres
Veteran
Posts: 2899
Joined: Thu Aug 09, 2018 11:14 am

Re: Part__Feature_solid with the object name

Post by Syres »

I'm sure there's a more efficient way but this is the best I could come up with:

Code: Select all

App.newDocument("Unnamed")
Gui.ActiveDocument.mergeProject("/home/.../Part1.FCStd")
objs = FreeCAD.ActiveDocument.Objects
for obj in objs:
    sPart1 = obj
Gui.ActiveDocument.mergeProject("/home/.../Part2.FCStd")
objs = FreeCAD.ActiveDocument.Objects
for obj in objs:
    if obj != sPart1:
        sPart2 = obj
        break
Gui.ActiveDocument.mergeProject("/home/.../Part3.FCStd")
objs = FreeCAD.ActiveDocument.Objects
for obj in objs:
    if obj != sPart1 and obj != sPart2:
        sPart3 = obj
        break

### Begin command Part_BooleanFragments
import BOPTools.SplitFeatures
j = BOPTools.SplitFeatures.makeBooleanFragments(name='BooleanFragments')
j.Objects = [sPart1, sPart2, sPart3]
j.Mode = 'Standard'
j.Proxy.execute(j)
j.purgeTouched()
for obj in j.ViewObject.Proxy.claimChildren():
    obj.ViewObject.hide()
### End command Part_BooleanFragments
Gui.SendMsgToActiveView("ViewFit")
Tested using:

Code: Select all

OS: Linux Mint 19.3 (X-Cinnamon/cinnamon)
Word size of FreeCAD: 64-bit
Version: 0.21.29899 (Git)
Build type: Release
Branch: master
Hash: 5b83b15b63dc6431a946e6d681d369ea60cc637b
Python 3.6.9, Qt 5.9.5, Coin 4.0.0a, Vtk 7.1.1, OCC 7.3.0
Locale: English/UnitedKingdom (en_GB)
Installed mods: 
  * fasteners 0.3.50
  * Silk 1.0.0
  * Plot 2022.4.17
  * CfdOF 1.16.1
  * BIM 2021.12.0
  * FeedsAndSpeeds 0.4.0
  * dodo
  * Curves 0.5.2
  * Manipulator 1.4.9
  * fcgear 1.0.0
  * ThreadProfile 1.81.0
  * A2plus 0.4.56a
  * sheetmetal 0.2.52
Oli772
Posts: 26
Joined: Wed Apr 27, 2022 2:35 pm

Re: Part__Feature_solid with the object name

Post by Oli772 »

thank you Syres.

This should solve part of my issue which is to keep and bring the names of the booleans fragments from this FC brep file through the geometry import process of Gmsh. That is obviously another story but it seems that Gmsh does not recognize at all the naming and the order in which they have been made.. the import gives there a random surface numbering
Post Reply