Tips for writing reusable code
EvanReese
Member, Mentor Posts: 3,100 PRO
I'm new to code of any kind, so perhaps this is obvious, but is there a clean way to reuse feature scripts and update them all from a central place? I'd love to be able to write an "edge selection" module that can just be imported into new custom features to create parts of the UI and selection logic. I'd like to have the option to update all features using the module from a central place. I see things in the standard Onshape library that seem to do this but I don't fully get how, and what the limitations are.
0
Answers
-
@Evan_ReeseEvan_Reese said:I'm new to code of any kind, so perhaps this is obvious, but is there a clean way to reuse feature scripts and update them all from a central place? I'd love to be able to write an "edge selection" module that can just be imported into new custom features to create parts of the UI and selection logic. I'd like to have the option to update all features using the module from a central place. I see things in the standard Onshape library that seem to do this but I don't fully get how, and what the limitations are.
How the standard library works is that it is all in one workspace.
I ran into this problem a few times.
I had created a simple library to make creating a Cutout FeatureScript easier, by providing predicates for the definition and a simple library of functions (https://cad.onshape.com/documents/2ad339efe44128f5171291fa)
I also had created a library to evaluate expressions, by tokenising them, then converting them to RPN notation, then finally evaluating it, returning an error code if a variable wasn't found. (https://cad.onshape.com/documents/429fd7dda5f0fdb93833a34a)
I find that the easiest way is to just have a simple document with the main code and test cases. You can then create versions of this and import it into other documents. The disadvantage of this approach is that it isn't easy to see what documents use that library.0 -
0
-
@MBartlett21 can you please give us access, I too would like to see how you're breaking up your programs.

thanks0 -
@MBartlett21
I'm getting the same error on the first link (https://cad.onshape.com/documents/2ad339efe44128f5171291fa)0 -
0

