Main Content

Programmatically Manage Simscape Block Parameter Data

You can programmatically author, share, and install new Simscape block parameter data and metadata as a part that belongs to a collection. To author a part collection:

  1. Parameterize a Simscape block.

  2. Store the parameters in a new or existing partrepo.simscape.BlockDataSet object.

  3. Update the properties of the partrepo.simscape.Metadata object.

  4. Validate the BlockDataSet object.

  5. Export the BlockDataSet object to a JSON part file.

  6. Create a collection directory.

  7. Add the JSON part file to a new or existing collection.

  8. Build the collection.

A partrepo.simscape.BlockDataSet object consists of a block parameterization and an associated set of metadata. When you are ready to share the collection, locate the MLDATX file in the Build folder of the collection directory. To install a part collection, double-click the MLDATX file for the collection. Installing a collection allows you to access the parts in that collection for a given Simscape block in the Block Parameterization Manager tool.

Create Block Data Sets

To create a partrepo.simscape.BlockDataSet object:

  1. Parameterize a Simscape block according to your requirements.

  2. Use the partrepo.simscape.dataSetFromBlock function to create a block data set that contains the parameter data and metadata for the block.

In the BlockDataSet object, the Metadata and Parameters properties contain information about the metadata and parameter values, respectively.

The partrepo.simscape.BlockDataSet object contains the partrepo.simscape.Metadata object, which has name, value, and unit properties, and partrepo.simscape.Parameters objects, which contain name, value expression, unit, and origin properties.

Edit Block Data Sets

To edit block parameter data in the BlockDataSet object:

  1. Apply the parameters from the object to a Simscape block by using the applyParams function.

  2. Edit the block parameters, as needed.

  3. Verify that the block behaves as expected with the new parameter settings.

  4. Use the partrepo.simscape.paramsFromBlock function to write the new block parameters to the BlockDataSet object.

To edit the block metadata, edit the properties of the partrepo.simscape.Metadata object. To remove a field, use the removeField function.

When you are finished editing the BlockDataSet object, use the validate function to validate the data set.

Import and Export Block Data as a Part

You can store your block data set as a part by exporting the block data set to a JSON file. To export a block data set to JSON, use the partrepo.exportDataSetsToJSON function. To import part data from a JSON file, use the partrepo.importDataSetsFromJSON function.

Share and Manage Collections of Parts

A part collection contains one or more parts that you can use to parameterize a given block. Use partrepo.collection.new to create a collection. Creating a collection generates a directory where you can add part files. To share parts, add the JSON file associated with each part to the collection. Use partrepo.collection.build to build the collection and create a shareable MLDATX file in the Build folder of the collection directory. To edit parts in a collection, you must create a new JSON part file from the block, replace the original JSON part file in the collection with the new part file, and re-build the collection.

To install or uninstall built collections, use partrepo.collection.install or partrepo.collection.uninstall, respectively. When you install a collection, the parts that belong to that collection appear in the options of the Block Parameterization Manager tool for the associated block.

See Also

Topics