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.

Import file using Python - API


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?


  • awkawk Member, Onshape Employees, Developers Posts: 78
    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 Support
  • fluvio_lobo_fenogliettofluvio_lobo_fenoglietto Member Posts: 36 PRO

    Thank you! This allowed me to import a data-set into a document that I also created through python.
  • behnam_kamranibehnam_kamrani Member Posts: 2

    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 apikey
    from apikey.client import Client

    # stacks to choose from
    stacks = {

    # create instance of the onshape client; change key to test on another stack
    c = Client(stack=stacks['cad'], logging=True)

    # Generate New Onshape Document
    new_doc = c.new_document(name="input",public=True).json()
    did = new_doc['id']
    wid = new_doc['defaultWorkspace']['id']

    # Get Document Information
    details = c.get_document(did)
    print 'Document name: ' + details.json()['name']

    # make a new document and grab the document ID and workspace ID  - first method
    new_doc = c.new_document(name="Test1", public=True).json()
    docs = c.list_documents().json()
    # print docs
    details = c.get_document(did).json()
    wid = details['defaultWorkspace']['id']
    eid = details['defaultElementId']  # this will give Null
    print 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, eid
    print "--------------"

    stl = c.part_studio_stl(did, wid, eid)
  • jakeramsleyjakeramsley Member, Moderator, Onshape Employees, Developers Posts: 657
    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 Ramsley

    Director of Quality Engineering & Release Manager              onshape.com
  • behnam_kamranibehnam_kamrani Member Posts: 2
    Thank you jakeramsley!! Exactly what I needed. 

    Thank you for prompt response as well :)  
Sign In or Register to comment.