Main Content

Simulink.fileGenControl

Specify root folders for files generated by diagram updates and model builds

Description

example

cfg = Simulink.fileGenControl('getConfig') returns a handle to an instance of the Simulink.FileGenConfig object, which contains the current values of these file generation control parameters:

  • CacheFolder – Specifies the root folder for model build artifacts that are used for simulation, including Simulink® cache files.

  • CodeGenFolder – Specifies the root folder for code generation files.

  • CodeGenFolderStructure – Controls the folder structure within the code generation folder.

To get or set the parameter values, use the Simulink.FileGenConfig object.

These Simulink preferences determine the initial parameter values for the MATLAB® session:

example

Simulink.fileGenControl(Action,Name,Value) performs an action that uses the file generation control parameters of the current MATLAB session. Specify additional options with one or more name,value pair arguments.

Examples

collapse all

To obtain the file generation control parameter values for the current MATLAB session, use getConfig.

cfg = Simulink.fileGenControl('getConfig');

myCacheFolder = cfg.CacheFolder;
myCodeGenFolder = cfg.CodeGenFolder;
myCodeGenFolderStructure = cfg.CodeGenFolderStructure;

To set the file generation control parameter values for the current MATLAB session, use the setConfig action. First, set values in an instance of the Simulink.FileGenConfig object. Then, pass the object instance. This example assumes that your system has aNonDefaultCacheFolder and aNonDefaultCodeGenFolder folders.

% Get the current configuration
cfg = Simulink.fileGenControl('getConfig');

% Change the parameters to non-default locations
% for the cache and code generation folders
cfg.CacheFolder = fullfile('C:','aNonDefaultCacheFolder');
cfg.CodeGenFolder = fullfile('C:','aNonDefaultCodeGenFolder');
cfg.CodeGenFolderStructure = 'TargetEnvironmentSubfolder';

Simulink.fileGenControl('setConfig', 'config', cfg);

You can set file generation control parameter values for the current MATLAB session without creating an instance of the Simulink.FileGenConfig object. This example assumes that your system has aNonDefaultCacheFolder and aNonDefaultCodeGenFolder folders.

myCacheFolder = fullfile('C:','aNonDefaultCacheFolder');
myCodeGenFolder = fullfile('C:','aNonDefaultCodeGenFolder');

Simulink.fileGenControl('set', 'CacheFolder', myCacheFolder, ...
   'CodeGenFolder', myCodeGenFolder, ...
   'CodeGenFolderStructure', ...
    Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder);

If you do not want to generate code for different target environments in separate folders, for 'CodeGenFolderStructure', specify the value Simulink.filegen.CodeGenFolderStructure.ModelSpecific.

You can reset the file generation control parameters to values from Simulink preferences.

Simulink.fileGenControl('reset');

To create file generation folders, use the set action with the 'createDir' option. You can keep previous file generation folders on the MATLAB path through the 'keepPreviousPath' option.

% 
myCacheFolder = fullfile('C:','aNonDefaultCacheFolder');
myCodeGenFolder = fullfile('C:','aNonDefaultCodeGenFolder');

Simulink.fileGenControl('set', ...
   'CacheFolder',myCacheFolder, ...
   'CodeGenFolder',myCodeGenFolder, ...
   'keepPreviousPath',true, ...
   'createDir',true);

Input Arguments

collapse all

Specify an action that uses the file generation control parameters of the current MATLAB session:

  • 'reset' – Reset file generation control parameters to values from Simulink preferences.

  • 'set' – Set file generation control parameters for the current MATLAB session by directly passing values.

  • 'setConfig' – Set file generation control parameters for the current MATLAB session by using an instance of a Simulink.FileGenConfig object.

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: Simulink.fileGenControl(Action, Name, Value);

Specify the Simulink.FileGenConfig object instance containing file generation control parameters that you want to set.

Option for setConfig.

Example: Simulink.fileGenControl('setConfig', 'config', cfg);

Specify a simulation cache folder path value for the CacheFolder parameter.

Option for set.

Example: Simulink.fileGenControl('set', 'CacheFolder', myCacheFolder);

Specify a code generation folder path value for the CodeGenFolder parameter. You can specify an absolute path or a path relative to build folders. For example:

  • 'C:\Work\mymodelsimcache' and '/mywork/mymodelgencode' specify absolute paths.

  • 'mymodelsimcache' is a path relative to the current working folder (pwd). The software converts a relative path to a fully qualified path at the time the CacheFolder or CodeGenFolder parameter is set. For example, if pwd is '/mywork', the result is '/mywork/mymodelsimcache'.

  • '../test/mymodelgencode' is a path relative to pwd. If pwd is '/mywork', the result is '/test/mymodelgencode'.

Option for set.

Example: Simulink.fileGenControl('set', 'CodeGenFolder', myCodeGenFolder);

Specify the layout of subfolders within the generated code folder:

  • Simulink.filegen.CodeGenFolderStructure.ModelSpecific (default) – Place generated code in subfolders within a model-specific folder.

  • Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder – If models are configured for different target environments, place generated code for each model in a separate subfolder. The name of the subfolder corresponds to the target environment.

Option for set.

Example: Simulink.fileGenControl('set', 'CacheFolder', myCacheFolder, ... 'CodeGenFolder', myCodeGenFolder, ... 'CodeGenFolderStructure', ... Simulink.filegen.CodeGenFolderStructure.TargetEnvironmentSubfolder);

Specify whether to keep the previous values of CacheFolder and CodeGenFolder on the MATLAB path:

  • true – Keep previous folder path values on MATLAB path.

  • false (default) – Remove previous older path values from MATLAB path.

Option for reset, set, or setConfig.

Example: Simulink.fileGenControl('reset', 'keepPreviousPath', true);

Specify whether to create folders for file generation if the folders do not exist:

  • true – Create folders for file generation.

  • false (default) – Do not create folders for file generation.

Option for set or setConfig.

Example: Simulink.fileGenControl('set', 'CacheFolder', myCacheFolder, 'CodeGenFolder', myCodeGenFolder, 'keepPreviousPath', true, 'createDir',true);

Avoid Naming Conflicts

Using Simulink.fileGenControl to set CacheFolder and CodeGenFolder adds the specified folders to your MATLAB search path. This function has the same potential for introducing a naming conflict as using addpath to add folders to the search path. For example, a naming conflict occurs if the folder that you specify for CacheFolder or CodeGenFolder contains a model file with the same name as an open model. For more information, see What Is the MATLAB Search Path? and Files and Folders That MATLAB Accesses.

To use a nondefault location for the simulation cache folder or code generation folder:

  1. Delete any potentially conflicting artifacts that exist in:

    • The current working folder, pwd.

    • The nondefault simulation cache and code generation folders that you intend to use.

  2. Specify the nondefault locations for the simulation cache and code generation folders by using Simulink.fileGenControl or Simulink preferences.

Output Arguments

collapse all

Instance of a Simulink.FileGenConfig object, which contains the current values of file generation control parameters.

Version History

Introduced in R2010b