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

Combining multiple FS in one

Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
Is it possible to have several different FS in one? 

Meaning I would like to create an enum that will allow you to choose which FS you want to use.

I know the work around here is to just physically copy and paste and have it work that way, but I don't want that. 
I would like to be able to import in to a new FS all of my different features so that I can secure my code. 

example:

FeatureScript 392;
import(path : "onshape/std/geometry.fs", version : "392.0");

FS1::import(path : "123123123123123", version : "321321321321");
FS2::import(path : "456456456456456", version : "654654654654");


export enum Choice
{
    annotation {"Name" : "FS1"}
    ONE,
    annotation {"Name" : "FS2"}
    TWO
}

annotation { "Feature Type Name" : "Creation Choice" }
export const myCreationChoice = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "My Enum" }
        definition.myChoice is Choice;
        
    }
    {
        if(definition.myChoice == Choice.ONE)
        {
            run function FS1
        }
        if(definition.myChoice == Choice.TWO)
        {
            run function FS2
        }
    });

Digital Engineering

Best Answers

  • Options
    ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,175
    Answer ✓
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc

Answers

  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    @ilya_baran would the copy/paste also hold true for the export enum options I have within my other FS? 

    Also, I'm not %100 on the "FS1::firstFeature(context, id, definition);" part.. would that be the "myFeature" that is placed when you create a new FS?
    The "const" would all have to be copy/paste as well? 

    @mahir so instead of my "FS1::import....." I would have to put "export FS1::import......" in it's place? 

    Is there a good example out there that does this? 

    Digital Engineering
  • Options
    ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,175
    No, the enum declarations need to be reexported, not copied.  Doing "export FS1::import" instead of "FS1::import" will do that.

    Yes, the default function name is "myFeature".

    Not sure what you mean about "const" copy/pasting, but yes, you need the boilerplate in your example above.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    @ilya_baran forgive me for my lack of knowledge/understanding... But what would go in the "(context, id, definition)" arguments? 

    This is what I have so far....
    This is the document that I am trying to get the 2 FS options to import in to.
    https://cad.onshape.com/documents/5a4159c08aa167c04de8c637/w/c4d507ef42bda6d297b57fb9/e/1d6f216f1df1cea430821a9c

    This is the document that is holding the 2 working FS.
    https://cad.onshape.com/documents/df4ff84027cc7cd2dde61b6c/w/b8de7280118f711b70aee96e/e/7ea31fe7944222c6fbe064e5

    @lemon1324 - I know you have some experience in this as well, would you mind shining some light on this for me? 

    Any questions, please ask... This is kind of an important hurdle I need to jump. 
    Thank you.

    Digital Engineering
  • Options
    ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,175
    Ok, your function body is correct -- (context, id definition) is exactly what goes in there -- you're just forwarding the context, id, and the definition to the other feature.  The problem is the enums -- you are redefining them in the outer FS, which makes them different.

    Unfortunately, you can't reuse the enums within a namespace (the FS1::) and you probably don't want to reexport the original feature without a namespace.  So what I'd do is the following:

    Make a separate feature studio with the enum declarations.  Export import it without a namespace into both other feature studios.  So:

    FS-enums:

    export enum Choice
    {
          ONE,
          TWO
    }

    FS-features:

    export import ( ... FS-enums ... )

    // define your two features

    FS-choiceFeature:

    export import ( ... FS-enums ... )
    FS1::import( ... FS-features ... )

    ... FS1::myTableCreator(context, id, definition); ...

    Does this make sense?
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    @ilya_baran I'm trying to follow as much as possible without asking many questions, but unfortunately I am unable to follow what you are telling me to do.

     
    Digital Engineering
  • Options
    ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,175
    Answer ✓
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    Thank you @ilya_baran

    Digital Engineering
  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    @ilya_baran



    Should it matter that one of my FS has imported parts? 

    I got the desired result, but my TableCreator FS is not wanting to generate. 

    I can only speculate that it's because of the imported legs? 
    Digital Engineering
  • Options
    ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,175
    I think it should work with imported legs the way you're doing it.  What's the error you're getting?
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Options
    Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    Sorry, you are correct @ilya_baran, I was not working in the latest version. 

    All is good and working!!! Thank you so much!!  :)
    Digital Engineering
Sign In or Register to comment.