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.

Can I reference Mass Properties in an Expression?

adrian_vlzkzadrian_vlzkz Member Posts: 266 PRO
Could find anything on the help, basically trying to see if I can use "system" values when writing an Expresion for a Variable. (Mass, Volume, Density...)
Adrian V. | Onshape Ambassador
CAD Engineering Manager
Tagged:

Answers

  • brucebartlettbrucebartlett Member, OS Professional, Mentor, User Group Leader Posts: 2,140 PRO
    I don't think so but this would be and handy
    Engineer ı Product Designer ı Onshape Consulting Partner
    Twitter: @onshapetricks  & @babart1977   
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @adrian_velazquez

    It would be pretty easy to make a "measure volume" custom feature which sets a variable to the volume of a selected part.  Density (and hence, mass) are trickier because FeatureScript does not have access to the material assignment of a part.  What is the overall goal here?
    Jake Rosenfeld - Modeling Team
  • adrian_vlzkzadrian_vlzkz Member Posts: 266 PRO
    The goal is to Drive a shape (a couple of dimensions) based on a specified weight.
    Adrian V. | Onshape Ambassador
    CAD Engineering Manager
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @adrian_velazquez

    Maybe I misunderstood.  Do you just want to set a variable to "3 m^3" or "10 kg", or do you want to set a variable to the measured volume/mass/density of an existing part? 
    Jake Rosenfeld - Modeling Team
  • adrian_vlzkzadrian_vlzkz Member Posts: 266 PRO
    I want to set a Variable to 1kg then have my dimensions driven by an expression that uses the Volume. Density would be needed in my expression to know my target Volume
    Adrian V. | Onshape Ambassador
    CAD Engineering Manager
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646


    This should be possible using an "any" variable
    Jake Rosenfeld - Modeling Team
  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
    edited February 2019
    Can you pass the context to a variable's function?

    function() { return evVolume(context, {"entities" : qEverything(EntityType.BODY)}); }



    Hoping this will return the volume of all parts at the position it's in the tree.


  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,210
    No, we deliberately block usage of context in expressions (because it can lead to some really unintuitive results -- what if the user does an opSomething call in a parameter?) but a custom feature can easily do thiis.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • shouldNotBePostingshouldNotBePosting Member Posts: 10 PRO
    Honestly, referring to featurescript from the variable function may not be necessary, I still had to lookup evVolume. If you're at the need level, just write a featurescript, I can do it in 3 lines of code and have greater functionality with featurescript vs. a 1 line function call.

    I'm going to write a featurescript to set these variables. This is all that needs to be done. Adrian's request is still valid. Why aren't these already being set? The benefit with a feature script is that you can ask which parts to include in a volume calculation which is useful. The globals that you set in a partstudio will have to be "all".


  • shouldNotBePostingshouldNotBePosting Member Posts: 10 PRO
    edited February 2019


     
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,210
    @shouldNotBePosting
    Not sure if I understand your question, but mass properties can be expensive to compute -- we should not be doing it without the user asking.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • billy2billy2 Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,068 PRO
    Sorry, I've got too many computers and too many accounts.

    @ilya_baran thanks, I think I have this under control. I'm going to have a featurescript write the volume to a variable using a featurescript.  


Sign In or Register to comment.