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

How to tell if a query is a single part or a composite?

eric_pestyeric_pesty Member Posts: 1,530 PRO
I have a feature that can needs to handle either a single part as the input or a composite.
I want to create a composite if it was a single part (as the feature often breaks it into several parts) and I had this working but when the input is already a composite I should add to it rather than create a new one...

I can figure out how to handle both cases but I am struggling with figuring out if my input is a composite or not...
It thought the following would work but I can't make sense of the "compositesize" value I am getting (i.e it's not "1" for a single part or the number of selected parts that went into the composite...)

            var compositesize = size(qBodyType(qContainedInCompositeParts(definition.baseBody), BodyType.SOLID));
            println(compositesize);
            const baseiscomposite = compositesize>1? true: false;

Best Answer

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,416
    Answer ✓
    You can use qBodyType(definition.baseBody, BodyType.COMPOSITE) then isQueryEmpty
    Senior Director, Technical Services, EMEAI

Answers

  • Options
    glen_dewsburyglen_dewsbury Member Posts: 592 ✭✭✭
    @eric_pesty
    Could you not filter type then make a decision as to method?
    Please excuse my poor formatting as I'm am just getting started but I think the idea is right.

    annotation { "Name" : "My Query", "Filter" : BodyType.COMPOSITE, "MaxNumberOfPicks" : 1 }

            definition.myQuery is Query;

            

    true

                    Do this

                    (add part to existing composite)

     false

                    Do that

                    (make new composite)


  • Options
    eric_pestyeric_pesty Member Posts: 1,530 PRO
    edited May 2023
    @glen_dewsbury

    I'm not quite following you...

    I've got what I need to do for true and false cases figured out, I'm just not having any luck figuring out how to set the true/false flag... and I'm not seeing how what you are writing would do that...

    It seems like what you are showing would restrict the selection to composites only, which isn't what I want as I want to be able to pick a single part as well.

    To clarify, this is how I pick my "base body" (which accepts both "regular" bodies and composite parts):

                annotation { "Name" : "Base Body", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 1 }
                definition.baseBody is Query;

    Basically I need a way to figure out if "definition.baseBody" is a composite or just a part. It sounds like it should be simple but I am stumped!

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,416
    Answer ✓
    You can use qBodyType(definition.baseBody, BodyType.COMPOSITE) then isQueryEmpty
    Senior Director, Technical Services, EMEAI
  • Options
    eric_pestyeric_pesty Member Posts: 1,530 PRO
    Thanks @NeilCooke
    That worked...
    I was really close but what threw me off is that I did a println() of exactly that statement and it was very much not "empty", but since I'm not very good at parsing that stuff I couldn't tell what I was looking at...
    I was initially expecting that filtering a query for  BodyType.SOLID would return something that would have a length equal to the number of bodies in it... I guess that would work if it was an array of solids but "Maps" still confuse the hell out of me!
Sign In or Register to comment.