Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Combining multiple FS in one
Dylan_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:
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
0
Best Answers
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,215You have most of it.
If the feature function in FS1 is called firstFeature, instead of "run function FS1" you'd have FS1::firstFeature(context, id, definition);
The other part is the UI definition -- that you do have to copy/paste. And if the two features share parameter names (the map fields, not the stuff in Annotation) you'd have to do a little gymnastics because you can't have duplicate parameters in a precondition.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5 -
mahir Member, Developers Posts: 1,309 ✭✭✭✭✭You can definitely do this. You just have to import your source FS.
export import(path : "SOURCE DOC PATH STRING", version : "SOURCE DOC VERSION STRING");
After importing your source FS, you should be able to use their exposed functions like a black box. An enum can be used to decide which inputs are shown and which functions are executed. I'm sure @dave_cowden would have more to add.
5 -
ilya_baran Onshape Employees, Developers, HDM Posts: 1,215Here's a working example: https://cad.onshape.com/documents/1c3157f205e22bde71791644/w/a049c6eb165ac02f76d77538/e/326fa2b5c795f0bbcf86e54c
Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc2
Answers
If the feature function in FS1 is called firstFeature, instead of "run function FS1" you'd have FS1::firstFeature(context, id, definition);
The other part is the UI definition -- that you do have to copy/paste. And if the two features share parameter names (the map fields, not the stuff in Annotation) you'd have to do a little gymnastics because you can't have duplicate parameters in a precondition.
After importing your source FS, you should be able to use their exposed functions like a black box. An enum can be used to decide which inputs are shown and which functions are executed. I'm sure @dave_cowden would have more to add.
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?
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.
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.
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?
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?
All is good and working!!! Thank you so much!!