Documentation

smexportonshape

Export a CAD assembly model from Onshape cloud software

Syntax

multibodyDescriptionFile = smexportonshape(assemblyURL)
multibodyDescriptionFile = smexportonshape(assemblyURL,Name,Value)

Description

multibodyDescriptionFile = smexportonshape(assemblyURL) generates the files that you need in order 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 this name as an argument in order to import the Onshape model into the Simscape Multibody environment. The figure shows the export and import stages of the Onshape CAD translation workflow. The Simscape Multibody model and M data file are the product of the import stage.

Onshape CAD Translation Workflow

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

Export an Onshape model of a humanoid robot assembly into the current MATLAB folder using the smexportonshape function. Then, import the generated model files into the Simscape Multibody environment using the smimport function.

  1. Store the URL of the Onshape model in a MATLAB variable named url. The URL must always correspond to the Onshape assembly tab that you want to export.

    url = 'https://cad.onshape.com/documents/5817806f96eae5105bfa5085/w/15ab3bfb58cacbf427d77ff3/e/181493813f84966648a8db1b';
  2. Export the humanoid robot model using the smexportonshape function. Store the name of 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. Import the model into the Simscape Multibody environment using the smimport function. Simscape Multibody software recreates the Onshape model as a block diagram.

    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);

    Import the model into the Simscape Multibody environment as before using the smimport function. Update the diagram to visualize the imported model in Mechanics Explorer.

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 Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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

collapse all

Path of the folder in which 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 in order to save the files there.

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

See Also

Introduced in R2017a

Was this topic helpful?