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.
FS to remember previous selections
ben_partouch
Member, csevp Posts: 138 PRO
Hi all,
Anyone with suggestion on how to get my custom feature to remember the selections from the previous use?
(I mean only in the same part studio)
This was brought up here a while ago but I couldn't really use the info in the discussion.
Thank you.
0
Comments
I actually just wrote a blog article about this. Another user messaged me with the same question.
You can read the article on my website:
https://www.smartbenchsoftware.com/post/reading-previous-feature-inputs
It includes a sample feature if you want to see it in action.
Custom FeatureScript and Onshape Integrated Applications
Thanks @Caden_Armstrong . That would be me, as I was wondering about the likelihood of this IR being possible. You managed to quickly implement a solution to it.
I have some thoughts on the topic, but I'll add it to the IR
Custom FeatureScript and Onshape Integrated Applications
@Caden_Armstrong Thank you! I'm very excited to give this a try.
@Caden_Armstrong if I understand correctly this should work for queries as well?
It works for everything else but the queries.
Thank you🙏
@ben_partouch The way I demoed here is pretty similar to what Caden shows in his article except he's storing the queries with setAttribute() not setVariable(). Happy to answer questions as well.
The queries will work, if they are still valid. If operations happen in between that change entity IDs, the queries are no longer going to resolve.
Custom FeatureScript and Onshape Integrated Applications
@EvanReese, @Caden_Armstrong,
Thank you both. Much appreciated🙏
I shifted to Evan's method only because it's not tied to an external feature I wanted to keep things simple as this is already pretty complex for my FS knowledge.
I still can't make it to work. Maybe I'm not placing the getVariable function in the right place. The executing part of my code is pretty busy, mostly with functions that measure my selections. Should I share this with you?
Thank you.
I think I got it. Thank you!
@EvanReese what if I have multiple queries? Should I duplicate the relevant snippets? Thank you.
@ben_partouch Caden's way can be within the same feature too fyi. I can't think of any big pros/cons to either, but would love to learn if there are any.
If you have multiple queries, then yes, in principle you could duplicate those parts of the code, but I think if you're doing it multiple times or using this technique in more than one custom feature, you should write them into a reusable set of functions. It makes the code more readable, and makes edits and bug fixing easier.
@EvanReese
I tried this and yet, only the selections for Height are working and not for Depth.
Thank you and happy Thanksgiving!
export const variableName1 = "@qx*AYW@tbxxh5t";
export const variableName2 = "@qx*AYW@tbxxh6t";
annotation { "Name" : "Already set once1", "Default" : false, "UIHint" : UIHint.ALWAYS_HIDDEN}
definition.alreadySet1 is boolean;
annotation { "Name" : "Already set once2", "Default" : false, "UIHint" : UIHint.ALWAYS_HIDDEN}
definition.alreadySet2 is boolean;
try silent
{
getVariable(context, variableName1);
if (definition.alreadySet1)
{
setVariable(context, variableName1, definition.entitiesForHeight);
}
}
catch (error)
{
setVariable(context, variableName1, definition.entitiesForHeight);
}
try silent
{
getVariable(context, variableName2);
if (definition.alreadySet2)
{
setVariable(context, variableName2, definition.entitiesForDepth);
}
}
catch (error){
setVariable(context, variableName2, definition.entitiesForDepth);
}
export function editingLogic(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean, specifiedParameters is map, hiddenBodies is Query) returns map
{
if (isCreating && !definition.alreadySet1)
{
try silent
{
definition.entitiesForHeight = getVariable(context, variableName1);
definition.alreadySet1 = true;
return definition;
}
}
if (isCreating && !definition.alreadySet2)
{
try silent
{
definition.entitiesForDepth = getVariable(context, variableName2);
definition.alreadySet2 = true;
return definition;
}
}
Played with it a bit. The issue is in your editing logic. the return stops the rest of the function from completing. Try only doing one return at the end of it instead.
@EvanReese Perfect, all set.
Thank you, really appreciate it.
Enjoy the weekend.