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.

Extrude separate adjacent shapes

emory_krallemory_krall Member Posts: 15 PRO
Does anyone know of a way to extrude two or more adjacent sketch outlines as separate objects? I often need to do this and wind up making several separate extrude features, but it would be much quicker and simpler if there was a featurescript or something that would do it in one operation. 

Best Answer

Answers

  • philip_thomasphilip_thomas Member, Moderator, Onshape Employees, Developers Posts: 1,381
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    edited September 2017
    I believe the op means regions that touch each other.  In the past we've floated the concept of extruding the carcass of a draw for example.  4 individual sides but currently we'd need two extrude features else OS will merge the sides together.

    Cheers, Owen S.
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • philip_thomasphilip_thomas Member, Moderator, Onshape Employees, Developers Posts: 1,381
    @owen_sparks - Yes - if two profiles touch or overlap today, they would be extruded as a single body. Ideas have been floated to introduce the concept of 'bodies' in sketching (allowing things like boolean operations), but the conversations have (so far) ended with "the limited benefits are outweighed by the large number of new concepts and features required". If you have any ideas on how to do this as simply as possible, we are all ears! :)
    Philip Thomas - Onshape
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,210
    @philip_thomas
    I think the op is just asking for a custom feature that will extrude each face of the input as a separate body.  Unfortunately I don't have time to hack this up at the moment...
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    Answer ✓
  • philip_thomasphilip_thomas Member, Moderator, Onshape Employees, Developers Posts: 1,381
    ^^^ @Jake_Rosenfeld - nice! But how does it work? :)
    Philip Thomas - Onshape
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    It does exactly what @emory_krall has already been doing! It just calls extrude separately for each selected profile (so no guarantees on performance). 
            var definitionForOp = definition;
            var count = 0;
            const relevantEntityField = definition.bodyType == ToolBodyType.SOLID ? "entities" : "surfaceEntities";
            for (var entity in evaluateQuery(context, definition[relevantEntityField]))
            {
                definitionForOp[relevantEntityField] = entity;
                
                // keep original id for first entity so that manipulators work
                var idForOp = (count == 0) ? id : (id + count);
                count += 1;
                
                extrude(context, idForOp, definitionForOp);
            }

    Basically make the user supply the same definition as extrude takes, then apply to each entity separately (with some id finagling).
    Some semantic sugar also:
    'definition.entities' is the same as 'definition["entities"]'
    ternary operator (var a = condition ? this : that): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
    Jake Rosenfeld - Modeling Team
  • philip_thomasphilip_thomas Member, Moderator, Onshape Employees, Developers Posts: 1,381
    ^^^Nice! :)
    Philip Thomas - Onshape
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    Works perfectly, make it native please :)

    Thanks again @Jake_Rosenfeld

    For 10 points name another CAD company that will write you two new free features with 24 hours of asking...

    Cheers,

    Owen S.
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • emory_krallemory_krall Member Posts: 15 PRO
    Thanks @Jake_Rosenfeld!!! This is perfect. It even extrudes up to a face which is how we would generally need to use it. Fantastic!
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
     Hi All!

    Thanks for the kind words, glad I could help!  I've pushed a V2 with a very small fix that makes references to the created bodies more stable.

    There's also some weirdness with the "entities" box (you may notice all of your selected faces collapsing into one selection called "Missing of sketch X").  This should not be a huge problem as selections/deselections should act as usual in the graphics are.  We are investigating this as it seems like a systematic issue, hopefully it doesn't cause too much inconvenience. 
    Jake Rosenfeld - Modeling Team
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,045 ✭✭✭✭✭
    There's also some weirdness with the "entities" box (you may notice all of your selected faces collapsing into one selection called "Missing of sketch X").  This should not be a huge problem as selections/deselections should act as usual in the graphics are.  We are investigating this as it seems like a systematic issue, hopefully it doesn't cause too much inconvenience. 
    I had that same problem a while back, until I realised it was caused by the Id. :smile:
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @mbartlett21

    Yup, it's caused by the Id, but if I don't piggyback off the Id in that way, I'd have to do extra work to have the manipulators (or just not have them at all).
    Jake Rosenfeld - Modeling Team
  • paul_bunnellpaul_bunnell Member Posts: 26 EDU

     Thank you @Jake_Rosenfeld! I'm using OnShape to make a stained glass window pattern (of all things) but as you might imagine, your script just saved me a ton of time!

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646

    Glad to help @paul_bunnell !

    Jake Rosenfeld - Modeling Team
Sign In or Register to comment.