Main Content

smexportonshape

Export a CAD assembly model from Onshape

Description

multibodyDescriptionFile = smexportonshape(assemblyURL) generates the files that you need to import an Onshape® assembly model into the Simscape™ Multibody™ environment.

The assemblyURL argument is the web address of the Onshape assembly model to export. To obtain the web address, open the Onshape model, select the assembly tab, and copy the URL shown on your web browser.

The generated files include an XML multibody description file and a set of STEP files. The XML file identifies the bodies that comprise the model and defines their kinematic relationships. The STEP files provide the 3-D geometries of the bodies. By default, all files are stored in the current MATLAB® folder.

The multibodyDescriptionFile output is the name of the XML multibody description file. You must use the smimport function with multibodyDescriptionFile as input argument to import the Onshape model into the Simscape Multibody environment. The figure shows the export and import stages of the Onshape CAD translation workflow.

Workflow of the Onshape CAD translation

You must have an active Onshape account. The first time you use this function, you must give the Simscape Multibody Exporter access privileges to your Onshape account. The function uses these privileges strictly to access and export your Onshape models. Onshape software grants the function access via Javascript tokens that keep your login credentials and any user information secure and visible only to you.

To obtain the access tokens for your account, Simscape Multibody software requires you to log in to your Onshape account once per MATLAB session. A secure Onshape log-in page opens automatically on the first use of the smexportonshape function of a MATLAB session.

You can revoke the access privileges granted to the Simscape Multibody Exporter at any time. You must, however, restore those privileges if you want to export additional Onshape models. If you revoke the access privileges, then on your next use of smexportonshape an Onshape web page opens prompting you to accept or reject a request to restore those privileges.

multibodyDescriptionFile = smexportonshape(assemblyURL,Name=Value) adds a name-value pair argument to specify the folder in which to save the XML and STEP files for the model.

Examples

collapse all

This example shows how to export an Onshape model for Simscape Multibody.

  1. Create a variable named url to store the URL of a humanoid robot assembly created by using Onshape.

    url = "https://cad.onshape.com/documents/5817806f96eae5105bfa5085/w/15ab3bfb58cacbf427d77ff3/e/181493813f84966648a8db1b";
  2. Export the humanoid robot model by using the smexportonshape function. Store the generated multibody description file in a variable named xmlFile. You may be prompted to log in to your Onshape account.

    xmlFile = smexportonshape(url);

  3. To import the humanoid robot into the Simscape Multibody environment, use the smimport function.

    smimport(xmlFile);
  4. Update the block diagram. Mechanics Explorer opens with a static visualization of the model in its initial configuration—one matching the pose of the Onshape model at the time of export.

    Note that the vertical axis of the robot (+Y) differs from the default vertical axis used in the Mechanics Explorer visualization pane (+Z). To orient the robot vertically, select View > View convention > Y Up (XY Front). Select a standard view from the View > Standard Views menu to activate the new view convention.

Export an Onshape model of a humanoid robot assembly into a specific folder using the smexportonshape function.

  1. Store the URL of the Onshape model in a MATLAB variable named url and the folder in which to save the model in a variable named folder. You must create the folder shown or replace that folder with one to which you have write privileges.

    url = "https://cad.onshape.com/documents/5817806f96eae5105bfa5085/w/15ab3bfb58cacbf427d77ff3/e/181493813f84966648a8db1b";
    folder = "C:\Documents\Export"
  2. Export the humanoid robot model using the smexportonshape function. Use the FolderPath name-value pair argument to specify the export folder.

    xmlFile = smexportonshape(url,FolderPath=folder);

Input Arguments

collapse all

Web address of the Onshape assembly model to export. The function uses this address to access the assembly model and export it in a format compatible with Simscape Multibody software.

To obtain the URL, open the Onshape assembly model, select the assembly tab, and copy the URL from the web browser. The assembly model need not belong to your Onshape account if it is shared with you or made public.

Example: https://cad.onshape.com/documents/3e07ba43d290f9b924933ce8/w/eb80497ae2e1a3af0c4ce16d/e/f7903984700a200643fb6141

Data Types: char | string

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: xmlFile = smexportonshape("https://cad.onshape.com/documents/5817806f96eae5105bfa5085/w/15ab3bfb58cacbf427d77ff3/e/181493813f84966648a8db1b",FolderPath="C:\Documents\Export");

Path of the folder to save the XML and STEP files generated during model export. The path can be absolute or relative. You must have write privileges to the folder to save the files.

Example: "C:\Documents\Models"

Data Types: char | string

Output Arguments

collapse all

Name of the XML multibody description file generated during Onshape CAD export. The name is derived from the OnShape assembly name. You use this name as an argument in the smimport function to import the model into the Simscape Multibody environment.

Data Types: char

Version History

Introduced in R2017a

See Also