Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
Adding dimensions to sketch features via API
Though there are guides published for adding dimensions to drawings here, I can't find any sources for how to add a dimension to a part studio. The closest I've gotten is by creating a BTMSketchConstraint2 with "DISTANCE" as the constraint type. That applies a distance dimension, but I'm struggling to get it to reference sketch features correctly. I've tried creating parameters for a sketch line (BTMSketchCurveSegment155, wrapped in a BTMParameterString149) as well as passing two points (both BTMSketchPoint158 wrapped in a parameter string as well). In both cases the constraint is received but the feature solves with an error complaining that the references didn't resolve correctly.
The best source I've found for adding sketch constraints is the onshape_client package (now archived, though I can't seem to find a superseding repo yet). The tests there successfully apply coincident constraints using the "features" POST api call, which I've replicated. I don't see any information for how to extend this to a dimension however. I'm looking to see if anyone knows of additional guides/examples/documentations, or has the innate knowledge themselves on how to do dimensions. Thanks in advance.
For reference, here is an example of the JSON body code which is successfully received and solved for by Onshape, though producing unresolved errors in the model (passing two points as the parameters, the points were successfully solved for in the model):
{ 'bt_type': 'BTMSketchConstraint-2',
'constraint_type': 'DISTANCE',
'driven_dimension': True,
'entity_id': 'lengthId',
'parameters': [ { 'bt_type': 'BTMParameterString-149',
'parameter_id': 'localFirst',
'value': 'myPoint' },
{ 'bt_type': 'BTMParameterString-149',
'parameter_id': 'localSecond',
'value': 'my2ndPoint' }] }
Best Answer
-
Caden_Armstrong Member Posts: 194 PRO
I've done this before, and unfortunately there is no documentation/resources.
My process was to essentially reverse engineer the data structure of a sketch.
Manually make a sketch dimension, and do a "Get Features" api call. Look at what the result is, and then replicate.www.smartbenchsoftware.com --- fs.place --- Renaissance
Custom FeatureScript and Onshape Integrated Applications2
Answers
I've done this before, and unfortunately there is no documentation/resources.
My process was to essentially reverse engineer the data structure of a sketch.
Manually make a sketch dimension, and do a "Get Features" api call. Look at what the result is, and then replicate.
Custom FeatureScript and Onshape Integrated Applications