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.

Defining variables and prompts

susan_mosssusan_moss Member Posts: 3 EDU
I am just starting to explore FeatureScript and the documentation - while decent, is insufficient.

My background - I have been coding since the days of DOS.  I can code in BASIC (geez, my age shows), C++, VisualBASIC, VisualLISP, AutoLISP, JAVA, html, and a few other extremely esoteric languages that are specific to their own little software programs...4GL, anyone? So, I am not afraid to tinker and I don't mind writing code.

I always start by writing down an outline of what I want the code to do and use it as my guide.
So, I want to create a sketch.  I start by drawing a construction line.  I want to assign a variable for the length of the construction line.  I then want to place two lines offset parallel to the construction line at a distance from the construction line.  I would like to prompt the user for the length of the construction line and for the distance from the construction line to the offset line.  I then would like to be able to add a linear dimension to the sketch designating the length of construction line.

I see the sketch tool - no problem.
I see the line tool - no problem.  But how do I define it as a construction line?
I see the Length parameter.  I am assuming this prompts the user for the length value.  In the code I can change the name, but do I also need to modify the definition.myLength to use definition.myVar?
I don't see any tool on how to add a dimension.

Thanks for any enlightenment.

Elise Moss


  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 4,605
    Hi Elise, any sketches created by FeatureScript are not user editable so there is no dimension tool and no constraints. To create a construction line see the docs for skLine. 
    Director, Technical Services, EMEA
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 555
    edited June 2016
    To be clear: it IS possible to add constraints and dimensions to sketches in FeatureScript (after all, Part Studios and user-created sketches are just FeatureScript underneath). However, in practice, it is almost always easier to write code that places lines and other entities exactly where you want them in the first place, rather than writing the code to place them incorrectly, and writing additional code to control the (somewhat finicky) constraint solver.

    It sounds like you're coming to grips with some of the core concepts of FeatureScript. One helpful resource is the tutorials, found here. They introduce a lot of useful, generalizable patterns.

  • susan_mosssusan_moss Member Posts: 3 EDU
    Thanks, Neil and Kevin.

    I want to place the dimensions, so I have the option of modifying them later manually.
    I did skim through the tutorials, but couldn't find an example of auto-placing the dimension.
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 555
    Unfortunately, the workflow you describe is not possible in a custom feature. Custom features have parameters as inputs, but everything inside the feature (subfeatures, sketches, sketch dimensions) will not be editable after the fact except through those parameters.

    You can have a length parameter that controls the sketch dimension, as done with the width parameter in the slot tutorial. When you have such a parameter, you can use the value to place sketch entities (the easier way), or use it to drive a dimension.

  • susan_mosssusan_moss Member Posts: 3 EDU
    Thanks, Kevin.  It is helpful to know that placing a dimension would not allow a user to modify the feature later.  That allows me to modify the script accordingly.
Sign In or Register to comment.