Check if an object is a solid
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Check if an object is a solid
Hello,
for my macro I have to check, whether an object is a solid or not.
To example:
Body (PartDesign): solid
Sketch: no solid
Plane: no solid
Helix: no solid
Cube: solid
Loft: solid
Loft without checking creating volume: no solid
I hope, you understand, what I mean with solid.
Thanks in advance!
for my macro I have to check, whether an object is a solid or not.
To example:
Body (PartDesign): solid
Sketch: no solid
Plane: no solid
Helix: no solid
Cube: solid
Loft: solid
Loft without checking creating volume: no solid
I hope, you understand, what I mean with solid.
Thanks in advance!
-
- Veteran
- Posts: 5513
- Joined: Thu Apr 05, 2018 1:53 am
Re: Check if an object is a solid
Code: Select all
if App.ActiveDocument.Helix.Shape.Solids:
print("is a solid")
- wandererfan
- Veteran
- Posts: 6321
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Check if an object is a solid
A shape can contain solids without being a Solid.
Code: Select all
>>> f = App.ActiveDocument.Fusion
>>> fs = f.Shape
>>> fs.ShapeType
'Compound'
>>> fs.Solids
[<Solid object at 0x564a0c9ec060>]
>>>
If you need to know that it is a Solid in the topological sense, use ShapeType.
Re: Check if an object is a solid
Thank you, but I use this already in my macro, but for a body in a model it doesn't works. It's a legal body without errors or something else. The file is on my laptop, but I will try it on my computer and report.TheMarkster wrote: ↑Fri Sep 13, 2019 10:06 pmCode: Select all
if App.ActiveDocument.Helix.Shape.Solids: print("is a solid")
usbhub
- wandererfan
- Veteran
- Posts: 6321
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Check if an object is a solid
A Body is a DocumentObject, so it can never be a "Solid". Only Shapes can be Solids.
You could use "App.ActiveDocument.myBody.Shape.Solids".
Re: Check if an object is a solid
As wandererfan says, a PartDesign Body isn't a "solid" by itself, given that it can contain an Origin, a coordinate system, datum planes, lines, points, etc.
A PartDesign Body is a kind of container. Perhaps what you could do is iterate over its elements, and check that its "tip" is a solid, and then assume that the entire Body is a solid as well.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: Check if an object is a solid
Thank you all.
I solved the problem with another way. The check, if the object is a solid was for check, if it's possible to convert to mesh. Now I put the creation of the mesh in a try block and if an error occurs, I know, I can't create a mesh from the shape.
I solved the problem with another way. The check, if the object is a solid was for check, if it's possible to convert to mesh. Now I put the creation of the mesh in a try block and if an error occurs, I know, I can't create a mesh from the shape.
Re: Check if an object is a solid
I'm not sure what you are aiming at, but if it is supposed to be a general tool it should be able to handle bodies as well. At least from the GUI a body can be meshed.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: Check if an object is a solid
Oh yes, I think that's right.But that's not too bad. It is only for converting objects to a mesh for rendering / raytracing.
In retrospect, my question was not quite correct, but many thanks to everyone.
usbhub
PS: What is ATM?