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.

Duplicate part N times and alter extruded text based on string array of length N

sanford_mortonsanford_morton Member Posts: 3 EDU
Onshape community - as the title states I'd like to duplicate a part N times and alter extruded text on the part based on a string array of length N.

My motivation: I need to create N STL files with N people's unique names engraved on the part. When saving I can request onshape to save all the unique parts as their own STL file, saving me a great deal of time if N is large.

I think this is very possible to do with featurescript and I am experienced with programming, however I'm warming up to the syntax and was hoping for some guidance.

(1) Can someone critique my approach?
(2) Anyone have example code I could look at for patterning / duplicating parts? I'm running into simple syntax issues getting this to work (e.g. the transform variable type is throwing errors when I try to translate a part)

Thanks!

Answers

  • emagdalenaC2iemagdalenaC2i Member, Developers Posts: 545 ✭✭✭✭✭
    You don't need a FeatureScript, since the las upgrade of Onshape you can create configurations with the text

    https://cad.onshape.com/documents/08088a42c238903d7ed3fa7d/w/681d37f18ee34e713ebcf7a7/e/e4d164baeb4243b960c69859

    Un saludo,

    Eduardo Magdalena                           C2i Change 2 improve                           ☑ ¿Por qué no organizamos una reunión online?   
                                                                 Consulting Partner de Onshape                                      Averigua a quién conocemos en común
  • emagdalenaC2iemagdalenaC2i Member, Developers Posts: 545 ✭✭✭✭✭
    Un saludo,

    Eduardo Magdalena                           C2i Change 2 improve                           ☑ ¿Por qué no organizamos una reunión online?   
                                                                 Consulting Partner de Onshape                                      Averigua a quién conocemos en común
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 438
    I would recommend doing this with a small custom feature. However, with the right custom feature, it should be generic enough that you don't need to write anything more yourself, and the real magic can happen outside the custom feature.

    Take a look at this public document I just created:
    https://cad.onshape.com/documents/79364ddea3bca52fcc89c52c/w/1bcf4669bada2528631b80c8/e/cf7eebf1b4d07d7e39469dba

    There's four tabs there. The first is a generic part. The second is a straightforward custom feature which add some specified text at a specified base line (to make it a bit more generic I added a few bells and whistles to let you specify this text a few different ways).

    The last two are two different ways of making a series of parts with different text on them.

    "Parts with serial numbers" starts by deriving in the base part, sketching a position to put a serial number, and setting the serial number to the first number. Then, it copies the base part, calls the "add text" feature, and increases the serial number by one. The features in the previous sentence are then all patterned in a feature pattern, and finally, the base part is deleted.

    "Parts with names" is nearly identical. However, at the start, it defines an additional variable ("#Names"), which is set to a list of names in a variable with FeatureScript array syntax. (As the list of names gets large, you'll be happier editing it by copy-pasting to and from the text editor of your choice). Inside the "Add text" feature, the text is set to the expression "#Names[#Index]", which pulls in the right name inside the feature pattern.

    Note that in the second version, the pattern length is set to "size(#Names)", to ensure you don't have any sad extra parts named "undefined"! :smile:

    And, at the end of the day, you can export all these parts in separate files by simply right-clicking on the Part Studio > Export... > STL > Export unique parts as individual files. The individual file names will then be set according to the part name (which was set by the "Add text" feature to the text it wrote).

    Hopefully, you can take this simple custom features, add it to your toolbar, and build your own Part Studio with this same design pattern!

  • sanford_mortonsanford_morton Member Posts: 3 EDU
    @emagdalenaC2C
    I was actually looking into the text configuration feature earlier but was unable to figure out how to automatically change configuration for every duplicate part (e.g. for me N is greater than 60 so I don't want to manually duplicate and set a new configuration for each). If you are aware of a way to pattern the part and automatically have it assign the next text configuration in the list I'm all ears!

    @kevin_o_toole_1
    what a great way to leverage feature script to do this! I need to dig into the code you've written further. However I have one question for you:
    • Rather than use the featurescript to generate and place the sketch would it be possible for me to have a pre-placed (fully defined!) sketch with only text in it, and make one of the inputs to the featurescript that sketch itself, and then programatically edit the text as the part gets duplicated? 
    • The reason I ask: I have an intricate design where the text is has already been situated with much care, re-defining this might not be a huge deal but to me being able to select pre-placed text would make this script the most robust and handle the most general case. Curious to know your thoughts. If you're interested I can share a copy of the design. 
    Thanks for the responses guys! Really amazing to have such a helpful community at OnShape!


  • owen_sparksowen_sparks Member, Developers Posts: 2,264 PRO
    @kevin_o_toole_1

    (1) Great feature, thanks for writing and sharing it.

    (2) Please forgive the off topic question.  If someone were to be proficient in FS, how long should such a thing take to write?

    Cheers,

    Owen S.  
    Production Engineer
    HWM-Water Ltd
  • MBartlett21MBartlett21 Member Posts: 1,552 EDU

    (2) Please forgive the off topic question.  If someone were to be proficient in FS, how long should such a thing take to write?

    (2) Anyone have example code I could look at for patterning / duplicating parts? I'm running into simple syntax issues getting this to work (e.g. the transform variable type is throwing errors when I try to translate a part)

     There is a custom feature: https://forum.onshape.com/discussion/comment/34639#Comment_34639
    MB - I make FeatureScripts: view FS (My FS's have "Official" beside them)
  • owen_sparksowen_sparks Member, Developers Posts: 2,264 PRO
    @mbartlett21 ;
    Thanks for the link.  I was actually asking more from a return in investment of time spent learning FS, vs time saved by using the scripts.  I'm a big fan of FS already, but am wondering how much time would need to be invested in "getting proficient".

    Cheers,

    Owen S.  
    Production Engineer
    HWM-Water Ltd
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 438
    • Rather than use the featurescript to generate and place the sketch would it be possible for me to have a pre-placed (fully defined!) sketch with only text in it, and make one of the inputs to the featurescript that sketch itself, and then programatically edit the text as the part gets duplicated? 
    • The reason I ask: I have an intricate design where the text is has already been situated with much care, re-defining this might not be a huge deal but to me being able to select pre-placed text would make this script the most robust and handle the most general case. Curious to know your thoughts. If you're interested I can share a copy of the design. 
    The "Add text" feature makes its own sketch text with varying content, but it can't modify existing sketch text. Generally speaking, FeatureScript can't modify the inputs to existing features and sketches, it can only directly modify the geometry, or create new geometry.

    For your case, this shouldn't be a problem at all. You can define your baseline by either making a sketch on top of your old sketch, or simply by using the existing construction line at the bottom of the sketch text you already have. The Add text feature shouldn't care about the existing text, it will happily make its own.

    (2) Please forgive the off topic question.  If someone were to be proficient in FS, how long should such a thing take to write?
    The overall design here was mostly based on a similar design I built... well, almost exactly two years ago, right around the time FeatureScript was first released!
    https://cad.onshape.com/documents/cdbad61ec176b39049f8d4c1/w/0cb06ca7cb2788345cc7a448/e/c1778a16ae172747eaf7b147

    So, the design of this custom feature itself more or less fell into place (less than an hour). Iteration is always critical, and it's the piece which takes all of the time, but there was not much of that in this case, so I don't know if it's an illuminating example.

    I think it's quite true in general that the most important piece of being able to make good a custom features quickly is developing an intuition for how to break down problems into parametric pieces. Being "proficient in FS" is just one piece of that! :smile: Practicing good parametric practices can also involve simply making well-constructed, parametric Part Studios, which are flexible where they need to be, and inflexible where they don't. We designed FeatureScript to be a useful tool in solving these problems, but it's not the only tool.

    Figuring out if that good parametric design is a worthwhile investment for a project is always an important decision with varying tradeoffs. FeatureScript designs can have even better parametric properties than standard CAD, and can take even more time, but I think making that important decision involves most of the same considerations whether FeatureScript is involved or not.
Sign In or Register to comment.