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.

setFeatureComputedParameter leaving quotes

DSPuzzlesDSPuzzles Member Posts: 17 EDU
edited November 2018 in FeatureScript
I am currently making a feature that requires using the setFeatureComputedParameter function to set a custom label. However, when I use it and I pass a custom string onto the function, it leaves quotes around the name in the feature tree.

For example, if I do setFeatureComputedParameter(context, id, { "name" : "label", "value" : "World" }), and my Feature Name template is "Hello #label", the feature tree shows up as "Hello World", quotes included, instead of just Hello World.

Interestingly enough, it does not happen if I set the # to #name and I pass the string stored in a definition.name parameter (ie: setFeatureComputedParameter(context, id, { "name" : "name", "value" : definition.name })). If I do that, everything works and there are no quotes for some reason, and I can't quite figure out why.

Any help is appreciated. Thanks.
Tagged:

Answers

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Previous discussion here:
    https://forum.onshape.com/discussion/comment/30842#Comment_30842

    How would you feel about the solution proposed there? What would be a helpful name for that type?
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    @Disousa any variable set in the precondition will set the feature name without having to use setFeatureComputedParameter. 

    i.e. definition.label will set #label without any extra code. 

    #name is a special reserved case that will not add quotes (as used in variable.fs) - not sure why. 
    Senior Director, Technical Services, EMEAI
  • DSPuzzlesDSPuzzles Member Posts: 17 EDU
    @kevin_o_toole_1 That would work. But I'll leave the suggestion of maybe using italics/color for user inputted text instead of quotes. It would look more elegant.

    I think the need for differentiation between user-text and interface-text is there, but in the case of the custom feature defining a label, there is currently no way of making it not seem like user-text. What about using different symbols for a user-label (#label) that creates quotes and feature label (eg: $label) that does not?

    @NeilCooke I was not aware of this. I will try a workaround where definition.name is defined via code (outside the precondition) and used to set the label.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,308
    @Disousa I don’t think that will work
    Senior Director, Technical Services, EMEAI
Sign In or Register to comment.