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
-
Hi 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
-
Hi 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 -
-
0 -
Hi 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_definitiontest=Client()
This yielded the following error:
test_element=OnshapeElement('https://cad.onshape.com/documents/226f6d6bcf86b8b901b42113/w/4be950d3288c6267581068e4/e/2799ad870ef186e43363f7d4')
test_assembly_definition(test,test_element)
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
0

