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.

Duplicate a document through API

morteza_karimimorteza_karimi Member Posts: 13
There should be a simple API call to do this but surprisingly isn't.
We have a series of part studios in various documents which are created by multiple people in our organization. We're developing an application that exports these part studios to a different format, but before it does that it needs to do some operations including updating metadata, evaluating featurescript etc. I can do this in the original document and roll back once done but it would create unnecessary history.
I'm aware of the concept of derived parts, but I'm not sure how to achieve that through the API.
But even that is just limited to geometry within the source partstudio. I'd like to bring everything, including custom features into the newly created document.
Does anyone have any workflow for this?
Tagged:

Comments

  • raj_Onshaperaj_Onshape Onshape Employees Posts: 110
    Documents -> Copy Workspace REST API should do what you need


  • morteza_karimimorteza_karimi Member Posts: 13
    @raj_Onshape I see, that call copies the entire document. Which is fine, but I do need to reference a specific part studio in that document and of course elementID of newly created part studio isn't the same.
    Let me clarify what my app does, it takes documentId, workspaceId and elementId of a part studio to do the operations and export. Now that document might have multiple part studios. Once we copy workspace and create a new document, how can I tell which part studio within the new document is what the user was referring to?
    I suppose I could get elements from newly created workspace and iterate through the names of part studios to find out, but there's a chance my part studio names may not be unique.
    So to back up, is there a way to only copy a specific part studio to a new document?
  • mbattistellombattistello Member, Developers Posts: 51 ✭✭
    You might have to do it in a couple steps. I dont completely follow what you trying to do but I think its something like this,

    1. User submits did, wid, eid to run export on.
    2. On identified d/w/e set an attribute that identifies it as the one the user wants to export. T
    3. Call the Copy Document API. This should copy your document and give you the new d/w ids. 
    4. Find the element that was flagged in step 2 in the new document. 
    5. Do whatever you need in the copied document in the flagged element.
    6. Delete the copied document.
    7. Remove the flags from the original document.

    Its a couple different API calls but since the APIs are lower level operations its expected that you might need to make a couple different calls. 
  • morteza_karimimorteza_karimi Member Posts: 13
    Hi @mbattistello , that sums up what I'm trying to achieve and yes it will be a series of API calls.
    This could work, but it still does add unnecessary operations to the history. (flagging and unflagging), however it's much less than doing the whole operation in original document and having to roll back.
  • lanalana Onshape Employees Posts: 705
    @morteza_karimi
    Could your workflow include creating a version at the state where parts need to be exported? Then you could use api to branch a workspace off that version, make whatever changes needed, export and delete the workspace.
    The element id remains the same. Submitting a version for processing also has an advantage that the user can continue working in that workspace without concern for getting exported data in a wrong state.
Sign In or Register to comment.