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.

Options

set field default to variable

I am using the FeatureScript "Wiring" provided by Onshape to do a bunch of routing. I want the size of the wires to be dependent on a variable, #WireDiameter. I would like for this variable to be the default value in the "diameter" field, so I don't have to copy it in every time. Is there any way to have the default values given in "isLength" be variables, rather than numbers?

Comments

  • Options
    kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Not as such. That default value is stored statically as part of the custom feature type, and not recalculated dynamically in an environment that knows about external variables.

    A possible workaround is to copy the wiring feature and add an editing logic function that:
    • Is only called on creation (i.e. leaves out the isCreating parameter)
    • Checks the context for a #WireDiameter variable (via getVariable)
    • If that variable exists, sets the "definition.diameter" field to its value
    If coding this sounds worthwhile to you, let us know if you encounter any issues!

  • Options
    jonathan_mizrahi827jonathan_mizrahi827 Member Posts: 5 PRO
    Thanks for the suggestion, I will try that.

    One other issue that came up -- I noticed that in that feature if I set Starting Straightness or Ending Straightness to a variable, and then I change that variable, the displayed length of the wire does not update. To get it to update, I have to change it, and then change it back to the variable, and then it updates the displayed length. Is there a way to get it to update automatically when the variable value changes?
  • Options
    jon_sorrellsjon_sorrells Onshape Employees Posts: 51
    I noticed that in that feature if I set Starting Straightness or Ending Straightness to a variable, and then I change that variable, the displayed length of the wire does not update. To get it to update, I have to change it, and then change it back to the variable, and then it updates the displayed length.
    That's a bug in the Wiring feature.  It only updates the length in the editing logic function, so if that doesn't run the feature name won't update.  Using setFeatureComputedParameter to set 'length' to the appropriate value at the end of the feature should fix the problem.
  • Options
    ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,175
    It should also be possible to set an expression of a parameter from an editing logic function: instead of using the value of the variable, try setting the parameter to the string "#WireDiameter".
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.