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.
How do you get the document id and workspace id of the currently active document and workspace

I wonder what is the best practice to get the did
and wid
of the currently active document? I'm developing an app in the side panel and currently I'm using some JS code like the following to help me get them:
function getDocumentInfo() { onshape.getDocument(function(documentInfo) { if (documentInfo && documentInfo.documentId && documentInfo.workspaceId) { const documentId = documentInfo.documentId; const workspaceId = documentInfo.workspaceId; console.log("Document ID:", documentId); console.log("Workspace ID:", workspaceId); redirectToPanel(documentId, workspaceId); } else { console.error("Could not retrieve Document ID and Workspace ID from Onshape."); // Handle error appropriately, maybe display a message to the user. } }); } function redirectToPanel(documentId, workspaceId) { const panelUrl = `/panel/?documentId=${documentId}&workspaceId=${workspaceId}`; // Adjust the URL path if needed window.location.href = panelUrl; // Call getDocumentInfo() when your side panel is loaded or when you need to get the IDs. // For example, you might call it when a button is clicked in your side panel. getDocumentInfo();
But I wonder if this is a common practice? Do you have a better way?
Tagged:
0