5
$\begingroup$

Hi Geometry Nodes friends.

Is there a way to check the object type in geometry nodes?

For example: I would like to check an object if it's a curve or a mesh and do things then.

I've an edges path and would like to convert it to a curve, but if it's already a curve I would like to do other things within the same geometry nodes tree.

Important: Of course, I know how to convert an edge to a curve etc. But I would like to know how to check the object type before doing something.

Is that possible?

Best wishes Chris

$\endgroup$

3 Answers 3

7
$\begingroup$

the separate components node is probably what you are looking for. By using it, you can split the objects of your scene depending on their type

enter image description here

$\endgroup$
1
  • $\begingroup$ Much better :).. $\endgroup$
    – Robin Betts
    Commented Nov 21, 2023 at 19:14
6
$\begingroup$

In a recent answer, I used this hack to check geometry type, by checking for the existence of the curve_type named attribute:

enter image description here

In that case, taking the sum over the geometry, to drive a Switch. To be honest, I'm not very comfortable with it.

$\endgroup$
9
  • $\begingroup$ Interesting. Did it work with the other types, too? $\endgroup$ Commented Nov 20, 2023 at 7:45
  • $\begingroup$ Not by itself, I don't think.. you could cascade tests? But the whole thing is bit janky.. like OO downcasting. $\endgroup$
    – Robin Betts
    Commented Nov 20, 2023 at 7:47
  • 1
    $\begingroup$ @RobinBetts I hear that alarm-bell, too... anyway, instances wouldn't be a problem - you could always plug a Realize Instances before the whole Mesh to Curve and Switch part, because (contrary to the Mesh to Curve node which has an empty output if plug other than a mesh into it) a Realize Instances node lets geometry that's not an instance simply pass through. For other things like points etc. you'd probably have to create more switches to detect all types and react to them... but as you said, that would be a design problem. Why make a nodetree like: throw all in to get a curve out? $\endgroup$ Commented Nov 20, 2023 at 8:32
  • 1
    $\begingroup$ @Gordon OK. Sorry for the misunderstanding... "German guy has problems understanding English, sometimes..." ;) Maybe I'm thinking to complex. You're right. Every other type, than a curve or a mesh would make no sence and ended in no results, what would be ok in this case. $\endgroup$ Commented Nov 20, 2023 at 8:37
  • 2
    $\begingroup$ @ChristophWerner Kein Problem, bin auch ein "German guy". Dann schau einfach welche Antwort dir besser gefällt. $\endgroup$ Commented Nov 20, 2023 at 9:07
6
$\begingroup$

The way you could do it is with a Curve Length node and a Math node set to Compare if Greater Than 0. Of course this method has a flaw, if you plug in a curve with a length of 0, but I assume you do not use such an object. But the comparison is not necessary, depending on what you want to do next.

Because the practical setup depends on what "doing something" with the curve means. If you just want to make sure something is a curve to avoid having no output from the Mesh to Curve node, you can do it with a Switch node that uses the Curve Length for the Selection: a mesh will produce a False result, a curve will be interpreted as True if Curve Length > 0, so only the False branch needs the Mesh to Curve conversion:

mesh to curve switch

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .