mech_import

Generate model from Physical Modeling XML file

Syntax

mech_import
mech_import('filename.xml')
mech_import('filename.xml', option1, value1, option2, value2, ...)

Description

mech_import opens the Import Physical Modeling XML dialog box. See Alternatives following.

mech_import('filename.xml') generates a SimMechanics™ model from a Physical Modeling XML file called filename.xml. For an XML file generated from computer-aided design (CAD), the name of the generated model is the same as the original CAD assembly, regardless of the name of the XML file.

mech_import('filename.xml', option1, value1, option2, value2, ...) generates the SimMechanics model from filename.xml, using the specified option-value pairs when importing.

The mech_import function either generates a new SimMechanics model or updates a previously generated SimMechanics model that you specify. It also generates or updates the associated body geometry files.

Input Arguments

mech_import requires one input and accepts additional optional inputs.

'filename.xml'

Input XML file name. Replace filename with the name of the XML file that you want to import. The .xml extension in this input is optional.

This input is required.

Default: ''

'ImportMode'

0 – Import XML into a new model.

1 – Use XML to update contents of a model or subsystem.

2 – Add contents of new XML to a model or subsystem.

3 – Import contents of new XML into a model or subsystem and delete the existing contents.

This input is optional.

Default: 0

'ModelToImportInto'

String specifying the target model for importing or updating existing blocks. This input is optional.

Default: Original CAD assembly name

'SubsystemToImportInto'

String specifying the target subsystem for importing or updating existing blocks. This input is optional.

Default: Original CAD subassembly name

'CreateTopSS'

true or false – Whether to create a new subsystem if the specified subsystem ('SubsystemToImportInto') does not exist in the target model. Applies when 'ImportMode' = 2. This input is optional.

Default: false

'ModelSimplificationOpt'

0 – Follow the imported hierarchy and make no simplifications to the generated subsystem hierarchy.

1 – Bring all joints to the top model or subsystem. Group and place welded bodies into newly created rigid subsystems at each level of model hierarchy.

2 – Group and place welded bodies at each level of model hierarchy into newly created rigid subsystems at the same level.

This input is optional.

Default: 0

'UseDefaultJointNames'

'on' – Use default joint names such as Revolute1, Revolute2, etc., and ignore joint names specified in the XML file.

'off' – Use the joint names from the XML file.

This input is optional.

Default: 'on'

'UseBlockNamesForSpacing'

'on' – Space blocks so that their names do not overlap.

'off' – Use only block size to space blocks.

This input is optional.

Default: 'off'

'LayoutDirection'

'LR' – Diagram grows from left to right.

'TB' – Diagram grows from top to bottom.

This input is optional.

Default: 'LR'

'LayoutWithUpdate'

true or false – Whether to arrange all imported blocks after updating their parameters. Applies only when updating. If false, arrange newly imported blocks separately from the existing blocks. This input is optional.

Default: false

'EnableIndvlBlkUpdCtrl'

true or false – Whether to respect the update settings of individual blocks. If false, update all blocks regardless. This input is optional.

Default: true

'NewJointsAtTopLevel'

true or false – Whether or not to add new joints in the updated model at the highest level of the model hierarchy specified by either the ModelToImportInto or the SubsystemToImportInto option. Applies when 'ImportMode' = 1. This input is optional.

Default: false

'BackupMode'

0 – Do not create a backup version of the model while updating an existing model.

1 – Create a backup version of the model in the same folder as the updated model.

2 – Specify a name for the backup version of the model and a location.

This input is optional.

Default: 1

'BackupLocation'

Specify the complete path where importer will create the backup version of the model. Applies when 'BackupMode' = 2. This input is optional.

Default: ''

Output Arguments

mech_import produces or updates one model file.

The default output model name is the same as the assembly name specified in the Physical Modeling XML file. The output model name is independent of the name of the XML file used as the input.

Examples

Importing a New Model

Create the Physical Modeling XML file for a hypothetical CAD assembly called assembly:

  1. From your CAD platform, export the assembly. Call the file assembly.xml.

  2. Place or copy the XML file into your current MATLAB® working folder.

  3. At the command line, enter

  4. mech_import('assembly.xml')

    SimMechanics software generates the block diagram in a model file called assembly.mdl. You can save, rename, modify, and run this model.

Importing a New Model with a Nondefault Name

Change a model's name from the default:

  • When you invoke the function to import the XML file, use the 'ModelToImportInto' option.

  • When you use the dialog box to import the XML file, use the Specify model to import into field.

  • After you import the XML file and generate the model, when you save the model.

Apply a nondefault name to a final generated model in this way:

mech_import('robot.xml','ImportMode',0, ...
           'ModelToImportInto','myrobot')

This form of the function imports the example file, robot.xml, into a new SimMechanics model called myrobot.

Importing a New Model While Simplifying Model Hierarchy

At the command line, enter

showdemo mech_modelsimplification

to display the example page and learn about to simplify the joints and welded bodies in a generated model.

Updating an Existing Model with Several Options

Update an existing model (existingModel) with the XML file existingModelUpdate.xml:

mech_import('existingModelUpdate.xml','ImportMode',1, ...
            'ModelToImportInto','existingModel', ...
            'LayoutWithUpdate',true,'EnableIndvlBlkUpdCtrl',true, ...
            'BackupMode',2,'BackupLocation','C:\backupdir\')

The importer arranges the updated blocks, while respecting the individual block update settings. The function also creates a backup version of the model and specifies a nondefault backup location (C:\backupdir\).

Alternatives

If you enter mech_importmech_import at the command line with no inputs, the Import Physical Modeling XML dialog box opens.

Use the context-sensitive help in this dialog box for information about its parameters. These parameters provide the same control over generating SimMechanics models from Physical Modeling XML files as do the function inputs.

Was this topic helpful?