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.

Export/import of Featurescript for a Part Studio?

preston_bannisterpreston_bannister Member Posts: 6
In Part Studio, I can "Show code" to view the Featurescript text, but I cannot edit that text. 

In my case, I want to do a bit of refactoring - rename a parameter and update all uses of that parameter. This does not seem to be supported by Onshape (that I can tell). If I could export/import the Featurescript, I could do the renaming in a text editor. I could also do a did of search/replace to find any static values, and replace them with parameters.

Again, I am a software guy learning CAD, so my approach my be different than a usual CAD user.

Is there a way to export/import the Featurescript of a Part Studio?

Comments

  • mahirmahir Member, Developers Posts: 867 ✭✭✭✭
    Sorry, that is not an option. The "show code" option can be useful in learning how OS does things behind the scenes, but it isn't very useful for actual CAD data manipulation. If you have a particular variable/dimension that you want to vary, the best way is to create a #variable early in your feature tree and reference that variable in your design. If you need to change it later, you just change the variable, and everything linked to it should update accordingly.
  • preston_bannisterpreston_bannister Member Posts: 6
    Again, coming from software development, "refactoring" has become a big part of what we expect from development environments. Refactoring in software is applying some fairly complex transformations to programs, in a largely automated fashion. (Which is also why Eclipse and similar development environments require large globs of memory and CPU.)

    A simple example is renaming. You can change the name of a variable with a text editor that supports multifile search and replace (with Emacs as an early example). This is not a single-step operation, as local and member variables may use the same names (in effect, false positives).

    You can avoid the problem somewhat with naming conventions. I am starting to drift toward using a version of Hungarian notion for my CAD parameters.

    You can do most any sort of transformation in a smart text editor, especially with well-chosen naming, though the process may be rather manual. Learned that lesson a *long* time ago.
    https://bannister.us/weblog/2005/structure-editors-ides-and-another-lisp-flashback

    Yes, clearly if I had chosen good names for my parameters up front, I would not be looking to rename my parameters later. This is much like the experience with top-down versus iterative (agile) design in software. 

    Interesting ... I discovered the Featurescript view is live. If I select items in the "Features" view, then the corresponding text is highlighted in the script view (very cool). As a hack, I created a variable with the desired name, updated the existing variable to reference the new name, then suppressed the variable (in hopes of discovering where it was used, for manual fix-up). 

    First, the interface showed the "wait" cursor for rather a long time. As a non-paying user, I feel a bit guilty if I am slamming one of the Onshape servers. :) )

    Second, what failed was one of the sketches, which in my case was ~700 lines of Featurescript code. As the "Features" tree is a single level, in practical terms this is far too crude for figuring out what items in the sketch needs fixing.

    Which means doing renaming in a text editor is still a better idea.

    Note that this mapping between empirical language and visual representation is an old topic in programming environments. In roughly historic order, Visual Basic, Visual Cafe, Visual Studio, NetBeans, and (sometimes) Eclipse all had/have support.

    As to whether there is need for this level of support in the CAD world, I have no clue.
Sign In or Register to comment.