I am using Lattice2 workbench for getting the oriented bounding box, OBB (or mininum enclosing rectangle) (see https://forum.freecadweb.org/viewtopic.php?t=47408) for different parts.
So far I have used the tools via the FreeCAD GUI.
1. make Attached Placement.
2. Attach it so that axes are parallel to the sides (Align O-X-Y mode, for example)
3. select the shape, the placement, click "Bounding box"
But now I would like to replicate the process by python scripting, and I would also like it to work for any other part automatically. Do you know any python example snippet?
If this is not possible, is there any other way I can calculate the minimum enclosing rectangle for any geometry?
(Find attached the example I used to test Lattice2 tools through the FreeCAD GUI)
Lattice2 mininum enclosing Bounding Box by python script
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Lattice2 mininum enclosing Bounding Box by python script
- Attachments
-
- test_bb.png (5.99 KiB) Viewed 1466 times
-
- lattice_test.FCStd
- (10.48 KiB) Downloaded 38 times
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Lattice2 mininum enclosing Bounding Box by python script
Lattice2 is itself a script. See https://github.com/DeepSOIC/Lattice2/bl ... #L190-L204
Re: Lattice2 mininum enclosing Bounding Box by python script
Thank you DeepSOIC for your answer. However, I am not able to find in the repository the python statemens where the created Placement Object is modified depending on the field values from the GUI (References, Attachment mode, etc.).
I mean, I know the statements required for creating a new default Placement Object:
Once the object is created, it can be modified with the different parameters I mentioned before: References, Attachment mode (Align O-X-Y, Inertial CS, ...), etc., by means of the GUI, and after that, the Placement Object is recomputed.
The statemens where these parameters are collected and processed are those I cannot find.
The intention is I can indicate for example the values of the References by code and not by the GUI.
I mean, I know the statements required for creating a new default Placement Object:
Code: Select all
f = lattice2AttachablePlacement.makeAttachablePlacement(name='Placment')
The statemens where these parameters are collected and processed are those I cannot find.
The intention is I can indicate for example the values of the References by code and not by the GUI.
- Attachments
-
- lattice2_params.png (16.55 KiB) Viewed 1354 times
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Lattice2 mininum enclosing Bounding Box by python script
It's in FreeCAD. The important stuff is in Part.AttachEngine, but just the constructors of App.Placement should get you covered in most cases.
Re: Lattice2 mininum enclosing Bounding Box by python script
I'm sorry but I don't see how to do it.
I have tried the following:
1) Create new Placement object (by python code):
2) Edit Placement object parameters (manually by GUI):
But I have not been able to find how to code the second step.
I have tried the following:
1) Create new Placement object (by python code):
Code: Select all
plac = lattice2AttachablePlacement.makeAttachablePlacement(name='Placment')
3) Create bounding box (by python code):Reference1: Wire001:Vertex5
Reference2: Wire001:Edge5
Reference3: Wire001:Vertex6
Attachment mode: Align O-X-Y
Code: Select all
bbox = lattice2BoundBox.makeBoundBox(name= 'BoundBox')
bbox.ShapeLink = App.ActiveDocument.Wire001
bbox.Label = 'BoundBox of Wire001'
bbox.CompoundTraversal = 'Use as a whole'
bbox.Precision = False
bbox.OrientMode = 'use OrientLink'
bbox.OrientLink = App.ActiveDocument.Placment
lattice2Executer.executeFeature(bbox)
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: Lattice2 mininum enclosing Bounding Box by python script
ah, yeah, these commands aren't logged to console. Here's a workaround:
After you have created an attached placement, go to properties, select MapMode, and click three-dots button there. You'll get attachment dialog. Do something, click OK, and a bunch of commands will appear in py console.
The one Lattice2 activates does not log, because it's actually a different version of the same dialog, which happens to not have this logging. ("..." button invokes a c++ version of the dialog, Lattice2 invokes a python version of the dialog, they are similar but independent)
After you have created an attached placement, go to properties, select MapMode, and click three-dots button there. You'll get attachment dialog. Do something, click OK, and a bunch of commands will appear in py console.
The one Lattice2 activates does not log, because it's actually a different version of the same dialog, which happens to not have this logging. ("..." button invokes a c++ version of the dialog, Lattice2 invokes a python version of the dialog, they are similar but independent)
Re: Lattice2 mininum enclosing Bounding Box by python script
Ah okey I see. And is there any way to invoke these commands from python script?