CWernerArt, German
@CWernerArt@mstdn.social avatar

Do someone knows why this condition is not working in python? Is there really no way to check objects, if they have no faces/polygons?

if reference_mesh.edges and not reference_mesh.polygons: # Check if the reference mesh has only edges

This line have to check, if an object has edges only and no faces. But it doesn't work. Always objects having faces are also included into this condition.
Any idea?

TerryHancock,
@TerryHancock@realsocial.life avatar

@CWernerArt
I'm not sure and I'm not testing this right now, but IIRC, bpy collection data types can behave a little oddly for Python programmer expectations.

You might want to check if those data types actually return "false" when they are empty.

If not, you might need to use len() to see if they are 0-length, instead.

CWernerArt,
@CWernerArt@mstdn.social avatar

@TerryHancock You mean like this?

if len(reference_mesh.edges) == 0 and len(reference_mesh.polygons) == 0:

This is also not working. I tried that already.

CWernerArt,
@CWernerArt@mstdn.social avatar

@TerryHancock Maybe it helps if I add: when using empty plane objects for example, then all works fine.

But if you use an empty cube (without faces just wireframe), then it doesn't work.

TerryHancock,
@TerryHancock@realsocial.life avatar

@CWernerArt
Yeah, I just tried deleting the faces from the default cube, and it still reports 6 polygons in the mesh.

I'm not sure why that is.

Maybe "face" and "polygon" are not actually the same thing?

I see that the mesh type doesn't have a "faces" element. But "polygons" doesn't seem to respect whether there are actually faces defined or not.

CWernerArt,
@CWernerArt@mstdn.social avatar

@TerryHancock Yeah. Actually I also thought we can check for polygons by using the .polygons suffix.

CWernerArt,
@CWernerArt@mstdn.social avatar

@TerryHancock Maybe it's a bug?

TerryHancock,
@TerryHancock@realsocial.life avatar

@CWernerArt

Okay, I just looked this up, and there is a weird thing: if you are in Edit Mode, the mesh may not be up to date!

Changing to Object Mode, and THEN inspecting the list(my_mesh.polygons) reports [] if the faces have been deleted.

https://docs.blender.org/api/current/info_gotcha.html#info-gotcha-mesh-faces

TerryHancock,
@TerryHancock@realsocial.life avatar

@CWernerArt
I mean, I just checked this with a couple of cube meshes.

The link suggests a couple of different ways to deal with this. You may be able to force an update even while in edit mode.

CWernerArt,
@CWernerArt@mstdn.social avatar

@TerryHancock Yeah. But I'm always not in Edit mode. I just check for objects that already are wireframe and some not. Or do I misunderstand something? I'm still new to blender python...

TerryHancock,
@TerryHancock@realsocial.life avatar

@CWernerArt

I don't know, but when I did tests above, I had left Blender in edit mode, so I was getting stale results from querying the cube objects.

When I exited to object mode and then ran the tests, I got the expected behavior that the mesh with faces deleted returned an empty list from list(cubemesh.polygons), while the one with faces reported 6 polygons.

Tested in Blender 2.79 and 3.30 just now.

CWernerArt,
@CWernerArt@mstdn.social avatar

@TerryHancock I'm in 3.6 and will check my routine in 3.3.

CWernerArt,
@CWernerArt@mstdn.social avatar

@TerryHancock Same problem in 3.3.

Two cubes. If I delete just the faces of one cube and exit the edit mode, both cubes are recognized as containing polygons and selected...

TerryHancock,
@TerryHancock@realsocial.life avatar
CWernerArt,
@CWernerArt@mstdn.social avatar

@TerryHancock Thank you a lot for your efforts. I guess I've found a solution for my situation, in the meantime. Now all works as expected. 🙂

  • All
  • Subscribed
  • Moderated
  • Favorites
  • blender
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • cubers
  • rosin
  • thenastyranch
  • Youngstown
  • osvaldo12
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • Durango
  • JUstTest
  • everett
  • tacticalgear
  • modclub
  • anitta
  • cisconetworking
  • tester
  • ngwrru68w68
  • GTA5RPClips
  • normalnudes
  • megavids
  • Leos
  • provamag3
  • lostlight
  • All magazines