

First time visiting? Here are some places to start:



Re-usable code

john_mcclaryjohn_mcclary Member, Developers Posts: 1,996 PRO
edited October 2018 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


Best Answers


  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 911 ✭✭✭✭✭
    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,613 EDU
    edited October 2018

    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.)

    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,996 PRO
    edited October 2018
    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,337

    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:
    Jake Rosenfeld - Modeling Team
  • lanalana Onshape Employees Posts: 469
    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,996 PRO
    so would these functions need to be exported in SheetMetalStart.fs in order to access them?

  • john_mcclaryjohn_mcclary Member, Developers Posts: 1,996 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)
            // 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.