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.
Feature Name doesnt update
dave_cowden
Member, Developers Posts: 475 ✭✭✭
I'm computing a feature name inside of my editing logic function, and it works fine.
In my case, I want the name to include information that is based on things external to the feature, for example a diameter that is selected as an input to the feature.
I've noticed that when the model is updated externally, the feature name is not changed. I wasn't really surprised about that-- so i added code to re-compute the name from within the render function itself, and that still didnt work.
Am i doing something wrong, or should it be possible to have the name of the feature update in response to changes outside of the feature?
In my case, I want the name to include information that is based on things external to the feature, for example a diameter that is selected as an input to the feature.
I've noticed that when the model is updated externally, the feature name is not changed. I wasn't really surprised about that-- so i added code to re-compute the name from within the render function itself, and that still didnt work.
Am i doing something wrong, or should it be possible to have the name of the feature update in response to changes outside of the feature?
0
Best Answer
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565Not having your code, it's hard to say what's going wrong. setFeatureComputedParameter() is the function that adds dynamically updating values to a feature name, and that function should give you the behavior you want.
A working example of it is in Onshape's variable feature.5
Answers
A working example of it is in Onshape's variable feature.
Ok i had a look at variable.fs, and i did find setFeatureComputedParameter, but after a very frustrating hour trying out every combination I could come up with, I cannot get it to work.
I can get the feature name to update when you create the feature the first time, and when you open the feature dialog to change it-- but not when the model updates.
I've got too much code to paste it all, but here's the relevant parts:
feature precondition:
I have a function that given the context and definition gives me a friendly name:
My feature uses the name in its title:
In the editing logic function, i'm setting the definition name, and using setFeatureComputedParameter:
I'm also doing it in the main logic of the feature;
setFeatureComputedParameter refers to variable.fs as an example, but setFeatureComputedParameter is not called anywhere in std, so I cannot see any examples of how to use it correctly. What's the magic?
https://cad.onshape.com/documents/12312312345abcabcabcdeff/v/afe256a70b2f06312dadeefd/e/357eadcd05424ef4a2360e88
https://cad.onshape.com/documents/654abccb4b71b717122f4809/w/443cff5cbfa5c86c47780dfa/e/9fa406dbd02659e104393642
One possibility is that you're setting a parameter on the definition whose name matches the computed parameter you set, and the definition parameter (which doesn't update) is overriding the computed one (which does update).
Ok, i think i figured this out. Does setFeatureComputedParameter by chance require a numeric value? I changed your example from this, which works:
setFeatureComputedParameter(context, id, { "name" : "r", "value" : radius });
to this, which does not:
setFeatureComputedParameter(context, id, { "name" : "r", "value" : "R" ~ radius });
In short, this method doesnt appear to support strings.
I cannot use the method you did, because in my case the entire string is dependent on the geometry, not just a single numeric value. IE, it is not possible for me to reduce the description to a static string with numbers thrown in.
Using a hidden definition field, like this:
definition.hiddenName = <whatever>
does allow string to appear in the name, but in that case, the value cannot be dynamically updated according to model changes.
Please consider this an improvement request to allow computing strings that become part of the description. Otherwise, its not really possible to create a nice description, such as M20-5 x 0.75 LH ( which is what i'm trying to do here )
Looks like we have code on the client side which only displays that value when it's a quantity or number. We're currently doing work to make parameters in dialogs more generic and compatible with all FeatureScript types. I've written up your bug and I think it can be fixed as part of that effort.
However, since the new functionality involves changes to mobile apps as well as the browser, that means even after it's fixed, the new behavior won't be there on iOS and Android until people update, and I believe we don't force an upgrade until those users are >2 versions back.
In the mean time, I don't see a workaround that gives dynamic updating. As you've said, putting a string value on the definition will display it fine, but your editing logic function isn't going to run unless the feature is actually edited.