Check if an object is a solid

Need help, or want to share a macro? Post here!
usbhub
Posts: 29
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Check if an object is a solid

Postby usbhub » Fri Sep 13, 2019 9:35 pm

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!
TheMarkster
Posts: 1055
Joined: Thu Apr 05, 2018 1:53 am

Re: Check if an object is a solid

Postby TheMarkster » Fri Sep 13, 2019 10:06 pm

Code: Select all

if App.ActiveDocument.Helix.Shape.Solids:
    print("is a solid")
wandererfan
Posts: 2882
Joined: Tue Nov 06, 2012 5:42 pm

Re: Check if an object is a solid

Postby wandererfan » Sat Sep 14, 2019 12:28 am

usbhub wrote:
Fri Sep 13, 2019 9:35 pm
for my macro I have to check, whether an object is a solid or not.
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 want to know if the shape contains solids, use @TheMarkster's method.

If you need to know that it is a Solid in the topological sense, use ShapeType.
usbhub
Posts: 29
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Re: Check if an object is a solid

Postby usbhub » Sun Sep 15, 2019 5:10 pm

TheMarkster wrote:
Fri Sep 13, 2019 10:06 pm

Code: Select all

if App.ActiveDocument.Helix.Shape.Solids:
    print("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.

usbhub
wandererfan
Posts: 2882
Joined: Tue Nov 06, 2012 5:42 pm

Re: Check if an object is a solid

Postby wandererfan » Sun Sep 15, 2019 7:50 pm

usbhub wrote:
Sun Sep 15, 2019 5:10 pm
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.
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".
vocx
Posts: 986
Joined: Thu Oct 18, 2018 9:18 pm

Re: Check if an object is a solid

Postby vocx » Mon Sep 16, 2019 5:22 pm

usbhub wrote:
Sun Sep 15, 2019 5:10 pm
but for a body in a model it doesn't works. It's a legal body without errors or something else.
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.
usbhub
Posts: 29
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Re: Check if an object is a solid

Postby usbhub » Tue Sep 17, 2019 4:07 pm

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.
chrisb
Posts: 17520
Joined: Tue Mar 17, 2015 9:14 am

Re: Check if an object is a solid

Postby chrisb » Tue Sep 17, 2019 4:33 pm

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.
openBrain
Posts: 1815
Joined: Fri Nov 09, 2018 5:38 pm

Re: Check if an object is a solid

Postby openBrain » Tue Sep 17, 2019 5:23 pm

usbhub wrote:
Tue Sep 17, 2019 4:07 pm
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.
I'm not able to check ATM but I'd bet that a shell can also be converted to mesh. ;)
usbhub
Posts: 29
Joined: Tue Apr 02, 2019 8:22 pm
Location: Earth

Re: Check if an object is a solid

Postby usbhub » Tue Sep 17, 2019 6:43 pm

openBrain wrote:
Tue Sep 17, 2019 5:23 pm
usbhub wrote:
Tue Sep 17, 2019 4:07 pm
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.
I'm not able to check ATM but I'd bet that a shell can also be converted to mesh. ;)
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?