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.

Changing name of part to it's length using Beam FeatureScript

marco_teixeiramarco_teixeira Member Posts: 1
edited March 2018 in FeatureScript
I tend to use the Beam FeatureScript alot in my projects, and thanks to the new BOM update its way easier to indicate parts in drawings.
So instead of having the parts being generated with the name "Part 1" etc. I want to have the name of the profile and the length in the name.
I have done the profile name part sucessfully however i cant get the length.
Here's what i have done:

var partName is string = definition.profile.size;
partName ~= "x";
partName ~= /*total lengh of part*/

setProperty(context, {
                    "entities" : qCreatedBy(id, EntityType.BODY),
                    "propertyType" : PropertyType.NAME,
                    "value" : partName
});

I got to the point of out putting some length values but they were pretty much all sketch lines summed up and the length comes in the form of ValueWithUnits and i only want the "Values" contained in it.
i used this line to do the above: evLength(context, {entities : definition.edges});
I want each individual line selected to have its length.
Does anyone have a solution for this?

Thank you

Comments

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    edited March 2018
    As always, sharing a document will make answering the questions easier!

    In the most likely case, evLength is the correct solution. For the "entities" there, you will want to pass in an individual edge, i.e. one element of the array returned by evaluateQuery(context, definition.edges)
    Similarly, you'll want the "entities" of the setProperty call to point to a single beam. As for how that should be accomplished, it will depend on the layout of your current feature code – you want to make sure the right length gets attached to the right beam!

    Let us know if you have further questions.

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    It may also be helpful to note that you can do the following to get your length in whatever unit you desire (lengths are always stored in meters, so the .value field of the valueWithUnits will always be in meters):

    // lengthWithUnits is of type ValueWithUnits
    var lengthWithUnits = evLength(...);
    
    // lengthInInches and lengthInMillimeters are both raw numbers
    var lengthInInches = lengthWithUnits / inch;
    var lengthInMillimeters = lengthWithUnits / millimeter;
    
    // These are both strings
    var inchString = lengthInInches ~ "in";
    var millimeterString = lengthInMillimeters ~ "mm";

    Jake Rosenfeld - Modeling Team
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,714
    It's been a while since I wrote that feature, but remember that the length of the beam does not always equal the length of the sketch line (due to trimming or extending). Best way to measure each beam would be to do an evBox3d using the beam's sketch normal as the Csys.
    Senior Director, Technical Services, EMEAI
Sign In or Register to comment.