Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

Options

Query that Resolves to nothing != qNothing()

Jonathan_HutchinsonJonathan_Hutchinson Member Posts: 64 PRO
edited July 2023 in FeatureScript
I stumbled on some strange behaviour I couldn't figure out. What I thought was quite a straightforward conditional where I do a qSubtraction, resolved weirdly. As below.

                const allGeom = qCreatedBy(id + "extrudeThin", EntityType.FACE);
                const planeGeom = qGeometry(qCreatedBy(id + "extrudeThin", EntityType.FACE), GeometryType.PLANE);
                const curvedGeom = qSubtraction(allGeom, planeGeom);

                debug(context, allGeom, DebugColor.RED);
                debug(context, planeGeom, DebugColor.RED);
                debug(context, curvedGeom, DebugColor.RED);

                if (curvedGeom != qNothing())
                {
                    println("is something");
                }

                else
                {
                    println("is nothing");
                }

Returned in the console:

debug: Query resolves to 6 faces
debug: Query resolves to 6 faces
debug: Query resolves to nothing >>> (curvedGeom variable)
is something >>> (curvedGeom variable, resolves to nothing but isn't equal to qNothing?)

My workaround is to evaluate the query and test if it's equal to an empty array. But I thought equality to qNothing was possible?
Tagged:

Comments

  • Options
    Jacob_CorderJacob_Corder Member Posts: 126 PRO
    qNothing is a query structure and is only the same as another qNothing(). An empty query will not resolve to qNothing() it will return [] from evaluateQuery and false with isQueryEmpty. To solve your current code, the fastest ways is
    if(isQueryEmpty(curvedGeom)==false)
    {

    }

    so, use isQueryEmpty(curvedGeom)
  • Options
    Jonathan_HutchinsonJonathan_Hutchinson Member Posts: 64 PRO
    edited July 2023
    Ah, thank you! I don't know why I had it in my head that comparing to a qNothing would help me out.
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,401
    Or, even more succinct:

    if(!isQueryEmpty(curvedGeom))
    {

    }
    Senior Director, Technical Services, EMEAI
Sign In or Register to comment.