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.

Can't get "isSheetMetalModelActive" function to work

shawn_crockershawn_crocker Member, OS Professional Posts: 865 PRO
edited August 11 in FeatureScript
I am trying to check is a sheet metal part from a query is active or not.  It seems isSheetMetalModelActive() should do the job.  My problem is it always returns false even when I know for sure the selected part is active.  Here is some sample code I have been testing with.

precondition
    {
        annotation { "Name" : "Sheet Metal Parts to Convert", "Filter" : EntityType.BODY && BodyType.SOLID }
        definition.parts is Query;
    }
    {
        const loopSize = size(evaluateQuery(context, definition.parts));
        var incompatibleParts = [];
        for(var i = 0; i < loopSize; i += 1) {
            const partQuery = qNthElement(definition.parts, i);
            println(isSheetMetalModelActive(context, partQuery));
        }
    }

Any ideas would be very appreciated.  chatGPT seems to also be at a loss with this one too.  :)
Tagged:

Best Answer

  • Caden_ArmstrongCaden_Armstrong Member Posts: 173 PRO
    Answer ✓
    Sheet metal in featurescript is not really straight forward when compared to everything else.
    From my understanding there is the model you see and interact with, but there is also a secret hidden model that is the sheet metal definition model. This helps do all the unfolding and tracking stuff that is unique to sheet metal. Modifying the sheet metal part requires modifying both. This is why most operations don't really work on a sheet metal part, and but the full feature (ex opExtrude vs extrude) does work, because Onshape has all that complexity built into their features that most people won't bother with for a custom feature.

    You can get the underlying sheet metal entities and use that to check.
    But you also cant get the underlying entities (the array is empty) if the sm part is finished, so that is a check in itself.

    tl;dr isSheetMetalModelActive doesn't take a part query, its taking a query for a sheetMetalModel which is a different thing.
            var sm = getSMDefinitionEntities(context, definition.body);
            var isActive = isSheetMetalModelActive(context, sm[0]);

    Chat GPT is worse than useless at FeatureScript. Don't waste your time with it.
    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications

Answers

  • Caden_ArmstrongCaden_Armstrong Member Posts: 173 PRO
    Answer ✓
    Sheet metal in featurescript is not really straight forward when compared to everything else.
    From my understanding there is the model you see and interact with, but there is also a secret hidden model that is the sheet metal definition model. This helps do all the unfolding and tracking stuff that is unique to sheet metal. Modifying the sheet metal part requires modifying both. This is why most operations don't really work on a sheet metal part, and but the full feature (ex opExtrude vs extrude) does work, because Onshape has all that complexity built into their features that most people won't bother with for a custom feature.

    You can get the underlying sheet metal entities and use that to check.
    But you also cant get the underlying entities (the array is empty) if the sm part is finished, so that is a check in itself.

    tl;dr isSheetMetalModelActive doesn't take a part query, its taking a query for a sheetMetalModel which is a different thing.
            var sm = getSMDefinitionEntities(context, definition.body);
            var isActive = isSheetMetalModelActive(context, sm[0]);

    Chat GPT is worse than useless at FeatureScript. Don't waste your time with it.
    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • shawn_crockershawn_crocker Member, OS Professional Posts: 865 PRO
    @Caden_Armstrong
    I see.  I wouldn't have guessed that.  Its strange the function wouldn't just take a part.  If I have to call in the master sheet metal body and then test it, the isSheetMetalModelActive seems redundant seeing as I will not be able to return the master model is the part has been finished.  Thanks for the help.  I will continue using some other logic I implemented after finding this function was not behaving how I had expected.
Sign In or Register to comment.