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.
Add tooltip to feature
CAD_SSP
Member Posts: 45 ✭✭
How do you add a tooltip to a feature like the builtin ones?
If you add a "Hole" and hover over "Sketch points to place holes" you get a tooltip saying "No points selected" and on a chamfer if you hover over "Entities to chamfer" you get a tooltip "select edges or faces to chamfer".
I cant locate the tooltip text anywhere in the open source documentation to show how they do it
If you add a "Hole" and hover over "Sketch points to place holes" you get a tooltip saying "No points selected" and on a chamfer if you hover over "Entities to chamfer" you get a tooltip "select edges or faces to chamfer".
I cant locate the tooltip text anywhere in the open source documentation to show how they do it
Tagged:
0
Best Answer
-
Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646Hi @keith_marsh
What you're actually seeing is the text of the error string when an error is thrown and attributed to that query box. To illustrate what I mean, you can do the following:- Create a chamfer feature and select nothing. Hover over the red chamfer in the Feature List. Hover over the red title of the feature. Hover over the "Entities to chamfer" box. Notice that they all contain the same error "select edges or faces to chamfer"
- Fill the "Entities to chamfer" box. Now notice that none of the three locations in the last step yield "select edges or faces to chamfer".
annotation { "Feature Type Name" : "Failing feature" } export const failingFeature = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Query 1", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 } definition.myQuery1 is Query; annotation { "Name" : "Query 2", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 } definition.myQuery2 is Query; } { });
This will create a feature with two query boxes.
Add the following code to the feature definition:if (size(evaluateQuery(definition.myQuery2)) == 0) { throw regenError("Query 2 cannot be empty"); }
Now go and create an empty instance of this feature. Hover over the Feature List, title, and "Query 2" box. Notice that the Feature List and title show the error string, but the "Query 2" box does not.
Modify the code so it looks like this:if (size(evaluateQuery(definition.myQuery2)) == 0) { throw regenError("Query 2 cannot be empty", ["myQuery2"]); }
Now go back and look at the failing feature again. Now, the "Query 2" box will be red, and hovering over it will display the error as desired.
You can see more about errors in the following places of documentation:
https://cad.onshape.com/FsDoc/library.html#module-error.fs
https://cad.onshape.com/FsDoc/output.html ("Error Handling" section)
But you're right that this documentation doesn't have the information you were looking for.
Hope this helps! Let us know if you have more questions.Jake Rosenfeld - Modeling Team6
Answers
What you're actually seeing is the text of the error string when an error is thrown and attributed to that query box. To illustrate what I mean, you can do the following:
- Create a chamfer feature and select nothing. Hover over the red chamfer in the Feature List. Hover over the red title of the feature. Hover over the "Entities to chamfer" box. Notice that they all contain the same error "select edges or faces to chamfer"
- Fill the "Entities to chamfer" box. Now notice that none of the three locations in the last step yield "select edges or faces to chamfer".
Here is an example of how to do this yourself. First, define the following feature:This will create a feature with two query boxes.
Add the following code to the feature definition:
Now go and create an empty instance of this feature. Hover over the Feature List, title, and "Query 2" box. Notice that the Feature List and title show the error string, but the "Query 2" box does not.
Modify the code so it looks like this:
Now go back and look at the failing feature again. Now, the "Query 2" box will be red, and hovering over it will display the error as desired.
You can see more about errors in the following places of documentation:
https://cad.onshape.com/FsDoc/library.html#module-error.fs
https://cad.onshape.com/FsDoc/output.html ("Error Handling" section)
But you're right that this documentation doesn't have the information you were looking for.
Hope this helps! Let us know if you have more questions.
This aborts the feature with an error, puts one parameter ("locations") in an error state, and provides an error message which is used as the tooltip for that parameter. In the case of hole (a standard feature), a special error key was used (internally, this key will become a different localized message depending on the end user's language, and you can find the English translations for our existing error messages written as comments in errorstringenum.gen.fs ).
For custom features, you can simply provide an english error message: Note that this behavior is specific to error cases (usually those which are present when a user first opens the feature).
(Whoops, looks like Jake got there first, with a much more thorough explanation. Sorry for the redundancy!)