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.
Featurescript: building arrays
jrs_spedley
Member Posts: 71 ✭✭
I need to build an array of values and nested arrays in featurescript. They won't be long arrays, typically 100 items for all items but I'm concerned about the "append" command which says "Returns a copy of an array with a single value added to the end." Is there a better way?
I could use a 'map' with an index but it is a lot of extra complexity.
I could use a 'map' with an index but it is a lot of extra complexity.
0
Comments
I take it by latest version you mean the import(path : "onshape/std/geometry.fs", version : "660.0"); How do I find out what the latest version is, I've looked around the website but can't see a list of updates (changelog) for the std files?
Will look into the profiler more, didn't think of checking that for myself.
If implemented in a language like C, your concerns about append() would absolutely be legitimate. However, in FeatureScript, the language is internally implemented to optimize out the performance and memory concerns of this case and many others like it.
In our documentation, you can read that all FeatureScript values have value semantics (except for a box, which behaves like a pointer in C). This means that, following a statement like
newArray = append(oldArray, "newThing");
, a change to newArray will not change oldArray.What's not in the docs yet is that these value semantics are internally implemented as copy-on-write. This means that, if you don't change either array, the two will secretly share the same location in memory. This memory sharing is completely opaque to the author. The language itself will take care doing the copying when necessary, so to a FeatureScript author, it appears that a copy was made all along.
In the case of arrays and maps, that copy-on-write behavior also applies recursively to values within the array (so that, after one element is changed int a large array, most of the memory will still be shared).
Within this implementation, building an array with append() is a critical specific case we've optimized for. This means append() is in practice the fastest way to populate an array in FeatureScript (faster, even, than using makeArray() and setting all its elements).
Hope this helps. BTW, profiler update is from: https://forum.onshape.com/discussion/6102/improvements-to-onshape-march-24th-2017
There are a couple different ways you can find the correct number. The easiest is probably making a new document, and making a Feature Studio in that document, and checking what number is at the top of that Feature Studio.
The more exact way of doing this is actually looking at the standard library version. Here is the Onshape standard library:
https://cad.onshape.com/documents/12312312345abcabcabcdeff
It can be found by searching 'std' on public documents, and looking for the one that is owned by Onshape (but we are looking to make it easier to find in the future).
The current version is accessible by looking at its version graph (or any of the imports in any of the files of the library):
So, your answer for right now is 1036.0
HWM-Water Ltd