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.

Variables and FeatureScript

Dylan_StewartDylan_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.
Digital Engineering

Best Answer

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Answer ✓
    @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!

Answers

  • Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    @lougallo @kevin_o_toole_1 @cody_armstrong
    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 
    Digital Engineering
  • lemon1324lemon1324 Member, Developers Posts: 225 EDU
    edited August 2016
    You should be able to do that with the getVariable() and setVariable() functions, documented under "context" in the FS library documentation.

    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.
    Arul Suresh
    PhD, Mechanical Engineering, Stanford University
  • Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    Maybe a cube was a bad example...

    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.
    Digital Engineering
  • lemon1324lemon1324 Member, Developers Posts: 225 EDU
    Ah, so parameter-driven configurations, basically.  I'm pretty sure this isn't possible in Onshape yet, though configurations have been requested.

    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.
    Arul Suresh
    PhD, Mechanical Engineering, Stanford University
  • Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    @lemon1324

    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? 
    Digital Engineering
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    Answer ✓
    @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!

  • thomas_lampertius037thomas_lampertius037 Member Posts: 6 EDU
    @kevin_o_toole_1 is it possible in the lastest version of Onshape?
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,211
    The specific functionality Kevin is talking about is configurations, released here: https://forum.onshape.com/discussion/7975/improvements-to-onshape-january-2nd-2018/p1  Neil is showing how to use them in combination with FeatureScript.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.