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 Query all Surface Bodies

Alex_BentonAlex_Benton Member, csevp Posts: 4 PRO
Hi All,

I've got a problem where to create a reusable part, I need to combine all surface bodies in a document into a composite part. I'm struggling with the correct query. I've tried the following:

selectedBodies = qBodyType(qEverything(EntityType.BODY), BodyType.SHEET);
This gives the error "Cannot create a composite part containing a plane" So I tried to remove planes with qGeometry:

selectedBodies = qSubtraction(selectedBodies, qGeometry(selectedBodies, GeometryType.PLANE));
But this gives the same error. All of the surfaces I want to join are coplanar, but I assume this error concers reference planes.

The queries are being used as follows:
            opCreateCompositePart(context, compositePartId, {
                        "bodies" : selectedBodies,
                        "closed" : false
                    });

The equivalent for compositing all solid bodies works just fine.
selectedBodies = qAllModifiableSolidBodies();

What's the correct query to use here?



As an extension, I'd like to modify the standard 'wrap' feature so I can select this composite surface in a dialog box, and have the wrap feature apply to all faces of this composite body. Is there a way to do that?

Cheers,
Alex

Best Answer

  • Options
    MichaelPascoeMichaelPascoe Member Posts: 1,724 PRO
    edited January 31 Answer ✓

    @_anton beat me to it. You can also put it in your own function so you don't have to do that again :D

        export function qAllSurfaces()
        {
            const allBodies = qEverything(EntityType.BODY);
            var surfaces = qBodyType(allBodies, BodyType.SHEET);
            surfaces = qSubtraction(surfaces, qConstructionFilter(surfaces, ConstructionObject.YES));
            surfaces = qSubtraction(surfaces, qSketchFilter(surfaces, SketchObject.YES));
            
            return surfaces;
        }

    To modify the Wrap feature, copy it from the Onshape Standard Library, then make the modification you need from your copied document.
    Note that wrap does not wrap to non cylindrical or planar faces.
    https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/5e2ac00ef43da299ccb2ff00

    You will need to modify the target input to something like this:
            annotation { "Name" : "Target", "Filter" : BodyType.COMPOSITE, "MaxNumberOfPicks" : 1 }
            definition.destination is Query;
    Then, to get all of the faces out of the composite:
            const faces = qOwnedByBody(definition.destination, EntityType.FACE);



    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎

Answers

  • Options
    _anton_anton Member, Onshape Employees Posts: 279
    I think you'll want

    var sheetBodies = qEverything(EntityType.BODY)->qBodyType(BodyType.SHEET)->qSketchFilter(SketchObject.NO)->qSubtraction(qDefaultBodies());
  • Options
    MichaelPascoeMichaelPascoe Member Posts: 1,724 PRO
    edited January 31 Answer ✓

    @_anton beat me to it. You can also put it in your own function so you don't have to do that again :D

        export function qAllSurfaces()
        {
            const allBodies = qEverything(EntityType.BODY);
            var surfaces = qBodyType(allBodies, BodyType.SHEET);
            surfaces = qSubtraction(surfaces, qConstructionFilter(surfaces, ConstructionObject.YES));
            surfaces = qSubtraction(surfaces, qSketchFilter(surfaces, SketchObject.YES));
            
            return surfaces;
        }

    To modify the Wrap feature, copy it from the Onshape Standard Library, then make the modification you need from your copied document.
    Note that wrap does not wrap to non cylindrical or planar faces.
    https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/5e2ac00ef43da299ccb2ff00

    You will need to modify the target input to something like this:
            annotation { "Name" : "Target", "Filter" : BodyType.COMPOSITE, "MaxNumberOfPicks" : 1 }
            definition.destination is Query;
    Then, to get all of the faces out of the composite:
            const faces = qOwnedByBody(definition.destination, EntityType.FACE);



    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • Options
    Alex_BentonAlex_Benton Member, csevp Posts: 4 PRO
    Thanks both! Super helpful :)
Sign In or Register to comment.