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.
Can I use API to add multiple parts in an assembly?
timo_schmid
Member Posts: 36 EDU
Hi,
I'm trying to put multiple parts in to an assembly in a semi-automatized manner. (i.e. I want to select only a few points, and then the program automatically adds multiple parts in the right place & orientation in relation to the selected points)
I'm wondering if the API (potentially using the python client) is feasible for this kind of task?
If yes, are there any ressources (apart from the API explorer) that provide guidance?
Thanks for your help,
Timo
I'm trying to put multiple parts in to an assembly in a semi-automatized manner. (i.e. I want to select only a few points, and then the program automatically adds multiple parts in the right place & orientation in relation to the selected points)
I'm wondering if the API (potentially using the python client) is feasible for this kind of task?
If yes, are there any ressources (apart from the API explorer) that provide guidance?
Thanks for your help,
Timo
0
Best Answer
-
Ethan_K Member, Onshape Employees Posts: 57Hi Timo,
Yes, this is certainly possible. An example program for the latest experimental python client can be found here: https://github.com/onshape-public/onshape-clients/blob/polymorphic_python/python/test/test_assemblies_api.py#L28 . This test replicates an assembly programmatically through the API. You wouldn't actually do this in practice, but it is an informative and useful test. Please let me know if you have additional questions. Note that you can find definitions of each of the fixtures (function params in the test function) from the conftest.py file.
Cheers,
-Ethan5
Answers
Yes, this is certainly possible. An example program for the latest experimental python client can be found here: https://github.com/onshape-public/onshape-clients/blob/polymorphic_python/python/test/test_assemblies_api.py#L28 . This test replicates an assembly programmatically through the API. You wouldn't actually do this in practice, but it is an informative and useful test. Please let me know if you have additional questions. Note that you can find definitions of each of the fixtures (function params in the test function) from the conftest.py file.
Cheers,
-Ethan
Thanks for your answer. I tried running the create_circle.py script and it gives an InsecureRequestWarning from the urllib3 package. Despite the warning, it does create a new document on my onshape Account, but it cannot create the circle. I receive the following error:
AttributeError: 'PartStudiosApi' object has no attribute 'add_part_studio_feature'
(line 49 in the create_circle script)
Similarly, in the test_assemblies_api.py script that you suggested, I added the following lines to try running the function test_assembly_definition
This yielded the following error:
Do you know the reason for the two errors? Or is there a documentation to understand the python client for the API better?
Best,
Timo