Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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_cowdendave_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?

Best Answer

Answers

  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    ok thank you! I am not using setFeatureComputedParameter, so that's probably what i'm missing!
  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    Hi, @kevin_o_toole_1

    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:

    <div>&nbsp; &nbsp; annotation { "Name" : "friendlyName", "UIHint" : "ALWAYS_HIDDEN" }</div><div>&nbsp; &nbsp; definition.friendlyName is string;</div>



    I have a function that given the context and definition gives me a friendly name:

    <div><div>function computeFriendlyName(context, definition, diameter)</div><div>{</div></div>...<br>}<br>

    My feature uses the name in its title:

    <div>annotation { "Feature Type Name" : "ThreadCreatorTest", "Feature Name Template" : "#friendlyName", "Editing Logic Function" : "screwEditLogic" }</div><div>export const threadCreatorTest = defineFeature(function(context is Context, id is Id, definition is map)</div>


    In the editing logic function, i'm setting the definition name, and using setFeatureComputedParameter:


    <div>&nbsp; &nbsp; definition.friendlyName = computeFriendlyName(context, definition);</div><div>&nbsp; &nbsp; setFeatureComputedParameter(context,id, { &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "name": "friendlyName",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "value": computeFriendlyName(context, definition)</div><div>&nbsp; &nbsp; }); &nbsp;</div>

    I'm also doing it in the main logic of the feature;

    <div>&nbsp; &nbsp; setFeatureComputedParameter(context,id, { &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "name": "friendlyName",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "value": computeFriendlyName(context, definition)</div><div>&nbsp; &nbsp; }); &nbsp;</div>
    With all of this, I get the name computed once, but never again unless the editing logic function runs.   I have successfully eliminated lots of ways that DONT' work:

    • remove the definition from the feature. This simply gives a ? in the description
    • remove the setFeatureComputedParameter from each and both locations. This has no affect at all-- without it, we get a value when the editing logic function runs, and we do not get it when we dont.

    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? 

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    I don't have time for a deep dive now (and I do apologize for the lack of documentation of this functions), but setFeatureComputedParameter was used by old versions of the variable feature, so for a simple example, look here:
    https://cad.onshape.com/documents/12312312345abcabcabcdeff/v/afe256a70b2f06312dadeefd/e/357eadcd05424ef4a2360e88

  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    Yes, that's pretty much how i'm using it ( see above), but I cannot get it to work. It updates the first time, but not when the geometry updates outside of the feature.
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Okay. In that case I'm not sure what the problem could be. A simple example I tried is updating fine:
    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).

  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    ok thanks Kevin for the example!. I'll use it as a guide to build one. 
  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    edited October 2016
    Hi, @kevin_o_toole_1

    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 )
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Aha! Yes, that would be the problem.

    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.

  • dave_cowdendave_cowden Member, Developers Posts: 475 ✭✭✭
    ok thanks. let me know when the supported functionality changes-- i'll update my code then. for now, i'll go back to using a string value on the definition, and updating it only when the user changes it. that's better than always getting ?mark.
Sign In or Register to comment.