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.
Variables and FeatureScript
Dylan_Stewart
Member, Developers Posts: 107 PRO
I am trying to create a 'template cube' to be imported in to a featurescript so that I may place a cube in a new part studio using a feature.
The problem I am having is I want the cube to be driven by a variable.
So can I 'get' the variable via FS from the part studio and then in the UI of the FS 'set' the variable and have the model update?
I feel like I have seen this done before but can't seem to find the thread/document giving me an example.
The problem I am having is I want the cube to be driven by a variable.
So can I 'get' the variable via FS from the part studio and then in the UI of the FS 'set' the variable and have the model update?
I feel like I have seen this done before but can't seem to find the thread/document giving me an example.
Digital Engineering
0
Best Answer
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565@Dylan_Stewart
What you're describing is not possible yet, but definitely on our timeline.
Right now, a Part Studio defines a build function, which takes zero arguments, and outputs one or more parts in the Context.
You can imagine many possibilities if any Part Studio could take arguments into its build function... you could pass in these arguments via FeatureScript like you're describing, but also from assembly insertion or derived feature. I won't say much more, but stay tuned as Onshape and FeatureScript continue to evolve!
2
Answers
I feel like it was one of you that explained this to me once before.
Here is the document that I am working in right now.
https://cad.onshape.com/documents/fb05828f81a7f5b855ce9fb5/w/ff59ad7f7d768d717aaff556/e/1e0c2f988e5f4f430b8907b4
Edit: If you're trying to read a variable in one part studio and then create a cube of that size in a different part studio, I don't believe that's possible given how FS is sandboxed. You could write a FS that simply defines variables and then include it as the first feature in every part studio you want access to those variables.
PhD, Mechanical Engineering, Stanford University
Take a picture frame that is already modeled and now place the imported file in to a FS and call it in another part studio.
Use the FS to place the picture frame and give it a width and height dimension inside of the UI of the FS.
I also don't think you can call the FS generated by a part studio--this came up in a different discussion on the forum, and if I remember correctly, being able to view a part studio's code is just for reference. Even if you did, it also contains the code setting the variables to whatever they were in the part studio, and you wouldn't be able to modify the value in the middle of executing the part studio code using the calling FS you wrote.
PhD, Mechanical Engineering, Stanford University
I think I remember seeing the same thing... This is frustrating me a bit.
But, I would like to explore the get and set variables...
Do you have any examples or just a quick document you can collaborate with me for learning purposes?
What you're describing is not possible yet, but definitely on our timeline.
Right now, a Part Studio defines a build function, which takes zero arguments, and outputs one or more parts in the Context.
You can imagine many possibilities if any Part Studio could take arguments into its build function... you could pass in these arguments via FeatureScript like you're describing, but also from assembly insertion or derived feature. I won't say much more, but stay tuned as Onshape and FeatureScript continue to evolve!
https://cad.onshape.com/FsDoc/library.html#getVariable-Context-string
https://cad.onshape.com/FsDoc/library.html#module-instantiator.fs
https://cad.onshape.com/FsDoc/uispec.html