Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape, CAD, maker project and design.

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.

Re-usable code

john_mcclaryjohn_mcclary Member, Developers Posts: 1,217 PRO
edited October 18 in FeatureScript
Is there a way to "#include" or maybe something like 'using' another featurescript?
tried to do : import(path : "onshape/str/sheetMetalStart.fs", version : "920.0"); but that gave me a bunch of errors

I basically want to just expand on "sheet metal model's" pre-conditions. (add a guage and bend radius table)
but I don't want to maintain the rest of the featurescript manually every 3 weeks, if they decide to fix a bug or whatever in the standard library source.

this also applies to many other standard features / custom features which I want the base code, but just a more customized dialog.

I'm probably missing something simple

https://cad.onshape.com/documents/28050bca2b1ddeb0acbab720/w/72369ffa7faabbf84de28ab1/e/227b8ffd6d2196f915165a0d

Best Answers

Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 739 ✭✭✭✭
    the answer abought some errors of import might be in this thread - https://forum.onshape.com/discussion/comment/42372#Comment_42372

  • mbartlett21mbartlett21 Member Posts: 1,032 EDU
    edited October 18
    @john_mcclary

    Here is my Sheet metal model FS: (it has bend allowance and deduction. It also supports recognizing a part as sheet metal if you extruded it normally.)
    https://cad.onshape.com/documents/a39db7615a2a945ffb7076c3

    What i'd really like is some way to see what has changed in the Feature Studio in STD (Compare feature for Feature Studios), so as to update my feature easier
  • john_mcclaryjohn_mcclary Member, Developers Posts: 1,217 PRO
    edited October 18
    I'm still stewing on how I want to really handle this specific task. going back and forth in my head yet. 

    but I have other FS's that only have a couple edits to the standard library. For example "Log Linear Pattern" allows for logarithmic spacing. When they allowed sheet-metal to be linear patterned, I had to copy paste their new code in to the script and add my 2 lines again.

    Would be nice to just set overrides to the pre-condition.
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,055
    @john_mcclary

    Your errors are coming from a couple sources. Firstly,  You don't ned to copy SMProcessType, SMCornerStrategyType etc. because they are already defined and exported out of sheetMetalStart.fs.  It's saying 'dupicate top level symbol' because you are trying to define something that's already been defined.

    Next, the whole feature is errored because you need to import 'sheetMetalUtils.fs' (same syntax as how you imported 'sheetMetalStart.fs').  You'll notice that hovering over this highlight says 'defineSheetMetalFeature not found'.  That function is defined and exported by sheetMetalUtils module.

    You actually don't need the sheetMetalStart.fs import, since geometry.fs exports that module:
    https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/b9a58548f6cc4fa7acef723a
    Jake Rosenfeld - Modeling Team
  • lanalana Onshape Employees Posts: 387
    You actually don't need the sheetMetalStart.fs import, since geometry.fs exports that module:
    You need, but you need to do export import in order to export definitions of all enums.
    export import(path : "onshape/std/sheetMetalStart.fs", version : "920.0");
    @john_mcclary , Welcome to sheet metal development team  :)


  • john_mcclaryjohn_mcclary Member, Developers Posts: 1,217 PRO
    so would these functions need to be exported in SheetMetalStart.fs in order to access them?


  • john_mcclaryjohn_mcclary Member, Developers Posts: 1,217 PRO
    I think that sheetMetalStart is already imported, you can just use it like this:
    annotation { "Feature Type Name" : "Sheet metal model New" }
    export const sheetMetalStartNew = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {...}
        {
            // Calculate K-Factor from definition
            definition.kFactor =
                        (-definition.radius +
                                ((definition.bendAllowance) /
                                        (PI / 2)))
                        / definition.thickness;
                    definition.kFactorRolled = definition.kFactor;
            sheetMetalStart(context, id, definition);
        });
    The code for calculating the K-Factor from the BA is from Wikipedia (It is my implementation of it)
    took a bit to realize what you just did, yea that did it for me thanks!
Sign In or Register to comment.