Import file using Python - API
fluvio_lobo_fenoglietto
Member Posts: 36 PRO
Hello,
I am trying to create a python function that imports a file into an Onshape document.
I have successfully installed and tested demo functions from the GitHub API page, such as app.py.
I have also generated my own version of the file in order to change some of the document attributes.
However, I cannot seem to find "import" or "export" functions that I can call.
Is there any detailed list of functions, function calls?
I am trying to create a python function that imports a file into an Onshape document.
I have successfully installed and tested demo functions from the GitHub API page, such as app.py.
I have also generated my own version of the file in order to change some of the document attributes.
However, I cannot seem to find "import" or "export" functions that I can call.
Is there any detailed list of functions, function calls?
Tagged:
0
Comments
-
If you've agreed to the API Terms (as part of signing in at the Developer Portal) you should now be able to see the 'API Explorer' app in the appstore. It's a free subscription and once added to a document will let you see the selection of API calls you can make, the parameters they take and their responses.
You have two choices for extracting your part studio to another format (Part Studios API in the API Explorer): you can elect to translate it to formats like Solidworks, or STEP (the Get Translations Formats lists the formats we support) Or you can export it to Parasolid or STL formats.
Similar choices and mechanisms exist for an assembly too.
Translation is a batch process, your translation starts and there are APIs to establish the status of the translation (Translations API). Export is an immediate response with the converted data (but the choice of formats is limited).Director of API, Appstore, and App Partner Technical Support1 -
@andrew_kimpton
Thank you! This allowed me to import a data-set into a document that I also created through python.
0 -
Hi,
I have a related question which I really appreciate to get help.
I'm trying to use the existing example (app.py) to import, say an .iges file, and export it as .stl but I can't figure out "element id (eid)" of imported .iges file in either of following methods.
If I create a new document (as it has been done in app.py) the eid seems to be Null. However, sending "null" or "none" to export stl API gives error. Also I can't see a new physical tab in the Chrome as it seems it is happening in the background.
If I use an existing physical tab, I can see that .iges file is imported and 2 new tabs are created, of which one has not preview (only a receipt showing the file is imported), and the other tab seems to be the 'real deal' showing the imported file. However, in this case I can only fetch the eid of the first tab which doesn't help me. Since my intention is to do this in batch.
It will be really nice if someone can help here. Thanks very much!import apikeyfrom apikey.client import Client# stacks to choose fromstacks = {'cad': 'https://cad.onshape.com'}# create instance of the onshape client; change key to test on another stackc = Client(stack=stacks['cad'], logging=True)# Generate New Onshape Documentnew_doc = c.new_document(name="input",public=True).json()did = new_doc['id']wid = new_doc['defaultWorkspace']['id']# Get Document Informationdetails = c.get_document(did)print 'Document name: ' + details.json()['name']# make a new document and grab the document ID and workspace ID - first methodnew_doc = c.new_document(name="Test1", public=True).json()docs = c.list_documents().json()# print docsdetails = c.get_document(did).json()wid = details['defaultWorkspace']['id']eid = details['defaultElementId'] # this will give Nullprint did, wid, eid# Import Dataset# second method (to use an existing hardcoded tab)# did = '5035008d4d7bdbc526bee2a9'# wid = 'b1978821b5ba45cc10c373b8'# eid = '75f9193e72533d86db0929e4'details = c.get_document(did)input_file_path = "testFile.iges"input_file = c.upload_blob(did, wid, filepath=input_file_path)eid = input_file.json()['id']print did, wid, eidprint "--------------"stl = c.part_studio_stl(did, wid, eid)0 -
Hi behnam_kamrani,
I believe you need to make a call to api/documents/d/[did]/w/[wid]/elements in order to get the list of elements in the document and get the ID from that. The upload call won't return an element ID as it is made asynchronously.Jake RamsleyDirector of Quality Engineering & Release Manager onshape.com1 -
0
Categories
- All Categories
- 10.2K Community Support
- 4.6K General
- 194 Account and subscriptions
- 353 Data management
- 1.6K Product Feedback
- 215 New in Onshape
- 14 Onshape Labs
- 75 CAM Studio
- 35 PCB Studio
- 107 Simulation
- 209 Onshape Mobile
- 315 App Store & Partners Apps
- 8.2K Using Onshape
- 1.8K Drawings
- 2.3K FeatureScript
- 324 Learning Center
- 253 Education Community



