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.

New Custom Feature: Rename Beams

SethFSethF Member Posts: 129 PRO
This is mostly just recycled code from the beams feature. In our case, it's really nice to have the beams named accurately, including the length, which obviously changes with move faces or what have you. So the idea is that you put this feature after all of your manipulation to the beams, it remeasures the length, and sets a new name.

https://cad.onshape.com/documents/6d2b1edc58ecf1f27385a36d/v/8a838befd9737ddf11bfe069/e/26552c6e3aabd627ba52bf99

Here's an example:

1) Make some beams


2) Mess up their lengths


3) Rename them:



As you can see in the example, you have the option for a second unit in case you would like to show the length in both inches and mm, for example. As you can also see in the example, it has the short coming of not being able to change your naming options for individual Beam features. Initially I had made my own copy of the Beams feature, added some new attributes for me to use, and then grabbed those in rename. That way I could add to the name that was already selected (minus the incorrect length). But I didn't want to have to add in code every time the Beam feature is updated. So for now, using this feature, if you want the Standard listed for one beam, you get the Standard listed for ALL the beams..

I'm a programming nooob. So. Sorry if the code is ugly.

Comments

  • MichaelPascoeMichaelPascoe Member Posts: 1,698 PRO
    edited September 2021
    Nice! Thanks for sharing.

    Welcome to featurescripting!

    Something that would have helped me a lot when I started are some simple JavaScript tutorials. If you don't already know JS, learning some basics will really help you with FeatureScript.

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • SethFSethF Member Posts: 129 PRO
    @MichaelPascoe Thanks! I'll have go through a few. I've only ever done the very basics in python.
  • matthew_stacymatthew_stacy Member Posts: 476 PRO
    @SethF, nice work.  That is a very useful feature script.

    What happens if you manually rename a part after running the RB script?  Is there a way to re-apply the feature script ... or have I severed the link permanently?

    In this linked document I manually edited the name of the first beam element.  Now the feature script only acts on the second part.


  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 130 PRO
    @matthew_stacy If you right click on the part, click "Properties," then click the "Reset All" button at the bottom left of the pop up, that will remove the manual link and allow the custom feature to take control again. 



    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
  • MichaelPascoeMichaelPascoe Member Posts: 1,698 PRO
    @chadstoltzfus
    That is a neat trick. Now I can use Part Name!

    Did you know about this trick @Evan_Reese?

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • matthew_stacymatthew_stacy Member Posts: 476 PRO
    Thank you @chadstoltzfus.  Your suggestion worked!

    Is there away to reset the part NAME only, so that you don't lose previously entered property attributes (description, part number, etc.)?
  • Evan_ReeseEvan_Reese Member Posts: 2,060 PRO
    edited September 2021
    @chadstoltzfus
    That is a neat trick. Now I can use Part Name!

    Did you know about this trick @Evan_Reese?
    I did. I guess I should add a note about that to the Part Name and Part Color documents. I've even considered doing a check in the feature to see if it's applied the property as intended and sending up a warning with instructions if it didn't work, but that's for another day.
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • chadstoltzfuschadstoltzfus Member, Developers, csevp Posts: 130 PRO
    @matthew_stacy To my knowledge there is currently not a way to reset a specific property. It's currently an all or nothing button. Could make for a good improvement request. 
    Applications Developer at Premier Custom Built
    chadstoltzfus@premiercb.com
Sign In or Register to comment.