
Grandkid_ops = concat( //- grandkid-specific default With this, we actually achieve a subclassing-style coding pattern, so that we can design complex module and inherit from it.Īlso note that this "mother-child" relationship can go on forever. So the users or next-step-developer can enter any individual_ops to Wrench_1, in which the len be set to 12, and then the whole "hash bundle" ( Wrench_1_ops ) be sent to Wrench(), in which it is processed against the wrench_default. Note that in Wrench_1, users can set any parameter but "len", 'cos it will be set to 12 no matter what. is passed to "update" the wrench_default of mother wrench. Wrench( Wrench_1_ops ) // calling the "mother wrench", in which this Wrench_1_ops , individual_ops //- user-input ops for Wrench_1 Wrench_1_ops = concat( //- Wrench_1-specific default , // wrench_defaultĪnd then, "subclassing" from Wrench, to make a specific type of wrench like: But since the hash() reads data from left to right and stops whenever the key is found so it will give us the new "len", 12, making the data look like it is updated.Ĥ) With this coding pattern, we can define the basic wrench, the mother of all wrenches, like: Which gives us the "working as updated" data :


Ops = concat( individual_ops, wrench_default ) But, we can cheat this by a simple concat : And it will take much more than just a function to come up with a feature like that. In OpenScad, however, we don't have hash, let alone update.

Ops = update( wrench_default, individual_ops ) Usually such an action is performed by an update function: So there's a need to modify the hash bundle on the fly. For example, "len" might be different for different types. If there are 5 types of wrenches, although they share lots of common wrench parameters, we can't expect all types to share all parameters. It means we save a lot of hassle on re-typing the same things, and the global space will not be polluted by variables that are not supposed to be global in the first place.ģ) But this is not quite enough. With this, we are able to encapsulate the parameters and throw them around as a whole " hash bundle". Len = ops("len") // convert to local scope Wrench_default = Ģ) Secondly define a hash function to get value:Īnd since functions and variables use different name spaces, we can take the advantage and define this function:įunction wrench_default(k) = hash( wrench_ops, k) I encountered this situation quite often and here is how I dealt with it.ġ) First define an array to encapsulate/group similar parameters in a pattern of key-value pairs:

I think that would become almost unreadable.Īny hints on a good way to handle this? Or options I should consider? I considered creating an object/module with those dozen parameters, but
#Openscad models code
This approach is clear, but those code blocks now take up aįew pages, so skipping over them to get to the real code is laborious. Objects, and I ensure that the object of interest has its code block at I haveĪbout 10 blocks of code that define the parameters for each of my 10 There are about aĭozen parameters that have to be set for each object.Īt the moment, I use global variables for these parameters. Think of itĪs if I want to create a family of crescent wrenches. I have an OpenSCAD file that creates a family of objects.
